Comments (11)
+1 for this feature, migrating to Maven isn't really an option.
from shadow.
Any news on this? Are there other workarounds?
@johnrengelman what would be the approach for implementing support for this?
from shadow.
@johnrengelman how's this coming?
from shadow.
Up to the current shadow version 4.0.4, this kind of "all-sources.jar" feature is still missing, afaik.
In one of my internal Gradle-MultiProject's I create and publish a single "...-all.jar" for my internal clients. To produce an accompanying "...-all-sources.jar" I collect all the sources from the dependent projects ("modules") with the following groovy snippet in my build.gradle file
...
task sourcesJar(type: Jar, dependsOn: classes) {
group = 'build'
classifier = 'sources'
from { collectSourceSetsIncludingSubmodules(project) } // we return here a closure to do this lazy, after all projects are configured by gradle
}
// workaround for missing gradle shadow plugin feature, see https://github.com/johnrengelman/shadow/issues/41
private Set<SourceDirectorySet> collectSourceSetsIncludingSubmodules(Project project){
Set<SourceDirectorySet> result = [].toSet()
recursiveCollectSourceSets(project, [].toSet(), result)
return result
}
private void recursiveCollectSourceSets(Project visitingProject,
Set<Project> visitedProjects,
Set<SourceDirectorySet> collectedSourceSets) {
if (!visitedProjects.contains(visitingProject)) {
visitedProjects.add(visitingProject)
collectedSourceSets.add(visitingProject.sourceSets.main.allSource)
visitingProject.configurations.implementation.getAllDependencies().withType(ProjectDependency).each { ProjectDependency pd ->
recursiveCollectSourceSets(pd.getDependencyProject(), visitedProjects, collectedSourceSets)
}
}
}
artifacts {
archives sourcesJar
}
shadowJar.dependsOn sourcesJar
shadowJar {
...
}
...
It's not perfect (I'm not a gradle expert), but works for me. Maybe this helps someone else looking for a solution.
(I'm using Gradle 4.10.x)
from shadow.
It's on the list of things to do. It's a native feature of Maven Shade, so I'd like to do it as well...Not sure when I'll have the time to do it though.
from shadow.
Thanks for your quick reply. Are you sure that this is possible using the Maven Shade plugin? I asked a question about this on the Gradle forum where the existence of such a tool was questioned. I also looked for documentations on this regarding Maven's shadowing plugin but I did not find any documentation on this. Could you provide a link or tell me where within the plugin this is implemented?
from shadow.
I've never used it but: https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#createSourcesJar
from shadow.
I just tried it and it works! Thanks so much for the link, I must have read to quickly through the descriptions because I did not see it when I came looking.
I really hope you are integrating the source code shifting feature one day. I just had to migrate my build from Gradle to Maven for this feature... Too bad. Thanks for considering to do it some day! I'll keep my Gradle build as a secondary option until this happens.
from shadow.
What is the gradle.kts
version for this workaround?
from shadow.
I tried the following with gradle.kts
but it didn't work for me =/, at least not yet:
val sourcesJar by tasks.creating(Jar::class) {
dependsOn("classes")
group = "build"
archiveClassifier.value("sources")
from(collectSourceSetsIncludingSubmodules(project))
}
fun collectSourceSetsIncludingSubmodules(project: Project): MutableSet<SourceDirectorySet> {
val result: MutableSet<SourceDirectorySet> = mutableSetOf()
recursiveCollectSourceSets(project, mutableSetOf(), result)
return result
}
fun recursiveCollectSourceSets(
visitingProject: Project,
visitedProjects: MutableSet<Project>,
collectedSourceSets: MutableSet<SourceDirectorySet>
) {
if (!visitedProjects.contains(visitingProject)) {
visitedProjects.add(visitingProject)
collectedSourceSets.add(visitingProject.sourceSets.getByName("main").allSource)
visitingProject.configurations.implementation.get().allDependencies.withType<ProjectDependency>().forEach {
pd: ProjectDependency ->
recursiveCollectSourceSets(pd.getDependencyProject(), visitedProjects, collectedSourceSets)
}
}
}
artifacts {
archives(sourcesJar)
}
from shadow.
A question because this was reopened:
Does this mean you are planning to work (or already working) on this issue?
If not, would you accept a PR?
I'd love to see the shadow plugin being able to create the correct source jar.
This would also make life a whole lot easier for publishing an artifact with shaded dependencies.
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.