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