-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDK version determined incorrectly by Gradle on JDK 10 #143
Comments
Possible fix:
|
This is not a bug. The version should anyways be defined in the project setup, checking against the current version is wrong anyways. |
https://docs.gradle.org/current/userguide/java_plugin.html#other_convention_properties Neither setting sourceCompatibility nor targetCompatibility is not recommended but allowed. Both sourceCompatibility and targetCompatibility are of type org.gradle.api.JavaVersion.
|
Actually this is a serious bug in Gradle. The forbiddenapis backend solely uses official version numbers, as accepted by javac. Javac does not accept "1.[9|10|11]" as version for the new |
For build reproducibility it is required to be set. Otherwise the project build depends on the actually used Java version and produces artifacts solely working with this Java version. This may also cause compile errors, as the source code parsing uses an undefined Java version. |
Sadly even setting source/target doesn't always help (for example, covariants on ByteBuffer.flip() can cause incompatibilities if compiled under java 9 with 1.8 as the target). |
I know but some people like pain 😳 |
@dweiss Of course you should set "release 8", which compiles against the Java 8 symbols. That's what I said before. Maven supports this, no idea about Gradle.
|
@sdavids I can add a fix there, but I would do it only for the 2 enum entries (Java 9 and Java 10). Starting with Java 11, Gradle behaves correct. So it would apply the setting as-is, but for Java 9 and Java 10 it would set it to "9" and "10" manually. |
My fix would be (just workaround the 2 bogus versions): // Define our tasks (one for each SourceSet):
project.sourceSets.all{ sourceSet ->
def getSourceSetClassesDirs = { sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : project.files(sourceSet.output.classesDir) }
project.tasks.create(sourceSet.getTaskName(FORBIDDEN_APIS_TASK_NAME, null), CheckForbiddenApis.class) { task ->
description = "Runs forbidden-apis checks on '${sourceSet.name}' classes.";
conventionMapping.with{
extensionProps.each{ key ->
map(key, { extension[key] });
}
classesDirs = { getSourceSetClassesDirs() }
classpath = { sourceSet.compileClasspath }
targetCompatibility = { EnumSet.of(JavaVersion.VERSION_1_9,JavaVersion.VERSION_1_10).contains(project.targetCompatibility) ? project.targetCompatibility.majorVersion : project.targetCompatibility?.toString() }
}
// add dependency to compile task after evaluation, if the classesDirs collection has overlaps with our SourceSet:
project.afterEvaluate{
def sourceSetDirs = getSourceSetClassesDirs().files;
if (classesDirs.any{ sourceSetDirs.contains(it) }) {
task.dependsOn(sourceSet.output);
}
}
forbiddenTask.dependsOn(task);
}
} |
Actually the fix is much easier: targetCompatibility = { project.targetCompatibility?.majorVersion } This works, because Forbiddenapis always accepts the pure Major version (6,7,8,9,10,...) (like Java does, too). I thinks that fix is easiest. |
The previous suggestion failed with older Gradle versions, as the enum constants were missing! Any other suggestions? |
I checked the old Gradle docs. Minimum Gradle version of forbiddenapis is 2.3. This one has (https://docs.gradle.org/2.3/javadoc/org/gradle/api/JavaVersion.html) the Major Version property, so we can use it. This is also tested on Jenkins. I changed the check now to use the major version for everything below Java 11. Starting from Java 11 (where gradle is correct), it uses toString(). The latter is done to be future-proof (if JDK decides to add minor versions again,...). |
I will commit this workaround and let Jenkins decide if it's fine with Gradle: targetCompatibility = { (project.targetCompatibility?.hasProperty('java11Compatible') && project.targetCompatibility?.java11Compatible) ?
project.targetCompatibility.toString() : project.targetCompatibility?.majorVersion } |
I will release a new version anyways for compatibility with Java 11, so this fix should be out soon. |
https://github.com/policeman-tools/forbidden-apis/wiki/BundledSignatures
"Gradle automatically add the compile Java version"
Error:
Parsing signatures failed: Invalid bundled signature reference (JDK version is invalid): jdk-internal-1.10
Workaround:
The text was updated successfully, but these errors were encountered: