build.gradle 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. }
  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) {
  28. return null
  29. }
  30. }
  31. dependencies {
  32. api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
  33. api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
  34. api 'com.googlecode.libphonenumber:libphonenumber:8.13.39'
  35. api 'androidx.annotation:annotation:1.8.0'
  36. api 'net.sourceforge.streamsupport:streamsupport-flow:1.7.4'
  37. api 'com.google.protobuf:protobuf-kotlin-lite:3.25.1'
  38. implementation "org.slf4j:slf4j-api:$slf4j_version"
  39. // commons-io >2.6 requires android 8
  40. implementation 'commons-io:commons-io:2.6'
  41. implementation 'net.i2p.crypto:eddsa:0.3.0'
  42. implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
  43. // Note: when updating this version, we need to include the libjnidispatch.so of the same
  44. // version for each ABI in app/libs/
  45. // The libjnidispatch.so files can be found in the .jar file:
  46. // https://github.com/java-native-access/jna/tree/master/dist
  47. implementation "net.java.dev.jna:jna:5.13.0"
  48. testImplementation "junit:junit:$junit_version"
  49. testImplementation 'org.mockito:mockito-core:4.8.1'
  50. testImplementation "org.powermock:powermock-reflect:2.0.9"
  51. testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_coroutines_version"
  52. testImplementation "org.slf4j:slf4j-simple:$slf4j_version"
  53. testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
  54. testImplementation project(':test-helpers')
  55. // OkHttp
  56. api platform('com.squareup.okhttp3:okhttp-bom:4.12.0')
  57. api 'com.squareup.okhttp3:okhttp'
  58. api 'com.squareup.okhttp3:logging-interceptor'
  59. }
  60. sourceSets {
  61. def isProtobufSubrepositoryInitialized = file("./protocol/src/common.proto").exists()
  62. assert isProtobufSubrepositoryInitialized: "Error: Git protobuf submodule missing. Please run `git submodule update --init`.\n"
  63. main {
  64. java.srcDirs += "./build/generated/source/proto/main/java"
  65. java.srcDirs += "./build/generated/source/proto/main/kotlin"
  66. java.srcDirs += './build/generated/source/libthreema'
  67. }
  68. }
  69. test {
  70. useJUnit()
  71. }
  72. jacocoTestReport {
  73. reports {
  74. xml.required = true
  75. html.required = false
  76. }
  77. }
  78. sonarqube {
  79. properties {
  80. property 'sonar.projectKey', 'android-client'
  81. property 'sonar.projectName', 'Threema for Android'
  82. property "sonar.sources", "src/main/"
  83. property "sonar.exclusions", "src/main/java/ove/crypto/**"
  84. property "sonar.tests", "src/test/"
  85. property "sonar.sourceEncoding", "UTF-8"
  86. property "sonar.verbose", "true"
  87. property 'sonar.coverage.jacoco.xmlReportPaths', "$projectDir.parentFile.path/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml"
  88. }
  89. }
  90. afterEvaluate {
  91. def bindingsDirectory = '../build/generated/source/libthreema'
  92. // Define the task to generate libthreema library (only used to generate bindings for it)
  93. def generateLibthreema = tasks.register("generateLibthreema", Exec) {
  94. workingDir "${project.projectDir}/libthreema"
  95. commandLine 'cargo', 'build', '-F', 'uniffi', '-p', 'libthreema', '--release'
  96. }
  97. // Define the task to generate the uniffi bindings for libthreema
  98. def uniffiBindings = tasks.register("generateUniFFIBindings") {
  99. dependsOn generateLibthreema
  100. doLast {
  101. exec {
  102. // It seems that the uniffi package generates a "*.so" file on linux and a "*.dylib" on mac
  103. // while using the cargo build command from the gradle task above ("generateLibthreema").
  104. final String uniffiLibraryFilePathPrefix = "${project.projectDir}/libthreema/target/release/liblibthreema"
  105. File uniffiLibraryFile = file("${uniffiLibraryFilePathPrefix}.so")
  106. if (!uniffiLibraryFile.exists()) {
  107. uniffiLibraryFile = file("${uniffiLibraryFilePathPrefix}.dylib")
  108. }
  109. assert uniffiLibraryFile.exists(): "Error: Missing pre-generated uniffy library file in libthreema/target/*/ directory.\n"
  110. workingDir "${project.projectDir}/libthreema"
  111. commandLine 'cargo', 'run', '-p', 'uniffi-bindgen', 'generate', '--library', "${uniffiLibraryFile.path}", '--language', 'kotlin', '--out-dir', "${bindingsDirectory}", '--no-format'
  112. }
  113. }
  114. }
  115. tasks["compileKotlin"].dependsOn(uniffiBindings)
  116. }
  117. publishing {
  118. publications {
  119. library(MavenPublication) {
  120. from components.java
  121. version getGitVersion()
  122. }
  123. }
  124. repositories {
  125. maven {
  126. url System.getenv("CI_API_V4_URL") + "/projects/" + System.getenv("CI_PROJECT_ID") + "/packages/maven"
  127. name "Gitlab"
  128. credentials(HttpHeaderCredentials) {
  129. name = 'Job-Token'
  130. value = System.getenv("CI_JOB_TOKEN")
  131. }
  132. authentication {
  133. header(HttpHeaderAuthentication)
  134. }
  135. }
  136. }
  137. }
  138. tasks.register('compileProto', Exec) {
  139. workingDir "${project.projectDir}"
  140. commandLine './compile-proto.sh'
  141. }
  142. tasks.compileKotlin.dependsOn(compileProto)
  143. tasks.register('libthreemaCleanUp', Exec) {
  144. workingDir "${project.projectDir}/libthreema"
  145. commandLine 'cargo', 'clean'
  146. }
  147. tasks.clean.dependsOn(libthreemaCleanUp)
  148. java.targetCompatibility = JavaVersion.VERSION_11
  149. sourceCompatibility = JavaVersion.VERSION_11