GradleUp / shadow

Gradle plugin to create fat/uber JARs, apply file transforms, and relocate packages for applications and libraries. Gradle version of Maven's Shade plugin.
https://www.gradleup.com/shadow/
Apache License 2.0
3.73k stars 393 forks source link

Plugin incompatible with Gradle 6.4 #572

Open mpe85 opened 4 years ago

mpe85 commented 4 years ago

The plugin seems to be incompatible with Gradle 6.4. With previous version of Gradle (6.3 or lower) everything is fine.

Shadow Version

5.2.0

Gradle Version

6.4

Expected Behavior

runShadow task should not fail

Actual Behavior

Exception is raised:

java.lang.IllegalStateException: The value for task ':runShadow' property 'mainClass' is final and canno
t be changed any further.
        at org.gradle.api.internal.provider.AbstractProperty$FinalizedValue.beforeMutate(AbstractProperty.java:484)
        at org.gradle.api.internal.provider.AbstractProperty.assertCanMutate(AbstractProperty.java:264)
        at org.gradle.api.internal.provider.AbstractProperty.setSupplier(AbstractProperty.java:213)
        at org.gradle.api.internal.provider.DefaultProperty.set(DefaultProperty.java:69)
        at org.gradle.api.tasks.JavaExec.setMain(JavaExec.java:405)
        at com.github.jengelman.gradle.plugins.shadow.internal.JavaJarExec_Decorated.setMain(Unknown Source)
        at org.gradle.api.tasks.JavaExec$setMain.callCurrent(Unknown Source)
        at com.github.jengelman.gradle.plugins.shadow.internal.JavaJarExec.exec(JavaJarExec.groovy:16)

Gradle Build Script(s)

plugins {
  ...
  id("com.github.johnrengelman.shadow") version "5.2.0"
  ...
}
application {
  mainClassName = "a.b.c.MainKt"
  ...
}

Content of Shadow JAR (jar tf <jar file> - post link to GIST if too long)

softjake commented 4 years ago

Same problem as well. Tried with all plugin 5.0+ versions. Works well with Gradle 6.3 but breaks with 6.4 with the "'mainClass' is final and cannot be changed any further." error.

build.gradle.kts excerpt»:

application { mainClassName = "io.vertx.core.Launcher" } val mainVerticleName = "com.softjake.hpdg.spk01.MainVerticle" val vertxVersion = "3.8.4" ... java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } ...

robertnosko commented 4 years ago

@softjake, @mpe85

I have the following config: `application { version = appVersion mainClassName = appManifestAttributesMainClass // https://github.com/netty/netty/issues/9677 applicationDefaultJvmArgs = listOf("--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED") }

java { sourceCompatibility = JavaVersion.VERSION_13 targetCompatibility = JavaVersion.VERSION_13 } ... tasks.named("shadowJar") { archiveClassifier.set("all") mergeServiceFiles() configurations = listOf(project.configurations.compile.get(),project.configurations.runtimeClasspath.get() ) manifest { attributes["Implementation-Title"] = appManifestAttributesTitle attributes["Implementation-Version"] = appVersion attributes["Main-Class"] = appManifestAttributesMainClass attributes["Main-Verticle"] = appManifestAttributesMainVerticle } }` and it's working with gradle 6.3, 6.4, 6.4.1, 6.5-rc-1

SchweinchenFuntik commented 4 years ago

@robertnosko code formatting

liach commented 4 years ago

The problem may be that in gradle 6.4 application plugin now moves mainClassName getter and setter to a mainClass attribute.

TobseF commented 3 years ago

Setting the deprecated mainClassName won't work on Gradle 7.0, because there its not present anymore. In Kotlin Gradle DSL buidl script for Gradle 7.0 would look like:

application() {
    mainClass.set("de.tfr.MainKt")
}

But then it's necessary like mentioned before to manually set the manifest attributes. This blows up the build file and is a pity, because the whole manifest can be skipped, if the new mainClass would be supported like the old mainClassName.

I opened a separate ticket for that:
https://github.com/johnrengelman/shadow/issues/663