build.gradle 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.40'
  9. id 'org.jetbrains.kotlin.kapt' version '1.3.40'
  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.40'
  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. jar {
  38. manifest {
  39. attributes(
  40. 'Main-Class': 'org.briarproject.briar.headless.MainKt'
  41. )
  42. }
  43. from {
  44. configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
  45. }
  46. doLast() {
  47. // Rename the original jar
  48. File jar = project.jar.archivePath
  49. String srcPath = jar.toString().replaceFirst('\\.jar$', '.unsorted.jar')
  50. File srcFile = new File(srcPath)
  51. jar.renameTo(srcFile)
  52. JarFile srcJarFile = new JarFile(srcFile)
  53. OutputStream destStream = new JarOutputStream(new FileOutputStream(jar))
  54. // Read and sort the entries
  55. Map<String, JarEntry> entries = new TreeMap<String, JarEntry>()
  56. for (JarEntry e : list(srcJarFile.entries())) entries.put(e.getName(), e)
  57. // Write the sorted entries
  58. for (JarEntry srcEntry : entries.values()) {
  59. JarEntry destEntry = new JarEntry(srcEntry.getName())
  60. destEntry.setTime(0)
  61. destStream.putNextEntry(destEntry)
  62. InputStream srcStream = srcJarFile.getInputStream(srcEntry)
  63. int read
  64. byte[] buf = new byte[4096]
  65. while ((read = srcStream.read(buf, 0, buf.length)) != -1) {
  66. destStream.write(buf, 0, read)
  67. }
  68. destStream.closeEntry()
  69. srcStream.close()
  70. }
  71. destStream.close()
  72. srcJarFile.close()
  73. }
  74. }
  75. // At the moment for non-Android projects we need to explicitly mark the code generated by kapt
  76. // as 'generated source code' for correct highlighting and resolve in IDE.
  77. idea {
  78. module {
  79. sourceDirs += file('build/generated/source/kapt/main')
  80. testSourceDirs += file('build/generated/source/kapt/test')
  81. generatedSourceDirs += file('build/generated/source/kapt/main')
  82. }
  83. }
  84. test {
  85. useJUnitPlatform()
  86. testLogging {
  87. events "passed", "skipped", "failed"
  88. }
  89. }