build.gradle 3.4 KB

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