Skip to content

Commit 9cc2f16

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

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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

Lines changed: 21 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,21 @@ protected ToolProvider getJarTool() throws MojoException {
230232
return ToolProvider.findFirst(toolId).orElseThrow(() -> new MojoException("No such \"" + toolId + "\" tool."));
231233
}
232234

235+
/**
236+
* Returns whether the given release is supported.
237+
* TODO: should check is a toolchain is used.
238+
*
239+
* @param release name of an {@link SourceVersion} enumeration constant
240+
* @return whether the current environment support that version
241+
*/
242+
private static boolean isSupported(String release) {
243+
try {
244+
return SourceVersion.latestSupported().compareTo(SourceVersion.valueOf(release)) >= 0;
245+
} catch (IllegalArgumentException e) {
246+
return false;
247+
}
248+
}
249+
233250
/**
234251
* Returns the output time stamp or, as a fallback, the {@code SOURCE_DATE_EPOCH} environment variable.
235252
* If the time stamp is expressed in seconds, it is converted to ISO 8601 format. Otherwise it is returned as-is.
@@ -246,6 +263,10 @@ protected String getOutputTimestamp() {
246263
return null;
247264
}
248265
}
266+
if (!isSupported("RELEASE_19")) {
267+
log.warn("Reproducible build requires Java 19 or later.");
268+
return null;
269+
}
249270
for (int i = time.length(); --i >= 0; ) {
250271
char c = time.charAt(i);
251272
if ((c < '0' || c > '9') && (i != 0 || c != '-')) {

0 commit comments

Comments
 (0)