shadow icon indicating copy to clipboard operation
shadow copied to clipboard

Support compile and runtime scopes for a library in the output pom

Open daviddawson opened this issue 8 years ago • 5 comments

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

daviddawson avatar Aug 29 '17 17:08 daviddawson

+1 👍

HappyEmu avatar Oct 16 '17 08:10 HappyEmu

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')
          }
        }
      }
    }
  }
}

grthr avatar Mar 16 '18 15:03 grthr

:+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.

mkobit avatar Oct 23 '18 22:10 mkobit

👍 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.

Evanjt1 avatar Apr 24 '19 17:04 Evanjt1

@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.

eli-darkly avatar Jan 06 '20 19:01 eli-darkly

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.

Goooler avatar Jul 31 '25 15:07 Goooler