build.gradle.kts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import com.android.build.gradle.internal.tasks.factory.dependsOn
  2. import utils.getGitVersion
  3. plugins {
  4. alias(libs.plugins.sonarqube)
  5. alias(libs.plugins.java.library)
  6. alias(libs.plugins.java.testFixtures)
  7. alias(libs.plugins.kotlin.jvm)
  8. alias(libs.plugins.mavenPublish)
  9. alias(libs.plugins.jacoco)
  10. }
  11. dependencies {
  12. implementation(project(":common"))
  13. api(libs.kotlin.stdlib)
  14. api(libs.kotlinx.coroutines.core)
  15. api(libs.libphonenumber)
  16. api(libs.androidx.annotation)
  17. api(libs.streamsupport.flow)
  18. api(libs.protobuf.kotlin.lite)
  19. implementation(libs.slf4j.api)
  20. implementation(libs.commonsIo)
  21. implementation(libs.eddsa)
  22. implementation(libs.kotlinx.coroutines.android)
  23. implementation(libs.jna)
  24. testImplementation(libs.junit)
  25. testImplementation(libs.mockk)
  26. testImplementation(libs.kotlinx.coroutines.test)
  27. testImplementation(libs.slf4j.simple)
  28. testImplementation(libs.kotlin.test)
  29. testImplementation(project(":test-helpers"))
  30. }
  31. sourceSets {
  32. assert(file("./protocol/src/common.proto").exists()) {
  33. "Error: Git protobuf submodule missing. Please run `git submodule update --init`.\n"
  34. }
  35. main {
  36. java.srcDir("./build/generated/source/proto/main/java")
  37. java.srcDir("./build/generated/source/proto/main/kotlin")
  38. java.srcDir("./build/generated/source/libthreema")
  39. }
  40. }
  41. tasks.withType<Test> {
  42. // Necessary to load the dynamic libthreema library in unit tests
  43. systemProperty("jna.library.path", "${project.projectDir}/libthreema/target/release")
  44. useJUnitPlatform()
  45. }
  46. tasks.withType<JacocoReport> {
  47. reports {
  48. xml.required = true
  49. html.required = false
  50. }
  51. }
  52. sonarqube {
  53. properties {
  54. property("sonar.projectKey", "android-client")
  55. property("sonar.projectName", "Threema for Android")
  56. property("sonar.sources", "src/main/")
  57. property("sonar.exclusions", "src/main/java/ove/crypto/**")
  58. property("sonar.tests", "src/test/")
  59. property("sonar.sourceEncoding", "UTF-8")
  60. property("sonar.verbose", "true")
  61. property(
  62. "sonar.coverage.jacoco.xmlReportPaths",
  63. "${projectDir.parentFile.path}/build/reports/jacoco/codeCoverageReport/codeCoverageReport.xml",
  64. )
  65. }
  66. }
  67. afterEvaluate {
  68. val bindingsDirectory = "../build/generated/source/libthreema"
  69. // Define the task to generate libthreema library (only used to generate bindings for it)
  70. val generateLibthreema = tasks.register<Exec>("generateLibthreema") {
  71. workingDir("${project.projectDir}/libthreema")
  72. commandLine("cargo", "build", "-F", "uniffi", "-p", "libthreema", "--release", "--locked")
  73. }
  74. // Define the task to generate the uniffi bindings for libthreema
  75. val uniffiBindings = tasks.register("generateUniFFIBindings") {
  76. dependsOn(generateLibthreema)
  77. doLast {
  78. // It seems that the uniffi package generates a "*.so" file on linux and a "*.dylib" on mac
  79. // while using the cargo build command from the gradle task above ("generateLibthreema").
  80. val uniffiLibraryFilePathPrefix = "${project.projectDir}/libthreema/target/release/liblibthreema"
  81. val uniffiLibraryFile = file("$uniffiLibraryFilePathPrefix.so")
  82. .takeIf { it.exists() }
  83. ?: file("$uniffiLibraryFilePathPrefix.dylib")
  84. assert(uniffiLibraryFile.exists()) {
  85. "Error: Missing pre-generated uniffy library file in libthreema/target/*/ directory.\n"
  86. }
  87. val processBuilder = ProcessBuilder(
  88. "cargo",
  89. "run",
  90. "-p",
  91. "uniffi-bindgen",
  92. "generate",
  93. "--library",
  94. uniffiLibraryFile.path,
  95. "--language",
  96. "kotlin",
  97. "--out-dir",
  98. bindingsDirectory,
  99. "--no-format",
  100. )
  101. processBuilder.directory(file("${project.projectDir}/libthreema"))
  102. processBuilder.start().waitFor()
  103. }
  104. }
  105. tasks["compileKotlin"].dependsOn(uniffiBindings)
  106. }
  107. publishing {
  108. publications {
  109. register<MavenPublication>("library") {
  110. from(components["java"])
  111. version = getGitVersion()
  112. }
  113. }
  114. repositories {
  115. maven {
  116. url = run {
  117. val apiV4Url = System.getenv("CI_API_V4_URL")
  118. val projectId = System.getenv("CI_PROJECT_ID")
  119. uri("$apiV4Url/projects/$projectId/packages/maven")
  120. }
  121. name = "Gitlab"
  122. credentials(HttpHeaderCredentials::class.java) {
  123. name = "Job-Token"
  124. value = System.getenv("CI_JOB_TOKEN")
  125. }
  126. authentication {
  127. create<HttpHeaderAuthentication>("header")
  128. }
  129. }
  130. }
  131. }
  132. tasks.register<Exec>("compileProto") {
  133. group = "build"
  134. description = "generate class bindings from protobuf files in the 'protocol/src' directory"
  135. workingDir(project.projectDir)
  136. commandLine("./compile-proto.sh")
  137. }
  138. tasks.compileKotlin.dependsOn("compileProto")
  139. tasks.register<Exec>("libthreemaCleanUp") {
  140. workingDir("${project.projectDir}/libthreema")
  141. commandLine("cargo", "clean")
  142. }
  143. tasks.clean.dependsOn("libthreemaCleanUp")
  144. java {
  145. sourceCompatibility = JavaVersion.VERSION_11
  146. targetCompatibility = JavaVersion.VERSION_11
  147. }
  148. kotlin {
  149. compilerOptions {
  150. jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
  151. }
  152. }