Dependency on war output

(Ido Ran) #1

I have a multi-project in Gradle, one of them has both java-library and war plugins which means it produces both jar and war files.

Another project, the installer project, needs to package only the war file.

How can I reference only the war output?

(Ido Ran) #2

I’ve solved it but I’ll be glad to know if that’s the correct way.

In the war project I’ve added this code:

configurations {

artifacts {
    myWar war

In the installer project which consumes the war I’ve added this code:

dependencies {
    webappsRoot project(path: ':web', configuration: 'myWar')

task prepareInstallerSourceFiles(type: Copy) {
    into('webapps/root') {
        with copySpec {
            from configurations.webappsRoot.collect { zipTree(it) }

It looks very strange that the war configuration is not an artifact and that I have to manually expose it as artifact.

(Carlo Luib-Finetti) #3

Yeah, strange. ‘war’ is not a configuration at all, but a task. ‘compile’ or ‘testCompile’ is a built in configuration. And you are free to define arbitrarily configurations. I often use them to define dependencies for special build conditions, i.e. to have a war additional libraries in WEB-INF/lib for some reason.
I use ‘artifacts’ and ‘assemble’ like this:

artifacts {
    archives war

assemble.dependsOn war

I think you might say:

assemble.depends on war, jar. And inside jar{} and war{} you would use a configuration.

(Ido Ran) #4

Thank you, but how will I consume the archives from another project?

Is that the way?

dependencies {
    webappsRoot project(path: ':web', configuration: 'archives')

(Carlo Luib-Finetti) #5

maybe. There are always lot of different ways to do something in Gradle :slight_smile:

One way is like this

someTask(type:xyz) {

from project(’:de.uvdms.console.cusa’).jar.archivePath