Hi - I need to upgrade from `com.github.johnrengel...
# community-support
r
Hi - I need to upgrade from
com.github.johnrengelman.shadow:8.1.1
to
com.gradleup.shadow:9.2.2
, and it breaks some of my existing gradle config. Details in thread.
I used to have this in build.gradle.kts:
Copy code
publishing {

  publications {
    create<MavenPublication>("standaloneJar") {
      project.shadow.component(this)
    }
  }

  getComponents().withType<AdhocComponentWithVariants>().forEach { c ->
    c.withVariantsFromConfiguration(configurations.shadowRuntimeElements.get()) {
      skip()
    }
  }
}
However,
project.shadow.component(this)
no longer compiles and if I remove it the
getComponents().withType<AdhocComponentWithVariants>().forEach { c -> ... }
block fails at runtime when I do a
gradle shadowJar
. ChatGPT tells me I can simply replace as so:
Copy code
publishing {
  publications {
    create<MavenPublication>("standaloneJar") {
      from(components["shadow"])
    }
  }
}
and the
getComponents().withType<AdhocComponentWithVariants>().forEach { c -> }
stuff is not needed at all. However, it couldn't give me a reference for this, so I'm suspicious... Is it correct?
v
Maybe I misunderstand your code, but if not, why do you skip the shadowed jar publishing and reregister it as separate publication?
r
I don't really understand the intention of the original code.
ChatGPT reckons: This part:
Copy code
getComponents().withType<AdhocComponentWithVariants>().forEach { c ->
    c.withVariantsFromConfiguration(configurations.shadowRuntimeElements.get()) {
        skip()
    }
}
prevented Gradle from publishing duplicate runtime variants — otherwise, you’d end up with multiple variants for the same artifact (the plain JAR and the shadowed JAR).
v
Actually I don't really give much on any analysis any "AI" tool does nowadays as despite the "I" they are not intelligent but merely next-word guessers and cannot really understand things. For example it even contradicts itself, as it is neither duplicate variants nor the same artifact if they are differ artifacts, the plain and the shadowed. Besides that in isolation it might be halfway right, but above a separate publication is created that again publishes it, so ...
So without knowing what exactly you try to achieve, it is hard to recommend how to best achieve it. 🙂
Maybe the folks in #C07GJEMUZDH instantly know what breaking change they introduced though. 🙂
But from a very cursory look I guess you do not need to skip the variant manually, but can just set
project.shadow.addShadowVariantIntoJavaComponent = false
. At least from the naming I'd expect it to have the same effect as the lower part.
And the upper part is probably now
Copy code
val shadow by components.existing
from(shadow.get())
or
Copy code
from(components["shadow"])
Docs also suggest those two: https://gradleup.com/shadow/publishing/
r
It was added 2.5 years ago, not by me; the git commit says "Fixed build so that no -all artifact is included in the thin JAR publication" I'm probably best off seeing whether the correct artifacts get published to maven local, and if they do we're good.
v
Well, depends on what "correct" is. Iirc by default it publishes both jars as separate variants. So the original snippet probably suppressed the shadowed variant in the normal publication and created a separate publication to publish the shadowed one separately to some other maven repository.