shadow
shadow copied to clipboard
Publish task fails because generated pom is invalid with duplicated tag dependencies
Shadow Version 6.1.0
Gradle Version 6.8+
Expected Behavior
When attempting to publish a specific submodule of a multi-module project, a valid pom file should be generated in the generatePomFileFor...Publication
task and the publish task should not fail.
Actual Behavior
Caveat 1: this is a Kotlin + gRPC multi-module project. Caveat 2: I am publishing one of two submodules. The other one works fine (no shadowing). Caveat 3: when removing the shadow plugin, the pom is generated correctly.
The generated pom file has two dependencies
tags which causes the next task (generatePomFileFor...Publication
) to fail.
If I remove all references to the shadow plugin and its configuration. The pom generation task produces the correct output.
Gradle Build Script(s)
plugins {
kotlin("jvm") // version is managed in the rootProject
`maven-publish`
id("net.linguica.maven-settings") version "0.5"
id("com.github.johnrengelman.shadow") version "6.1.0"
}
val customArtifactId = "..."
group = "..."
version = "..."
val mainClass = "..."
publishing {
publications {
create<MavenPublication>("...") {
artifactId = customArtifactId
from(components["java"])
withoutBuildIdentifier()
project.shadow.component(this)
}
}
repositories {
maven {
val releases = "..."
val snapshots = "..."
url = uri("...")
name = "..."
}
}
}
dependencies {
implementation(project(":stub"))
implementation(kotlin("stdlib"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.4.20")
implementation("info.picocli:picocli:4.5.2")
implementation("com.mchange:c3p0:0.9.5.2")
implementation("org.slf4j:slf4j-api:1.7.25")
implementation("org.jdbi:jdbi3-kotlin-sqlobject:3.16.0")
runtimeOnly("mysql:mysql-connector-java:8.0.20")
runtimeOnly("ch.qos.logback:logback-classic:1.2.3")
runtimeOnly("io.grpc:grpc-netty:1.35.0")
testImplementation("org.junit.jupiter:junit-jupiter:5.7.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testImplementation(kotlin("test-junit5"))
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine", "5.5.2")
testRuntimeOnly("ch.qos.logback:logback-classic:1.2.3")
}
tasks {
test {
useJUnitPlatform()
}
jar {
manifest {
attributes(
Pair("Main-Class", mainClass)
)
}
}
shadowJar {
archiveBaseName.set(customArtifactId)
archiveVersion.set(project.version as String)
archiveFileName.set("${archiveBaseName.get()}-${archiveVersion.get()}.${archiveExtension.get()}")
}
}
tasks.withType<GenerateModuleMetadata> {
enabled = false
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "11"
}
}
The rootProject
build script
plugins {
id("com.google.protobuf") version "0.8.13" apply false
kotlin("jvm") version "1.4.20" apply false
}
ext["grpcVersion"] = "1.35.0"
ext["grpcKotlinVersion"] = "1.0.0"
ext["protobufVersion"] = "3.13.0"
ext["kotlinVersion"] = "1.4.20"
allprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
}
apply(plugin = "idea")
}
Content of Shadow JAR (jar tf <jar file>
- post link to GIST if too long)
The only thing missing inside the jar is the generated pom file. Everything else is there.
UPDATE
This did not actually work
I have found out that when I launch the process from outside the IDE (IntelliJ), it works as expected.
If you somehow end up where I am, try launching the task from the terminal.
Output (warnings were redacted):
$ ./gradlew :server:clean :server:publish --console=plain
> Task :server:clean
> Task :stub:extractIncludeProto
> Task :protos:compileJava NO-SOURCE
> Task :protos:processResources
> Task :protos:classes
> Task :protos:jar
> Task :stub:extractProto
> Task :stub:generateProto
> Task :stub:compileKotlin
> Task :stub:compileJava
> Task :stub:processResources
> Task :stub:classes
> Task :stub:inspectClassesForKotlinIC
> Task :stub:jar
> Task :server:compileKotlin
> Task :server:compileJava NO-SOURCE
> Task :server:processResources NO-SOURCE
> Task :server:classes UP-TO-DATE
> Task :server:inspectClassesForKotlinIC
> Task :server:jar
> Task :server:generateMetadataFileFor...Publication SKIPPED
> Task :server:generatePomFileFor...Publication
> Task :server:publish...PublicationTo...Repository
> Task :server:publish
BUILD SUCCESSFUL in 40s
16 actionable tasks: 16 executed
I am an idiot. The actual build does fail
$ ./gradlew :server:clean :server:publish --console=plain
> Task :server:clean
> Task :stub:extractIncludeProto UP-TO-DATE
> Task :protos:compileJava NO-SOURCE
> Task :protos:processResources UP-TO-DATE
> Task :protos:classes UP-TO-DATE
> Task :protos:jar UP-TO-DATE
> Task :stub:extractProto UP-TO-DATE
> Task :stub:generateProto UP-TO-DATE
> Task :stub:compileKotlin UP-TO-DATE
> Task :stub:compileJava UP-TO-DATE
> Task :stub:processResources UP-TO-DATE
> Task :stub:classes UP-TO-DATE
> Task :stub:inspectClassesForKotlinIC UP-TO-DATE
> Task :stub:jar UP-TO-DATE
> Task :server:compileKotlin
> Task :server:compileJava NO-SOURCE
> Task :server:processResources NO-SOURCE
> Task :server:classes UP-TO-DATE
> Task :server:inspectClassesForKotlinIC
> Task :server:jar
> Task :server:shadowJar
> Task :server:generateMetadataFileFor...Publication SKIPPED
> Task :server:generatePomFileFor...Publication
> Task :server:publish...PublicationTo...Repository FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':server:publish...PublicationTo...Repository'.
> Failed to publish publication '...' to repository '...'
> Invalid publication '...': POM file is invalid. Check any modifications you have made to the POM file.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
17 actionable tasks: 7 executed, 10 up-to-date
Upon inspection, the pom contains the duplicate tag
<dependencies>
...
</dependencies>
<dependencies/>
Hey I'm getting this issue too, did you ever figure anything out?
Seeing this as well on a multi-platform project.
kotlin {
jvm()
jvm("shaded") {
attributes {
attribute<org.gradle.api.attributes.Bundling>(
Bundling.BUNDLING_ATTRIBUTE,
objects.named(Bundling.SHADOWED)
)
}
}
...
}
publishing {
publications {
getByName<MavenPublication>("shaded") {
project.extensions.configure<com.github.jengelman.gradle.plugins.shadow.ShadowExtension>{
component(this@getByName)
}
}
}
}
I ran across the duplicated tag issue in v7.1.2. Seems to be fixed in https://github.com/johnrengelman/shadow/pull/769, which is included in 8.0.0 and later. Once I upgraded, I no longer faced that issue when publishing.