I have a multi-project gradle build, using kotlin as build script language.
I can build a "fat" jar containing all project dependencies (.class files) I am not sure how it works. But it goes through all dependencies and exclude duplicate packages.
tasks.jar {
//manifest.attributes["Main-Class"] = "com.example.MyMainClass"
val dependencies = configurations
.runtimeClasspath
.get()
.map(::zipTree) // OR .map { zipTree(it) }
from(dependencies)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
Is there some equivalent way to create a sources jar. Including the source code of all dependencies?
Side question: Can you declare sources like dependencies?
dependencies {
implementation(project(":common"))
implementation(files("../libs/somejar1.jar"))
implementation(files("../libs/somejar2.jar"))
}
sources {
?
}
Edit
I have written a library. The library has code I have written (multiple modules). The modules have dependencies. (Could be other modules within the project, and/or other libraries) I have the other libraries' as jar files stored locally together with the source code of those libraries.
I am able to pack all the code I have written together with my codes dependencies into a single fat jar.
It would be nice to also be able to pack all source files (including the source files of the dependencies) into a "fat sources jar".
That way, when I want to use my library in other projects. I can have 2 jars. One with all the .class files and one sources jar with all the .java files.