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

shadowJar task with minimize() doesn't use gradle toolchain. #1034

Open
VasilisManol opened this issue Nov 20, 2024 · 5 comments
Open

shadowJar task with minimize() doesn't use gradle toolchain. #1034

VasilisManol opened this issue Nov 20, 2024 · 5 comments
Labels

Comments

@VasilisManol
Copy link

Expected and Results

call shadowJar task with minimize() without errors.

Related environent and versions

Gradle 8.6
shadow 8.3.5

Installed JDKs
openjdk 8 - default
openjdk 21

Reproduction steps

  • Use jdk 8 as default
  • Install jdk 21
  • Create a gradle project with build.gradle.kts:
plugins {
    id("java")
    id("com.gradleup.shadow") version ("8.3.5")
}

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

configure<JavaPluginExtension> {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_21
}

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
....
}

tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
    exclude("META-INF", "META-INF/**")
    minimize()
    archiveClassifier.set("")
    isZip64 = true
}

tasks {
    build {
        dependsOn(shadowJar)
    }
}
  • Build e.g. ./gradlew build
    Then the following error occurs:
  Execution failed for task ':shadowJar'.
> org/vafer/jdependency/Clazzpath has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

If minimize() is commented out it builds as expected.

Anything else?

This error looks related with #814 but maybe not exactly the same. When switching to jdk21 as default jdk, minimize() doesn't give any error.

@Goooler
Copy link
Member

Goooler commented Jan 11, 2025

@VasilisManol This looks unrelated to Shadow, can you try out deleting

configure<JavaPluginExtension> {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_21
}

@VasilisManol
Copy link
Author

@Goooler I get the same even when I comment out that part. Even in that case, it builds without errors, if I just comment out the minimize(). Can you explain why you think it is unrelated to Shadow? For me, the fact that it fails only if I call minimize() but it works otherwise, points to Shadow and actually the implementation of the minimize() feature.

@Goooler
Copy link
Member

Goooler commented Jan 11, 2025

It's related to sourceCompatibility = JavaVersion.VERSION_1_8, org/vafer/jdependency/Clazzpath requires Java 11 to run, which minimize depends on, but you pinned Java 8 here cause it failed.

@VasilisManol
Copy link
Author

VasilisManol commented Jan 11, 2025

I see your point but then it should work with your suggestion. I think the issue is that Shadow doesn't use the toolchain defined in

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

As I wrote my default java on the system is java 8 and this is what Shadow uses. If I set default java to 21 then it works.

@Goooler
Copy link
Member

Goooler commented Jan 11, 2025

ShadowJar extends org.gradle.jvm.tasks.Jar, I don't see how to configure and use toolchain in that, need more time to investigate...

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

No branches or pull requests

2 participants