diff --git a/src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java b/src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java index ced1575..37a81f6 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java +++ b/src/main/java/de/thetaphi/forbiddenapis/maven/AbstractCheckMojo.java @@ -185,6 +185,14 @@ public abstract class AbstractCheckMojo extends AbstractMojo implements Constant @Parameter(required = false, defaultValue = "${maven.compiler.target}") private String targetVersion; + /** + * The default compiler release version used to expand references to bundled JDK signatures. + * E.g., if you use "jdk-deprecated", it will expand to this version. + * This setting should be identical to the release version used in the compiler plugin starting with Java 9. + */ + @Parameter(required = false, defaultValue = "${maven.compiler.release}") + private String releaseVersion; + /** * List of patterns matching all class files to be parsed from the classesDirectory. * Can be changed to e.g. exclude several files (using excludes). @@ -248,7 +256,7 @@ public abstract class AbstractCheckMojo extends AbstractMojo implements Constant /** gets overridden for test, because it uses testTargetVersion as optional name to override */ protected String getTargetVersion() { - return targetVersion; + return (releaseVersion != null) ? releaseVersion : targetVersion; } private File resolveSignaturesArtifact(SignaturesArtifact signaturesArtifact) throws ArtifactResolutionException, ArtifactNotFoundException { @@ -385,7 +393,8 @@ public void info(String msg) { String targetVersion = getTargetVersion(); if ("".equals(targetVersion)) targetVersion = null; if (targetVersion == null) { - log.warn("The 'targetVersion' parameter or '${maven.compiler.target}' property is missing. " + + log.warn("The 'targetVersion' and 'targetRelease' parameters or " + + "'${maven.compiler.target}' and '${maven.compiler.release}' properties are missing. " + "Trying to read bundled JDK signatures without compiler target. " + "You have to explicitly specify the version in the resource name."); } diff --git a/src/main/java/de/thetaphi/forbiddenapis/maven/TestCheckMojo.java b/src/main/java/de/thetaphi/forbiddenapis/maven/TestCheckMojo.java index 059e5de..04f0f4c 100644 --- a/src/main/java/de/thetaphi/forbiddenapis/maven/TestCheckMojo.java +++ b/src/main/java/de/thetaphi/forbiddenapis/maven/TestCheckMojo.java @@ -59,6 +59,16 @@ public final class TestCheckMojo extends AbstractCheckMojo { @Parameter(required = false, defaultValue = "${maven.compiler.testTarget}") private String testTargetVersion; + /** + * The default compiler release version used to expand references to bundled JDK signatures. + * This setting falls back to "targetVersion" if undefined. This can be used to override + * the release version solely used for tests. + * E.g., if you use "jdk-deprecated", it will expand to this version. + * This setting should be identical to the release version used in the compiler plugin. + */ + @Parameter(required = false, defaultValue = "${maven.compiler.testRelease}") + private String testReleaseVersion; + @Override protected List getClassPathElements() { return this.classpathElements; @@ -71,7 +81,8 @@ protected File getClassesDirectory() { @Override protected String getTargetVersion() { - return (testTargetVersion != null) ? testTargetVersion : super.getTargetVersion(); + return (testReleaseVersion != null) ? + testReleaseVersion : (testTargetVersion != null) ? testTargetVersion : super.getTargetVersion(); } } \ No newline at end of file