Support compile and runtime scopes for a library in the output pom
Currently shadow jar will put all non shaded dependencies into the runtime scope, even if they were originally, logically at least, in the "compile" scope
This is done here -> https://github.com/johnrengelman/shadow/blob/master/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy#L78
This causes problems in libraries that require their dependencies in the compile scope (ie, they use a transitive dependency class in their public api).
It would be good to be able have a shadowCompile option in the dependencies block that means the jar is put into the compile scope in the pom rather than runtime.
Shadow Version
2.0.1
+1 👍
As a workaround you could just replace the publishing configuration in build.gradle with:
publishing.publications {
shadow(MavenPublication) { publication ->
publication.artifact(project.tasks.shadowJar)
publication.pom { pom ->
pom.withXml { xml ->
def dependenciesNode = xml.asNode().appendNode('dependencies')
project.configurations.shadow.allDependencies.each {
if (! (it instanceof SelfResolvingDependency)) {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', 'compile')
}
}
}
}
}
}
:+1: to this - I'm using this plugin to relocate all of the runtime-style dependencies while keeping the api type dependencies in the POM as "compile" scope. I'm trying to get this to work well with the java-library plugin. It can be done, but it does take a bit of a hacky approach like above.
👍 as well, similar use case as @mkobit . Would be nice to have better support for java-library plugin in future. May add support for this when I have some free time.
@johnrengelman Could you comment on whether this is still an active issue that will be addressed in a future version, or is there a different solution for it now? We publish libraries using Shadow and our customers have complained about exactly this problem.
I noted the pom.withXml stuff in #1546.
From historical compatibility, I believe we can't change the behavior of configurations of shadow, implementation, and api. I commented on the related reason to https://github.com/GradleUp/shadow/issues/722#issuecomment-3135280851.