build.gradle 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import java.util.jar.JarEntry
  2. import java.util.jar.JarFile
  3. import java.util.jar.JarOutputStream
  4. import static java.util.Collections.list
  5. plugins {
  6. id 'java'
  7. id 'idea'
  8. id 'org.jetbrains.kotlin.jvm'
  9. id 'org.jetbrains.kotlin.kapt'
  10. id 'witness'
  11. }
  12. apply from: 'witness.gradle'
  13. configurations {
  14. windows {
  15. extendsFrom runtimeClasspath
  16. }
  17. linux {
  18. extendsFrom runtimeClasspath
  19. }
  20. }
  21. sourceCompatibility = 1.8
  22. targetCompatibility = 1.8
  23. dependencies {
  24. implementation project(':bramble-core')
  25. implementation project(':bramble-java')
  26. implementation project(':briar-core')
  27. linux "org.briarproject:tor-linux:$tor_version"
  28. linux "org.briarproject:obfs4proxy-linux:$obfs4proxy_version"
  29. linux "org.briarproject:snowflake-linux:$snowflake_version"
  30. windows "org.briarproject:tor-windows:$tor_version"
  31. windows "org.briarproject:obfs4proxy-windows:$obfs4proxy_version"
  32. windows "org.briarproject:snowflake-windows:$snowflake_version"
  33. implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
  34. implementation 'io.javalin:javalin:3.5.0'
  35. implementation 'org.slf4j:slf4j-simple:1.7.30'
  36. implementation 'com.github.ajalt:clikt:2.2.0'
  37. implementation "org.bouncycastle:bcprov-jdk15to18:$bouncy_castle_version"
  38. implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
  39. implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
  40. implementation "org.briarproject:onionwrapper-java:$onionwrapper_version"
  41. kapt "com.google.dagger:dagger-compiler:$dagger_version"
  42. testImplementation project(path: ':bramble-api', configuration: 'testOutput')
  43. testImplementation project(path: ':bramble-core', configuration: 'testOutput')
  44. testImplementation project(path: ':briar-core', configuration: 'testOutput')
  45. def junitVersion = '5.5.2'
  46. testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
  47. testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
  48. testImplementation 'io.mockk:mockk:1.12.4'
  49. testImplementation 'org.skyscreamer:jsonassert:1.5.0'
  50. testImplementation "com.squareup.okhttp3:okhttp:4.10.0"
  51. testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
  52. kaptTest "com.google.dagger:dagger-compiler:$dagger_version"
  53. }
  54. void jarFactory(Jar jarTask, os, architecture, configuration) {
  55. def jarArchitecture = os + "-" + architecture
  56. jarTask.dependsOn(
  57. ':bramble-api:jar',
  58. ':bramble-core:jar',
  59. ':bramble-java:jar',
  60. ':briar-api:jar',
  61. ':briar-core:jar'
  62. )
  63. jarTask.dependsOn(jar)
  64. jarTask.doFirst {
  65. println 'Building ' + jarArchitecture + ' version has started'
  66. }
  67. jarTask.manifest {
  68. attributes(
  69. 'Main-Class': 'org.briarproject.briar.headless.MainKt'
  70. )
  71. }
  72. jarTask.setArchiveClassifier(jarArchitecture)
  73. jarTask.from {
  74. configuration.collect { it.isDirectory() ? it : zipTree(it) }
  75. }
  76. {
  77. it.duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
  78. if (os == "linux") {
  79. String[] architectures = [
  80. "aarch64",
  81. "armhf",
  82. "x86_64",
  83. ]
  84. for (String arch : architectures) {
  85. if (arch != architecture) {
  86. exclude arch + "/obfs4proxy"
  87. exclude arch + "/tor"
  88. exclude arch + "/snowflake"
  89. }
  90. }
  91. }
  92. exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA'
  93. }
  94. jarTask.with jar
  95. jarTask.doLast {
  96. // Rename the original jar
  97. File jar = jarTask.archiveFile.get().asFile
  98. String srcPath = jar.toString().replaceFirst('\\.jar$', '.unsorted.jar')
  99. File srcFile = new File(srcPath)
  100. jar.renameTo(srcFile)
  101. JarFile srcJarFile = new JarFile(srcFile)
  102. OutputStream destStream = new JarOutputStream(new FileOutputStream(jar))
  103. // Read and sort the entries
  104. Map<String, JarEntry> entries = new TreeMap<>()
  105. for (JarEntry e : list(srcJarFile.entries())) entries.put(e.getName(), e)
  106. // Write the sorted entries
  107. for (JarEntry srcEntry : entries.values()) {
  108. JarEntry destEntry = new JarEntry(srcEntry.getName())
  109. destEntry.setTime(0)
  110. destStream.putNextEntry(destEntry)
  111. InputStream srcStream = srcJarFile.getInputStream(srcEntry)
  112. int read
  113. byte[] buf = new byte[4096]
  114. while ((read = srcStream.read(buf, 0, buf.length)) != -1) {
  115. destStream.write(buf, 0, read)
  116. }
  117. destStream.closeEntry()
  118. srcStream.close()
  119. }
  120. destStream.close()
  121. srcJarFile.close()
  122. println 'Building ' + jarArchitecture + ' version has finished'
  123. }
  124. }
  125. task aarch64LinuxJar(type: Jar) {
  126. jarFactory(it, 'linux', 'aarch64', configurations.linux)
  127. }
  128. task armhfLinuxJar(type: Jar) {
  129. jarFactory(it, 'linux', 'armhf', configurations.linux)
  130. }
  131. task x86LinuxJar(type: Jar) {
  132. jarFactory(it, 'linux', 'x86_64', configurations.linux)
  133. }
  134. task windowsJar(type: Jar) {
  135. jarFactory(it, 'windows', 'x86_64', configurations.windows)
  136. }
  137. task linuxJars {
  138. dependsOn(aarch64LinuxJar, armhfLinuxJar, x86LinuxJar)
  139. }
  140. // At the moment for non-Android projects we need to explicitly mark the code generated by kapt
  141. // as 'generated source code' for correct highlighting and resolve in IDE.
  142. idea {
  143. module {
  144. sourceDirs += file('build/generated/source/kapt/main')
  145. testSourceDirs += file('build/generated/source/kapt/test')
  146. generatedSourceDirs += file('build/generated/source/kapt/main')
  147. }
  148. }
  149. test {
  150. useJUnitPlatform()
  151. testLogging {
  152. events "passed", "skipped", "failed"
  153. }
  154. }