Skip to content

Commit 78039b6

Browse files
committed
Whether the --date option is supported depends on the Java version.
1 parent cf2a275 commit 78039b6

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/it/MJAR-275-reproducible-module-info/invoker.properties

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
# to you under the Apache License, Version 2.0 (the
66
# "License"); you may not use this file except in compliance
77
# with the License. You may obtain a copy of the License at
8-
#
8+
#
99
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing,
1212
# software distributed under the License is distributed on an
1313
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
# NOTE: Requires Java 10+ to compile the module declaration for Java 9+,
19-
# this is due that compiling the module declaration generates a
20-
# module descriptor with the JDK version on it, making it unreproducible.
21-
invoker.java.version = 10+
18+
# The --date option needed for reproducible build is available only since Java 19.
19+
invoker.java.version = 19+

src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.maven.plugins.jar;
2020

21+
import javax.lang.model.SourceVersion;
22+
2123
import java.io.IOException;
2224
import java.nio.file.Files;
2325
import java.nio.file.Path;
@@ -230,6 +232,20 @@ protected ToolProvider getJarTool() throws MojoException {
230232
return ToolProvider.findFirst(toolId).orElseThrow(() -> new MojoException("No such \"" + toolId + "\" tool."));
231233
}
232234

235+
/**
236+
* Returns whether the specified Java version is supported.
237+
*
238+
* @param release name of an {@link SourceVersion} enumeration constant
239+
* @return whether the current environment support that version
240+
*/
241+
private static boolean isSupported(String release) {
242+
try {
243+
return SourceVersion.latestSupported().compareTo(SourceVersion.valueOf(release)) >= 0;
244+
} catch (IllegalArgumentException e) {
245+
return false;
246+
}
247+
}
248+
233249
/**
234250
* Returns the output time stamp or, as a fallback, the {@code SOURCE_DATE_EPOCH} environment variable.
235251
* If the time stamp is expressed in seconds, it is converted to ISO 8601 format. Otherwise it is returned as-is.
@@ -246,6 +262,10 @@ protected String getOutputTimestamp() {
246262
return null;
247263
}
248264
}
265+
if (!isSupported("RELEASE_19")) {
266+
log.warn("Reproducible build requires Java 19 or later.");
267+
return null;
268+
}
249269
for (int i = time.length(); --i >= 0; ) {
250270
char c = time.charAt(i);
251271
if ((c < '0' || c > '9') && (i != 0 || c != '-')) {

0 commit comments

Comments
 (0)