Disable task if version is too low.  Include all sourcesets in jars
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
}
@@ -8,9 +10,6 @@ ext {
apply from: "${rootDir}/gradle/java.gradle"
-sourceCompatibility = "1.9"
-targetCompatibility = "1.9"
-
mainClassName = 'datadog.smoketest.moduleapp.ModuleApplication'
jar {
@@ -26,6 +25,10 @@ jlink {
options = ['--no-man-pages', '--no-header-files', '--add-modules', 'java.instrument']
}
+tasks.withType(BaseTask).each {
+ it.enabled = JavaVersion.VERSION_1_9.compareTo(JavaVersion.current()) <= 0
+}
+
test {
dependsOn tasks.jlink
jvmArgs "-Ddatadog.smoketest.module.image=${jlink.imageDir.get()}"

RENAME
dd-smoke-tests/java9-modules/src/main/java/datadog/smoketest/moduleapp/ModuleApplication.java
dd-smoke-tests/java9-modules/src/main/java9/datadog/smoketest/moduleapp/ModuleApplication.java
RENAME
dd-smoke-tests/java9-modules/src/main/java/module-info.java
dd-smoke-tests/java9-modules/src/main/java9/module-info.java
MODIFY
gradle/java.gradle
gradle/java.gradle
@@ -40,6 +40,10 @@ if (project.hasProperty('minJavaVersionForTests') && project.getProperty('minJav
"main_${name}AnnotationProcessor" "org.projectlombok:lombok:${project.lombok.version}" transitive false
}
+ jar {
+ from sourceSets."main_$name".output
+ }
+
tasks.withType(JavaCompile).configureEach {
if (it.name.toLowerCase().contains("test")) {
sourceCompatibility = version
@@ -55,6 +59,7 @@ java {
[JavaCompile, ScalaCompile].each { type ->
tasks.withType(type) {
+ onlyIf { JavaVersion.toVersion(sourceCompatibility).compareTo(JavaVersion.current()) <= 0 }
doFirst {
// We do this specifically for Java7 bytecode generation because we would like to be able to compile
// with Java8+ compiler. This likely would require some modifications when we switch to java11 compiler.

Disable task if version is too low.  Include all sourcesets in jars