build.gradle 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.3.72'
  9. id 'org.jetbrains.kotlin.kapt' version '1.3.72'
  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.3.72'
  19. implementation 'io.javalin:javalin:3.5.0'
  20. implementation 'org.slf4j:slf4j-simple:1.7.26'
  21. implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.0'
  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.9.3'
  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. String[] architectures = ["linux-aarch64", "linux-armhf", "linux-x86_64"]
  52. for (String arch : architectures) {
  53. if (arch != jarArchitecture) {
  54. exclude "obfs4proxy_" + arch + ".zip"
  55. exclude "tor_" + arch + ".zip"
  56. }
  57. }
  58. }
  59. jarTask.with jar
  60. jarTask.doLast {
  61. // Rename the original jar
  62. File jar = jarTask.archivePath
  63. String srcPath = jar.toString().replaceFirst('\\.jar$', '.unsorted.jar')
  64. File srcFile = new File(srcPath)
  65. jar.renameTo(srcFile)
  66. JarFile srcJarFile = new JarFile(srcFile)
  67. OutputStream destStream = new JarOutputStream(new FileOutputStream(jar))
  68. // Read and sort the entries
  69. Map<String, JarEntry> entries = new TreeMap<>()
  70. for (JarEntry e : list(srcJarFile.entries())) entries.put(e.getName(), e)
  71. // Write the sorted entries
  72. for (JarEntry srcEntry : entries.values()) {
  73. JarEntry destEntry = new JarEntry(srcEntry.getName())
  74. destEntry.setTime(0)
  75. destStream.putNextEntry(destEntry)
  76. InputStream srcStream = srcJarFile.getInputStream(srcEntry)
  77. int read
  78. byte[] buf = new byte[4096]
  79. while ((read = srcStream.read(buf, 0, buf.length)) != -1) {
  80. destStream.write(buf, 0, read)
  81. }
  82. destStream.closeEntry()
  83. srcStream.close()
  84. }
  85. destStream.close()
  86. srcJarFile.close()
  87. println 'Building ' + jarArchitecture + ' version has finished'
  88. }
  89. }
  90. task aarch64LinuxJar(type: Jar) {
  91. jarFactory(it, 'linux-aarch64')
  92. }
  93. task armhfLinuxJar(type: Jar) {
  94. jarFactory(it, 'linux-armhf')
  95. }
  96. task x86LinuxJar(type: Jar) {
  97. jarFactory(it, 'linux-x86_64')
  98. }
  99. // At the moment for non-Android projects we need to explicitly mark the code generated by kapt
  100. // as 'generated source code' for correct highlighting and resolve in IDE.
  101. idea {
  102. module {
  103. sourceDirs += file('build/generated/source/kapt/main')
  104. testSourceDirs += file('build/generated/source/kapt/test')
  105. generatedSourceDirs += file('build/generated/source/kapt/main')
  106. }
  107. }
  108. test {
  109. useJUnitPlatform()
  110. testLogging {
  111. events "passed", "skipped", "failed"
  112. }
  113. }