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

This commit is contained in:
Laplie Anderson 2019-09-04 13:10:32 -04:00
parent a3d792b4b9
commit be60d362ae
3 changed files with 32 additions and 20 deletions

View File

@ -1,17 +1,9 @@
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)
tasks.withType(BaseTask).each {
it.enabled = JavaVersion.VERSION_1_9.compareTo(JavaVersion.current()) <= 0
}
if (JavaVersion.VERSION_1_9.compareTo(javaVersion) > 0) {
return
}
test {
dependsOn tasks.jlink
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
}
}
it.jvmArgs "-Ddatadog.smoketest.module.image=${generatedImageDir}"
it.dependsOn jar
}
dependencies {
testCompile project(':dd-smoke-tests')
}
}

View File

@ -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)

View File

@ -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