Skip to content

Commit 58ab3f5

Browse files
authored
Use Java 8 as Target for Gradle Example (#339)
As discussed in gradle/gradle#33964 and apache/logging-log4j2#3754, Gradle fails the build if a `compileOnly` dependency is not compatible with the Java version specified via `options.release`, even though such dependencies don’t impact runtime behavior. This PR updates the Gradle example to explicitly target **Java 8**, allowing us to surface and detect such compatibility issues through our regression tests. This helps ensure our published artifacts remain usable in Gradle builds targeting Java 8, and catches potential issues earlier in our release cycle.
1 parent 09b14de commit 58ab3f5

File tree

3 files changed

+7
-22
lines changed

3 files changed

+7
-22
lines changed

log4j-samples-gradle-metadata/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ dependencies {
3030
}
3131

3232
tasks.withType(JavaCompile).configureEach {
33+
// Test compatibility of `compileOnly` dependencies with Java 8
34+
//
35+
// See: https://github.com/gradle/gradle/issues/33964
36+
options.release = 8
3337
options.compilerArgs.add("-Werror") // treat all warnings as errors
3438
options.compilerArgs.add("-Xlint:all") // includes 'classfile' check
3539
}
@@ -55,14 +59,14 @@ tasks.register("assertRuntimeClasspath") {
5559
inputs.files(configurations.runtimeClasspath)
5660
doLast {
5761
def actual = inputs.files.collect { it.name.replaceAll("-[0-9].*", "") }
58-
assert actual.sort() == expectedRuntimeClasspath : "Unexpected runtime classpath: $actual"
62+
assert actual.sort() == expectedRuntimeClasspath : "Unexpected runtime classpath:\nActual: $actual\nExpected: $expectedRuntimeClasspath"
5963
}
6064
}
6165
tasks.register("assertCompileClasspath") {
6266
inputs.files(configurations.compileClasspath)
6367
doLast {
6468
def actual = inputs.files.collect { it.name.replaceAll("-[0-9].*", "") }
65-
assert actual.sort() == expectedCompileClasspath : "Unexpected compile classpath: $actual"
69+
assert actual.sort() == expectedCompileClasspath : "Unexpected compile classpath:\nActual: $actual\nExpected: $expectedCompileClasspath"
6670
}
6771
}
6872

log4j-samples-gradle-metadata/src/main/java/module-info.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

log4j-samples-gradle-metadata/src/main/java/org/example/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public class App {
2424
org.apache.logging.log4j.spi.LoggerRegistry<?> r; // needs jspecify
2525

2626
public static void main(String[] args) {
27-
System.out.println("Hello from: " + App.class.getModule().getName());
27+
System.out.println("Hello from: " + App.class.getName());
2828
}
2929
}

0 commit comments

Comments
 (0)