build.gradle 5.3 KB

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