build.gradle.kts 5.2 KB

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