build.gradle 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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' version '1.4.32'
  9. id 'org.jetbrains.kotlin.kapt' version '1.4.32'
  10. id 'witness'
  11. }
  12. apply from: 'witness.gradle'
  13. sourceCompatibility = 1.8
  14. targetCompatibility = 1.8
  15. dependencies {
  16. implementation project(path: ':briar-core', configuration: 'default')
  17. implementation project(path: ':bramble-java', configuration: 'default')
  18. implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.32'
  19. implementation 'io.javalin:javalin:3.5.0'
  20. implementation 'org.slf4j:slf4j-simple:1.7.30'
  21. implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
  22. implementation 'com.github.ajalt:clikt:2.2.0'
  23. def daggerVersion = '2.24'
  24. kapt "com.google.dagger:dagger-compiler:$daggerVersion"
  25. testImplementation project(path: ':bramble-api', configuration: 'testOutput')
  26. testImplementation project(path: ':bramble-core', configuration: 'testOutput')
  27. testImplementation project(path: ':briar-core', configuration: 'testOutput')
  28. def junitVersion = '5.5.2'
  29. testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
  30. testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion"
  31. testRuntime "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
  32. testImplementation 'io.mockk:mockk:1.10.4'
  33. testImplementation 'org.skyscreamer:jsonassert:1.5.0'
  34. testImplementation 'khttp:khttp:0.1.0'
  35. kaptTest "com.google.dagger:dagger-compiler:$daggerVersion"
  36. }
  37. void jarFactory(Jar jarTask, jarArchitecture) {
  38. jarTask.doFirst {
  39. println 'Building ' + jarArchitecture + ' version has started'
  40. }
  41. jarTask.manifest {
  42. attributes(
  43. 'Main-Class': 'org.briarproject.briar.headless.MainKt'
  44. )
  45. }
  46. jarTask.setArchiveClassifier(jarArchitecture)
  47. jarTask.from {
  48. configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
  49. }
  50. {
  51. it.duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
  52. String[] architectures = ["linux-aarch64", "linux-armhf", "linux-x86_64"]
  53. for (String arch : architectures) {
  54. if (arch != jarArchitecture) {
  55. exclude "obfs4proxy_" + arch + ".zip"
  56. exclude "tor_" + arch + ".zip"
  57. }
  58. }
  59. exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA'
  60. }
  61. jarTask.with jar
  62. jarTask.doLast {
  63. // Rename the original jar
  64. File jar = jarTask.archivePath
  65. String srcPath = jar.toString().replaceFirst('\\.jar$', '.unsorted.jar')
  66. File srcFile = new File(srcPath)
  67. jar.renameTo(srcFile)
  68. JarFile srcJarFile = new JarFile(srcFile)
  69. OutputStream destStream = new JarOutputStream(new FileOutputStream(jar))
  70. // Read and sort the entries
  71. Map<String, JarEntry> entries = new TreeMap<>()
  72. for (JarEntry e : list(srcJarFile.entries())) entries.put(e.getName(), e)
  73. // Write the sorted entries
  74. for (JarEntry srcEntry : entries.values()) {
  75. JarEntry destEntry = new JarEntry(srcEntry.getName())
  76. destEntry.setTime(0)
  77. destStream.putNextEntry(destEntry)
  78. InputStream srcStream = srcJarFile.getInputStream(srcEntry)
  79. int read
  80. byte[] buf = new byte[4096]
  81. while ((read = srcStream.read(buf, 0, buf.length)) != -1) {
  82. destStream.write(buf, 0, read)
  83. }
  84. destStream.closeEntry()
  85. srcStream.close()
  86. }
  87. destStream.close()
  88. srcJarFile.close()
  89. println 'Building ' + jarArchitecture + ' version has finished'
  90. }
  91. }
  92. task aarch64LinuxJar(type: Jar) {
  93. jarFactory(it, 'linux-aarch64')
  94. }
  95. task armhfLinuxJar(type: Jar) {
  96. jarFactory(it, 'linux-armhf')
  97. }
  98. task x86LinuxJar(type: Jar) {
  99. jarFactory(it, 'linux-x86_64')
  100. }
  101. task linuxJars {
  102. dependsOn(aarch64LinuxJar, armhfLinuxJar, x86LinuxJar)
  103. }
  104. // At the moment for non-Android projects we need to explicitly mark the code generated by kapt
  105. // as 'generated source code' for correct highlighting and resolve in IDE.
  106. idea {
  107. module {
  108. sourceDirs += file('build/generated/source/kapt/main')
  109. testSourceDirs += file('build/generated/source/kapt/test')
  110. generatedSourceDirs += file('build/generated/source/kapt/main')
  111. }
  112. }
  113. test {
  114. useJUnitPlatform()
  115. testLogging {
  116. events "passed", "skipped", "failed"
  117. }
  118. }