Manually call jlink because plugin won't work with our build
MODIFY
dd-smoke-tests/java9-modules/java9-modules.gradle
dd-smoke-tests/java9-modules/java9-modules.gradle
-import org.beryx.jlink.BaseTask
-
-plugins {
- id 'org.beryx.jlink' version '2.1.1' // latest version that doesn't have a Java 11+ warning
-}
-
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_9
}
apply from: "${rootDir}/gradle/java.gradle"
-mainClassName = 'datadog.smoketest.moduleapp.ModuleApplication'
-
jar {
manifest {
attributes(
@@ -20,20 +12,32 @@ jar {
}
}
-jlink {
- moduleName = 'datadog.smoketest.moduleapp'
- options = ['--no-man-pages', '--no-header-files', '--add-modules', 'java.instrument']
+/**
+ * For each Test task, creates a jlink image using the java bin directory of the test
+ */
+tasks.withType(Test).each {
+ def javaExecutable = it.executable
+ def javaVersion = getJavaExecutableVersion(javaExecutable)
+
+ if (JavaVersion.VERSION_1_9.compareTo(javaVersion) > 0) {
+ return
}
-tasks.withType(BaseTask).each {
- it.enabled = JavaVersion.VERSION_1_9.compareTo(JavaVersion.current()) <= 0
+ def jlinkExecutable = file(javaExecutable).parent + "/jlink"
+ def generatedImageDir = "${buildDir}/${it.name}image"
+
+ it.doFirst {
+ exec {
+ commandLine jlinkExecutable, '--no-man-pages', '--no-header-files',
+ '--add-modules', 'java.instrument,datadog.smoketest.moduleapp',
+ "--module-path", jar.archiveFile.get().toString(), "--output", generatedImageDir
+ }
}
-test {
- dependsOn tasks.jlink
+ it.jvmArgs "-Ddatadog.smoketest.module.image=${generatedImageDir}"
+ it.dependsOn jar
}
dependencies {
testCompile project(':dd-smoke-tests')
}
\ No newline at end of file
-

MODIFY
dd-smoke-tests/java9-modules/src/test/groovy/datadog/smoketest/Java9ModulesSmokeTest.groovy
dd-smoke-tests/java9-modules/src/test/groovy/datadog/smoketest/Java9ModulesSmokeTest.groovy
@@ -10,8 +10,12 @@ class Java9ModulesSmokeTest extends AbstractSmokeTest {
@Override
ProcessBuilder createProcessBuilder() {
+ String imageDir = System.getProperty("datadog.smoketest.module.image")
+
+ assert imageDir != null
+
List<String> command = new ArrayList<>()
- command.add(buildDirectory + "/image/bin/java")
+ command.add(imageDir + "/bin/java")
command.addAll(defaultJavaProperties)
command.addAll((String[]) ["-m", "datadog.smoketest.moduleapp/datadog.smoketest.moduleapp.ModuleApplication"])
ProcessBuilder processBuilder = new ProcessBuilder(command)

MODIFY
gradle/java.gradle
gradle/java.gradle
@@ -246,6 +246,10 @@ JavaVersion getJavaExecutableVersion(String path) {
}
}
+ext {
+ getJavaExecutableVersion = this.&getJavaExecutableVersion
+}
+
def isJavaVersionAllowed(JavaVersion version) {
if (project.hasProperty('minJavaVersionForTests') && project.getProperty('minJavaVersionForTests').compareTo(version) > 0) {
return false

Manually call jlink because plugin won't work with our build