This is an automated email from the ASF dual-hosted git repository. pkarwasz pushed a commit to branch feat/gradle-compile-only-java-8 in repository https://gitbox.apache.org/repos/asf/logging-log4j-samples.git
commit c20baf824b909f07bb68e7e351fa9ed3aa573039 Author: Piotr P. Karwasz <pkarwasz-git...@apache.org> AuthorDate: Sat Jun 21 16:55:30 2025 +0200 Use Java 8 as Target for Gradle Example 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. --- log4j-samples-gradle-metadata/build.gradle | 8 ++++++-- .../src/main/java/module-info.java | 19 ------------------- .../src/main/java/org/example/App.java | 2 +- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/log4j-samples-gradle-metadata/build.gradle b/log4j-samples-gradle-metadata/build.gradle index b4b40eb..a8be180 100644 --- a/log4j-samples-gradle-metadata/build.gradle +++ b/log4j-samples-gradle-metadata/build.gradle @@ -30,6 +30,10 @@ dependencies { } tasks.withType(JavaCompile).configureEach { + // Test compatibility of `compileOnly` dependencies with Java 8 + // + // See: https://github.com/gradle/gradle/issues/33964 + options.release = 8 options.compilerArgs.add("-Werror") // treat all warnings as errors options.compilerArgs.add("-Xlint:all") // includes 'classfile' check } @@ -55,14 +59,14 @@ tasks.register("assertRuntimeClasspath") { inputs.files(configurations.runtimeClasspath) doLast { def actual = inputs.files.collect { it.name.replaceAll("-[0-9].*", "") } - assert actual.sort() == expectedRuntimeClasspath : "Unexpected runtime classpath: $actual" + assert actual.sort() == expectedRuntimeClasspath : "Unexpected runtime classpath:\nActual: $actual\nExpected: $expectedRuntimeClasspath" } } tasks.register("assertCompileClasspath") { inputs.files(configurations.compileClasspath) doLast { def actual = inputs.files.collect { it.name.replaceAll("-[0-9].*", "") } - assert actual.sort() == expectedCompileClasspath : "Unexpected compile classpath: $actual" + assert actual.sort() == expectedCompileClasspath : "Unexpected compile classpath:\nActual: $actual\nExpected: $expectedCompileClasspath" } } diff --git a/log4j-samples-gradle-metadata/src/main/java/module-info.java b/log4j-samples-gradle-metadata/src/main/java/module-info.java deleted file mode 100644 index b5c6c9c..0000000 --- a/log4j-samples-gradle-metadata/src/main/java/module-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -module org.example.log4j.metadata { - requires org.apache.logging.log4j; -} \ No newline at end of file diff --git a/log4j-samples-gradle-metadata/src/main/java/org/example/App.java b/log4j-samples-gradle-metadata/src/main/java/org/example/App.java index ef45021..5a783a7 100644 --- a/log4j-samples-gradle-metadata/src/main/java/org/example/App.java +++ b/log4j-samples-gradle-metadata/src/main/java/org/example/App.java @@ -24,6 +24,6 @@ public class App { org.apache.logging.log4j.spi.LoggerRegistry<?> r; // needs jspecify public static void main(String[] args) { - System.out.println("Hello from: " + App.class.getModule().getName()); + System.out.println("Hello from: " + App.class.getName()); } }