Skip to content

Target JVM version is incorrectly inferred #1501

@DreierF

Description

@DreierF

Expected and Results

#1199 introduced the missing "org.gradle.jvm.version" attribute for the module metadata of the shadowed artifacts. The version is however not resolved to the correct JVM version in all cases.

Related environment and versions

Shadow: 9.0.0-rc1

Reproduction steps

Consider the following example:

java {
	toolchain {
		languageVersion.set(JavaLanguageVersion.of(21))
	}
}

tasks.compileJava {
	options.release = 8
}

(See this blog post for why you'd want to do this)

This produces a jar compatible with Java 8, but when also applying the shadow plugin it claims it was compiled against Java 21.

Anything else?

The implementation currently only looks at targetCompatibility

val targetJvmVersion = provider {
javaPluginExtension.targetCompatibility.majorVersion.toInt()
}
// Track JavaPluginExtension to update targetJvmVersion when it changes.
attr.attributeProvider(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, targetJvmVersion)

The corresponding implementation in Gradle seems to take a few more cases into consideration:
https://github.com/gradle/gradle/blob/b06b7de4572c102a02ed831ae1f37e2da8255c35/platforms/jvm/plugins-java-base/src/main/java/org/gradle/api/plugins/jvm/internal/DefaultJvmLanguageUtilities.java#L64-L114

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions