Giter Club home page Giter Club logo

Comments (15)

aiqency avatar aiqency commented on August 22, 2024 10

Kotlin DSL version of @KhogaEslam solution:

tasks {
    build {
        dependsOn(shadowJar)
    }

    named<ShadowJar>("shadowJar") {
        configurations = listOf(project.configurations.shadow.get())
    }
}

dependencies {
    implementation("...") // excluded
    shadow("...") // included
}

Maybe it can save someone's time.

from shadow.

whimxiqal avatar whimxiqal commented on August 22, 2024 5

Kotlin DSL version of @KhogaEslam solution:

tasks {
    build {
        dependsOn(shadowJar)
    }

    named<ShadowJar>("shadowJar") {
        configurations = listOf(project.configurations.shadow.get())
    }
}

dependencies {
    implementation("...") // excluded
    shadow("...") // included
}

Maybe it can save someone's time.

I thought it was the other way around.

Dependencies added to the shadow configuration are not bundled into the output JAR.

https://imperceptiblethoughts.com/shadow/configuration/#configuring-the-runtime-classpath

I'm trying to do the same thing as OP: only include a single dependency into my project but I'm only finding hacky ways to do it. How do I just say exclude '*' but include 'my:dependency:version'

from shadow.

a-k-g avatar a-k-g commented on August 22, 2024 4

Just figured out the way to do this in the current versions. Say you have-

dependencies {
   compile 'jackson:some-module:1.0'
   compile 'guava:some-other-module:1.0'
}

and you only want the fat jar to include a shaded jackson and not guava, you could do-

shadowJar {
   dependencies {
      include(dependency('jackson:some-module:1.0'))
   }
   relocate "com.jackson", "shaded.com.jackson"
}

from shadow.

KhogaEslam avatar KhogaEslam commented on August 22, 2024 3
configurations {
    provided
    compile.extendsFrom provided
}

dependencies {
    provided 'WHATEVER' // Packages you don't need to add to jar
    provided 'Other WHATEVER' // Packages you don't need to add to jar

    shadow 'OTHER' // Packages you need to add to jar
    shadow 'Another OTHER' // Packages you need to add to jar
}

shadowJar {
    configurations = [project.configurations.shadow] // ***
}

as mentioned here

line *** is the way to tell shadow what dependencies to include in jar

from shadow.

johnrengelman avatar johnrengelman commented on August 22, 2024

I'm not certain I follow your description completely, but the exclude/include configuration leaves a lot to be wanted. It's on my list to improved for v0.9. I'm hoping to leverage some library or other open source project that has a good filtering implementation.

If you have an example project somewhere and a more concise description of what you want to be included/excluded, I could take a look.

from shadow.

tlaundal avatar tlaundal commented on August 22, 2024

A very short and consie formulation; How can I shade two specific dependencies, with different groupIds, into my jar?

A longer question(also by me): http://stackoverflow.com/questions/20937118/packaging-dependencies-in-jar

thanks for helping.

from shadow.

tlaundal avatar tlaundal commented on August 22, 2024

So, Is this possible?

from shadow.

johnrengelman avatar johnrengelman commented on August 22, 2024

So you're saying you want to exclude all your dependencies except for a specific one?
Sorry, but you're descriptions are still confusing. It sounds like you want some type of 'provided' scope (dependencies that are needed at compile time but are available on the target system).

I guess maybe the easiest way to do it without the above improvements to the filtering system would be to declare all the dependencies that you do NOT want in the final jar to be signedCompile or signedRuntime and the one you want to include as compile.

By default the plugin does not include dependencies in the signedCompiled and signedRuntime scopes in the shadow jar.

from shadow.

tlaundal avatar tlaundal commented on August 22, 2024

Well, yeah you are kind of correct. I have one dependency(with a dependency) that I need to shade, but not any other dependencies. The problem is that I cannot change the declarations of the other dependencies, So I thought the filtering might help me, but I couldn't get it to work like I wanted.

To sum up, exclude all dependencies except two. impossible to change declaration of the dependencies.

I hope you understand the issue a bit better now.

from shadow.

johnrengelman avatar johnrengelman commented on August 22, 2024

I was thinking more about this last night and I think the main issue here is that you have something like this:

myApp
  - foo:foo
    - a:a
  - bar:bar
    - b:b

Where myApp has 2 dependencies (foo and bar) and each one of those have a dependency (a and b respectively). If I'm understanding you correctly, you want to exclude bar (and by association b) and include foo (and by association a). So in the end your shadow jar would have the contents of myApp, foo, and a in it. Is that correct?

Unfortunately, there is no support in Shadow for automatically handling transitive dependencies. The entire dependency graph is evaluated before filtering is applied, so you'll need to include/exclude all the dependencies you want to control (it doesn't propagate filtering using the dependency graph). The issue here is that you may have multiple dependencies that depend on a common transitive dependency (i.e. bar also depends on a), so would include or exclude that dependency and so.

Also, please note that include and exclude are filters for jar contents, not jars themselves. Using them applies a global filter to all jars with the specified pattern. For example

include('**/*.properties')
exclue('**/MANIFEST.MF')

Would include all property files and exclude all MANIFEST files across ALL dependencies.

If you want to include/exclude entire dependencies, you want to use artifactSet (See https://github.com/johnrengelman/shadow/blob/master/it/artifact-includes-excludes/build.gradle for an example)
This configuration item allows you to specify patterns against the Maven Group/Artifact/Classifier/Type to include/exclude entire dependencies.

So, taking this back to the example up top. You could configure the following

artifactSet {
   exclude 'b'
   exclude 'bar'
}

This would exclude all artifacts under the Maven Group ID's of b and bar.

from shadow.

tlaundal avatar tlaundal commented on August 22, 2024

Thanks! That was exactly what I need. The only thing I wonder now is this:
In artifactSet, can I have exclude * and then just include my not
provided dependencies?

  1. jan. 2014 15:39 skrev "John Engelman" [email protected]
    følgende:

I was thinking more about this last night and I think the main issue here
is that you have something like this:

myApp

  • foo:foo
    • a:a
  • bar:bar
    • b:b

Where myApp has 2 dependencies (foo and bar) and each one of those have a
dependency (a and b respectively). If I'm understanding you correctly,
you want to exclude bar (and by association b) and include foo (and by
association a). So in the end your shadow jar would have the contents of
myApp, foo, and a in it. Is that correct?

Unfortunately, there is no support in Shadow for automatically handling
transitive dependencies. The entire dependency graph is evaluated before
filtering is applied, so you'll need to include/exclude all the
dependencies you want to control (it doesn't propagate filtering using the
dependency graph). The issue here is that you may have multiple
dependencies that depend on a common transitive dependency (i.e. bar also
depends on a), so would include or exclude that dependency and so.

Also, please note that include and exclude are filters for jar contents,
not jars themselves. Using them applies a global filter to all jars with
the specified pattern. For example

include('/*.properties')
exclue('
/MANIFEST.MF')

Would include all property files and exclude all MANIFEST files across ALL
dependencies.

If you want to include/exclude entire dependencies, you want to use
artifactSet (See
https://github.com/johnrengelman/shadow/blob/master/it/artifact-includes-excludes/build.gradlefor an example)
This configuration item allows you to specify patterns against the Maven
Group/Artifact/Classifier/Type to include/exclude entire dependencies.

So, taking this back to the example up top. You could configure the
following

artifactSet {
exclude 'b'
exclude 'bar'
}

This would exclude all artifacts under the Maven Group ID's of b and bar.


Reply to this email directly or view it on GitHubhttps://github.com//issues/31#issuecomment-32473844
.

from shadow.

johnrengelman avatar johnrengelman commented on August 22, 2024

You'd have to try...Like I said the include/exclude has a lot to be desired. I'm not sure how the stacking will play together. This will be improved in future versions.

from shadow.

tlaundal avatar tlaundal commented on August 22, 2024

OK, I'll try next week. Thanks for all help.
16. jan. 2014 17:46 skrev "John Engelman" [email protected]
følgende:

You'd have to try...Like I said the include/exclude has a lot to be
desired. I'm not sure how the stacking will play together. This will be
improved in future versions.


Reply to this email directly or view it on GitHubhttps://github.com//issues/31#issuecomment-32486836
.

from shadow.

tlaundal avatar tlaundal commented on August 22, 2024

ArtifactSet seem to be what I looked for, but there is still one flaw.
Here is what I want to be able to do:

shadow {
    artifactAttached = false
    artifactSet {
          exclude '*'
          include 'de.cubeisland.engine:configuration'
          include 'org.yaml:snakeyaml'
    }
}

But that doesn't work. I have to manually exclude all the dependencies I don't want.

So; Feature request: Ability to exclude '*' and then include dependencies with artifactSet

from shadow.

a-k-g avatar a-k-g commented on August 22, 2024

👍 for this FR. Is it possible in the current versions?

from shadow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.