build.gradle 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. plugins {
  2. id 'org.sonarqube'
  3. id 'java-library'
  4. id 'java-test-fixtures'
  5. id 'maven-publish'
  6. id 'jacoco'
  7. id 'com.google.protobuf'
  8. }
  9. /**
  10. * Return the latest available domain version from git, if git is installed.
  11. */
  12. def getGitVersion = { ->
  13. def domainTagPrefix = 'domain-v'
  14. def stdout = new ByteArrayOutputStream()
  15. def stderr = new ByteArrayOutputStream()
  16. try {
  17. exec {
  18. commandLine 'git', 'describe', '--tags', '--match', domainTagPrefix + '*'
  19. standardOutput = stdout
  20. errorOutput = stderr
  21. ignoreExitValue true
  22. }
  23. def string = stdout.toString().trim()
  24. def versionMatches = (string =~ /^${domainTagPrefix}([0-9.]+).*$/)[0][1]
  25. if(versionMatches.isEmpty()) return null
  26. return versionMatches
  27. } catch (ignored) { return null }
  28. }
  29. dependencies {
  30. api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
  31. api 'com.googlecode.libphonenumber:libphonenumber:8.12.41'
  32. api 'androidx.annotation:annotation:1.3.0'
  33. api 'net.sourceforge.streamsupport:streamsupport-flow:1.7.0'
  34. api 'com.google.protobuf:protobuf-javalite:3.19.4'
  35. implementation "org.slf4j:slf4j-api:$slf4j_version"
  36. // commons-io >2.6 requires android 8
  37. implementation 'commons-io:commons-io:2.6'
  38. implementation 'net.i2p.crypto:eddsa:0.3.0'
  39. testImplementation 'junit:junit:4.13.1'
  40. testImplementation 'org.mockito:mockito-core:3.3.3'
  41. testImplementation "org.slf4j:slf4j-simple:$slf4j_version"
  42. }
  43. sourceSets {
  44. def isProtobufSubrepositoryInitialized = file("./src/main/proto/common.proto").exists()
  45. assert isProtobufSubrepositoryInitialized : "Error: Git protobuf submodule missing. Please run `git submodule update --init`.\n"
  46. main {
  47. java.srcDirs += "${protobuf.generatedFilesBaseDir}/main/java"
  48. }
  49. }
  50. sourceCompatibility = '1.8'
  51. protobuf {
  52. protoc {
  53. artifact = 'com.google.protobuf:protoc:3.19.4'
  54. }
  55. generateProtoTasks {
  56. all().each { task ->
  57. task.builtins {
  58. java {
  59. option 'lite'
  60. }
  61. }
  62. }
  63. }
  64. }
  65. test {
  66. useJUnit()
  67. }
  68. jacocoTestReport {
  69. reports {
  70. xml.required = true
  71. html.required = false
  72. }
  73. }
  74. sonarqube {
  75. properties {
  76. property 'sonar.projectKey', 'android-client'
  77. property 'sonar.projectName', 'Threema for Android'
  78. property "sonar.sources", "src/main/"
  79. property "sonar.exclusions", "src/main/java/ove/crypto/**"
  80. property "sonar.tests", "src/test/"
  81. property "sonar.sourceEncoding", "UTF-8"
  82. property "sonar.verbose", "true"
  83. property 'sonar.coverage.jacoco.xmlReportPaths', "$projectDir.parentFile.path/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
  84. }
  85. }
  86. publishing {
  87. publications {
  88. library(MavenPublication) {
  89. from components.java
  90. version getGitVersion()
  91. }
  92. }
  93. repositories {
  94. maven {
  95. url System.getenv("CI_API_V4_URL") + "/projects/" + System.getenv("CI_PROJECT_ID") + "/packages/maven"
  96. name "Gitlab"
  97. credentials(HttpHeaderCredentials) {
  98. name = 'Job-Token'
  99. value = System.getenv("CI_JOB_TOKEN")
  100. }
  101. authentication {
  102. header(HttpHeaderAuthentication)
  103. }
  104. }
  105. }
  106. }