Giter Club home page Giter Club logo

Comments (11)

juddgaddie avatar juddgaddie commented on August 22, 2024 16

+1 for this feature, migrating to Maven isn't really an option.

from shadow.

felixbarny avatar felixbarny commented on August 22, 2024 5

Any news on this? Are there other workarounds?
@johnrengelman what would be the approach for implementing support for this?

from shadow.

johnou avatar johnou commented on August 22, 2024 3

@johnrengelman how's this coming?

from shadow.

Petikoch avatar Petikoch commented on August 22, 2024 3

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.

johnrengelman avatar johnrengelman commented on August 22, 2024

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.

raphw avatar raphw commented on August 22, 2024

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.

johnrengelman avatar johnrengelman commented on August 22, 2024

I've never used it but: https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#createSourcesJar

from shadow.

raphw avatar raphw commented on August 22, 2024

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.

Danilo-Araujo-Silva avatar Danilo-Araujo-Silva commented on August 22, 2024

What is the gradle.kts version for this workaround?

from shadow.

Danilo-Araujo-Silva avatar Danilo-Araujo-Silva commented on August 22, 2024

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.

DasBabyPixel avatar DasBabyPixel commented on August 22, 2024

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)

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.