I have Gradle 7 project & java 16, there are two sub modules
- Root
- sub project A
- sub project B
My goal is following:
1) When project A is build it creates a A.jar file.
2) When project B is build it creates a B.jar file that contains an unexploded A.jar output from build of project A
To be more clear B.jar should look something like this
URI aJarUri = someClassInsideBjar.getClassLaoder().getResource("A.jar");
Subproject A build just fine, but i cannot figure out how to embed its output jar into B.jar
Please not that i do NOT want to add project A as dependency to project B. This is due to nature of project im working on. project B is a bootstrap for project A, but i do not want to bother you with details.
This solution has drawbacks, like it was mentioned - transitive dependencies are inside the jar. As well classes are not available for the compilation with this configuration
Your SO answer is actually pretty bad and also does not answer the question here.
The question here is, how to inlcude the jar as a whole, not the contents.
If the transitive libs are not wanted, one can simply declare the dependency or configuration as non-transitive.
On the compile classpath they are most probably not needed for the use-case here and if, then the dependency can simply declared on compileOnly or whereever needed.
Your SO answer also directly accesses the source set output of a different project which is very bad and unsafe and shouldn’t be done. If you need outputs of another project, you should use the proper cross-project publishing documented at Sharing outputs between projects.