Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
daviddawson opened this issue Aug 29, 2017 · 5 comments
Open

Comments

@daviddawson
Copy link

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

@HappyEmu
Copy link

+1 👍

@grthr
Copy link

grthr commented Mar 16, 2018

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

@mkobit
Copy link
Contributor

mkobit commented Oct 23, 2018

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

@johnrengelman johnrengelman added this to the 5.0.0 milestone Oct 27, 2018
@johnrengelman johnrengelman removed this from the 5.0.0 milestone Jan 20, 2019
@Evanjt1
Copy link

Evanjt1 commented Apr 24, 2019

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

@eli-darkly
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants