Saturday, February 17, 2018

Artifact dependency in Gradle multiproject

Imagine that we have Gradle multiproject where one project (my-webapp) produces war artifact and another project (integration-test) needs to use that artifact. How to set dependency on war task output from sibling project?

In my-webapp/build.gradle


First create new configuration, that will be used for dependency resolution.

configurations {
    testWar
}

Then assign output of the war task to the testWar configuration.

artifacts {
    testWar war
}

In integration-test/build.gradle


Create configuration and set dependency on the sibling project configuration

configurations {
    testWar
}
dependencies {
    testWar project(path: ":my-webapp", configuration: "testWar")
}

Let depend the task where you need the war file on the testWar configuration and use the configuration files as you need.

task prepareWebapp(type: Copy) {
    dependsOn configurations.testWar
    configurations.testWar.files.each { artifact ->
        from artifact {
            into "${buildDir}/tomcat/webapps"
        }
    }
}

No comments:

Post a Comment