Search code examples
gradlerpmmulti-project

Collect build artifacts from subprojects into RPM with Gradle


I have the following project structure:

Root
+---Sub1
|
+---Sub2

Sub1 project produces JAR, Sub2 creates WAR. Root project goal is to produce RPM that contains both the Sub1 and Sub2 output.

I'm trying to use ospackage Gradle plugin to build RPM. Here is part of root build.gradle:

ospackage {
    from subprojects.collect { it.tasks.withType(Zip) } into 'lib'
}

It works but for Sub2 both JAR and WAR are created, which is undesirable.

What configuration should be applied in order to collect appropriate jars and wars into RPM?

UPDATE

I'm searching for some generic solution, i.e. iteration over subprojects is preferable to specifying behaviour for each subproject.


Solution

  • The solution is to add WAR plugin in Sub2 project's build.gradle:

    apply plugin: 'war'
    

    make buildRpm task dependent on all subprojects build tasks in the root build file:

    buildRpm.dependsOn getTasksByName('build', true)
    

    and finally configure ospackage plugin to collect the artifacts into the target RPM:

    ospackage {
        from(subprojects.collect { "${it.buildDir}/libs" }) {
            into 'bin'
        }
    }