Comments (15)
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.
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.
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.
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.
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.
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.
So, Is this possible?
from shadow.
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.
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.
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.
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?
- 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 exampleinclude('/*.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
followingartifactSet {
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.
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.
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.
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.
👍 for this FR. Is it possible in the current versions?
from shadow.
Related Issues (20)
- Plugin is incompatible with isolated projects feature HOT 2
- Future home/support for Shadow? HOT 20
- Gigantic jar when using Gradle 8.x HOT 4
- Unsupported class file major version 65 HOT 7
- Add a getter on ShadowCopyAction.ArchiveFileTreeElement to access the containing jar file name HOT 2
- How can i upgrade the jackson-databin jar version that included in the shade jar htrace-core4 HOT 2
- ShadowJar will report ZipException but not actually fail the build, creating invalid artifacts. HOT 1
- Relocating packages is also changing properties HOT 2
- Can't understand Expression 'shadowJar' HOT 1
- shadow plugin ignores jar files in resource folder
- Can't use the same module name as archive file name for the jar file HOT 2
- Create shadow jar after remapping HOT 1
- Exclude dependencies specified in libs-file?
- Gradle Warning: CopyProcessingSpec.setFileMode(Integer) method has been deprecated HOT 1
- Documentation says `destinationDir` which has been changed for `destinationDirectory` HOT 1
- NettyChannelBuilder can't locate the name resolver provider from service files when build with minimize shadowJar
- FileTreeElement.getMode()-deprecation notice HOT 2
- Redirect the old Maven coordinate to the new one HOT 2
- Old shadow versions are unreachable HOT 4
- Jar not being built when setting archiveClassifier to empty or null
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shadow.