build.gradle.kts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. plugins {
  2. id("otel.javaagent-instrumentation")
  3. }
  4. muzzle {
  5. pass {
  6. coreJdk()
  7. }
  8. }
  9. dependencies {
  10. compileOnly(project(":instrumentation:rmi:bootstrap"))
  11. }
  12. tasks {
  13. val rmic by registering(Exec::class) {
  14. dependsOn(testClasses)
  15. val clazz = "rmi.app.ServerLegacy"
  16. val rmicBinaryPath = listOf("/bin/rmic", "/../bin/rmic").map {
  17. File(System.getProperty("java.home"), it).absoluteFile
  18. }.find { it.isFile() }?.let(File::toString) ?: "rmic"
  19. commandLine(rmicBinaryPath, "-g", "-keep", "-classpath", sourceSets.test.get().output.classesDirs.asPath, "-d", "$buildDir/classes/java/test", clazz)
  20. }
  21. named<Test>("test") {
  22. dependsOn(rmic)
  23. }
  24. }
  25. // We cannot use "--release" javac option here because that will forbid importing "sun.rmi" package.
  26. // We also can't seem to use the toolchain without the "--release" option. So disable everything.
  27. java {
  28. sourceCompatibility = JavaVersion.VERSION_1_8
  29. targetCompatibility = JavaVersion.VERSION_1_8
  30. toolchain {
  31. languageVersion.set(null as JavaLanguageVersion?)
  32. }
  33. }
  34. tasks {
  35. withType<JavaCompile>().configureEach {
  36. options.release.set(null as Int?)
  37. }
  38. withType<GroovyCompile>().configureEach {
  39. options.release.set(null as Int?)
  40. }
  41. withType<Test>().configureEach {
  42. jvmArgs("-Djava.rmi.server.hostname=127.0.0.1")
  43. // Can only export on Java 9+
  44. val testJavaVersion = gradle.startParameter.projectProperties.get("testJavaVersion")?.let(JavaVersion::toVersion) ?: JavaVersion.current()
  45. if (testJavaVersion.isJava9Compatible) {
  46. jvmArgs("--add-exports=java.rmi/sun.rmi.server=ALL-UNNAMED")
  47. jvmArgs("--add-exports=java.rmi/sun.rmi.transport=ALL-UNNAMED")
  48. }
  49. }
  50. }