Can Gradle jar multiple projects into one jar ?
I know you can do it for a single project using a method like this:
task packageTests(type: Jar) {
from sourceSets.test.classes
}
But how does a person zip up multiple sub-projects into one jar?
I tried this and it doesn't work:
task packageTests(type: Jar) {
from project(':core').sourceSets.main.classes
from project(':core:google').sourceSets.test.classes
from project(':core:bing').sourceSets.test.classes
}
A multi-project build in Gradle consists of one root project, and one or more subprojects. A basic multi-project build contains a root project and a single subproject. This is a structure of a multi-project build that contains a single subproject called app : Example 1. Basic multi-project build.
Create a Multi-Project. Let's create a project containing its subprojects and build the Gradle project. Co'sider the below project structure in which the root project name is Multi_project, and the subproject name is sub_project. Create a new root directory in which we want to create a multi-project.
Here's my solution, which is a little bit simpler:
// Create a list of subprojects that you wish to include in the jar.
def mainProjects = [':apps',':core',':gui',':io']
task oneJar( type: Jar , dependsOn: mainProjects.collect{ it+":compileJava"}) {
baseName = 'name of jar'
from files(mainProjects.collect{ project(it).sourceSets.main.output })
}
Code has been tested on Gradle 1.12
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With