In a multi-project project, how do I include all the code/jar from project A in the assembled jar for project B when project B depends on project A?


(Andrew Headrick) #1

In a multi-project project, how do I include all the code/jar from project A in the assembled jar for project B when project B depends on project A? Does that make sense?

Thanks, Andy


(Stig Kleppe-Jørgensen) #2

Why do you want to do this? And do you mean

  1. having all A’s classes merged into B’s jar file, or

  2. include A’s jar file inside B’s jar file

There is a Gradle plugin for 2. that includes all of B’s dependencies inside its jar file so you can just run it like this:

java -jar b.jar

You can find this plugin at the Github project gradle-executable-jar-plugin with a description on how to use it.


(Andrew Headrick) #3

Basically I have a strict java library and I have a groovy project that adds some groovyness to the java lib. I would prefer that when I package the groovy project it would just include all the java code.

Thanks, Andy


(Peter Niederwieser) #4

Here is one way:

B/build.gradle:

jar {

from { project(":A").compileJava }

from { project(":A").processResources }

}