Skip to content
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

Java compatibility forced to match Gradle minimum Java compatability #95

Closed
MarkRx opened this issue Sep 8, 2023 · 6 comments
Closed

Comments

@MarkRx
Copy link

MarkRx commented Sep 8, 2023

When specifying a minimum Gradle version the plugin forces the java compatibility to match the Gradle minimum compatibility version here. This prevents plugins from building with a newer JDK because dependencies will fail to get pulled when running with newer versions of Gradle due to variant JDK version missmatches.

- Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 8

Users should be able to set compatibility to a version higher than the minimum Gradle java version.

@MarkRx
Copy link
Author

MarkRx commented Sep 8, 2023

It looks like this might have been fixed on the main branch. There does not appear to be a release yet with these changes though.

@lacasseio
Copy link
Member

The new and old codes accounted for this by only forcing JVM compatibility if the user didn't specify anything. I checked, and it does work. However... I see the issue. Gradle automatically set the source compatibility when setting the target compatibility, which is what was left out. Could you confirm that you only set the target compatibility?

@MarkRx
Copy link
Author

MarkRx commented Sep 13, 2023

It is actually still broken on master.

I'm using a java toolchain instead of source/target compatibility

        java {
            toolchain {
                languageVersion = JavaLanguageVersion.of(17)
            }
        }

The problem is that the plugin is setting the source compatibility value to 1.1 in InjectJvmCompatibilityPropertyIntoJavaExtensionRule.onExtension(JavaPluginExtension). That value ends up taking precedence over the toolchain version in DefaultJavaPluginExtension.getSourceCompatibility() meaning the toolchain version is never checked. As a result the logic to set the jvm compatibility version to the minimum version supported by the target version of gradle is called.

@lacasseio
Copy link
Member

Version 1.6.13 should fix the issue. Please reopen if the problem is still present.

@TheMrMilchmann
Copy link

The fix in 1.6.13 actually broke the compilation in my case. Here is what I typically do:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(22)
    }
}

withType<JavaCompile>().configureEach {
    options.release = 8
}

This configuration uses the latest toolchain to compile for a specific Java version. However, as of the changes in 1.6.13, this is no longer supported. The culprit seems to be that the compatibility versions are set to the toolchain versions regardless of whether options.release is specified and then take precedence.

For example, this issue surfaces when writing a plugin in Kotlin:

kotlin {
    compilerOptions {
        jvmTarget = JvmTarget.JVM_1_8
    }
}

Running a build then fails even if options.release is set with:

Inconsistent JVM-target compatibility detected for tasks 'compileJava' (22) and 'compileKotlin' (1.8).

@TheMrMilchmann
Copy link

Opened #113 for visibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants