I'm trying to make a dist of a multi project build. The root project looks something like this:
apply plugin: 'distribution'
version 1.0
distributions {
main {
baseName = 'someName'
contents {
from 'nodes'
into 'nodes'
}
}
}
It just copies a folder with some files to the dist.
I now want each subproject to inject its stuff into the dist. I want to add each subprojects jar, any dependecies, and possibly some other files etc...
I have no idea how to inject from the subproject to the root. Should I even do something like that? What i mean is something like this:
subprojects {
apply java...
...
// pseudocode
jack into the root project dist plugin
put my produced jars and dependencies in a folder with my name
...
}
Does anyone have any examples, or just point me in the right direction?
thanks!
I was looking for the same thing. With some peeking at the API docs and Gradle' own build files, I came to the following:
The contents {} closure is a CopySpec, knowing that makes using the distribution plugin way simpler :)
Check out Gradle' own subprojects/distributions/distributions.gradle file for some great examples of using the CopySpec.
This works.
Sadly, currently I've no clue on how to scale this to more than two projects in a clean way. Atleast we're one step closer :)
This is the setup I'm using in a project with multiple libraries to create a "release" archive:
Using
distZip
task creates an archive with all libraries with their files separated into three folders (lib
contains the actual jars,src
contains jars with sources anddoc
contains - you guessed it - Javadoc jars).I actually made it work by combining the approaches from both, pvdissel and sparc_spread.
In my root project I created a directory
src/main/dist
where I put exactly one file called.gitkeep
.The
build.gradle
file of my root project looks as follows:Works quite well for me. Tested with Gradle 2.0.
I found a solution that has been working well for me. The key is that you add a separate subproject for creating the dist. This subproject is sibling to the other subprojects. That is, do not try to script the distribution in your top-level
build.gradle
file.Let's call the new subproject
dist
. The first thing to do is to add it to your top-levelsettings.gradle
file in your multi-project root:Your
dist
project must at minimum include:build.gradle
- to be detailed belowsrc/main/dist/at_least_one_dummy_file.txt
- the distribution plugin always requires asrc/main/$distribution.name
directory. Having a non-empty one with adistribution.name
ofmain
tricks the plugin into following all the transitive dependencies of all themain
sourcesets of all the sibling projects.Next, the
build.gradle
file for thedist
project:Then run
gradle distZip
. TheZIP
file indist/build/distributions
will have alib
subdirectory with every singleJAR
you want: the sibling projectJAR
s and their transitive dependencies.Because of the trickery we used, the distribution plugin will make an empty
JAR
calleddist-${version}.jar
. For cosmetic reasons, I remove it with theexclude
call above, but it is harmless. You could also use a secondexclude
call to remove theat_least_one_dummy_file.txt
if there really is no content undersrc/main/dist
that you want to include. If you do not want add any artifacts and/or remove the ones mentioned here, then you don't even need acontents
section at all.I also have found ways of selectively including different artifacts based on whether this is a "dev" or "prod" distribution, a la Maven profiles. If you want me to add that, please post in comments and I will.