Generate an artifact per subproject


(Alonso Dominguez) #1

Hi all, maybe I’m going in the wrong direction about what I’m trying to achieve but I got stuck on this and I’d like to hear some opinions or suggestions how to get it.

I have a custom plugin written in Groovy which builds my source code. The project I’m trying to build neither has Java or Groovy source files, it’s compound of several SCA (Service Component Architecture) subprojects developed with WebSphere Integration Developer. My goal with the custom plugin I’m working on is to have means to automate the build of those SCA modules with a Continuous Integration server.

The steps to perform the build of each of the modules are as follows: 1) Package the SCA module with all its SCA dependencies in a ZIP file at the continuous integration server 2) Send the ZIP file to the build server through SCP 3) Execute the build command remotely 4) Grab the resulting file (an EAR file) back to the continuous integration server (using SCP again) 5) Publish the EAR artifact into our centralized repository * We need (3) beacuse to build the EAR file you need the WebSphere scripts (and libraries, etc) and we don’t want to have it installed along out continuous integration server

Right, all those steps are done perfectly now but the last one (5). When the plugin it’s initialized it defines a custom task per subproject that performs the 4 first steps and defines the EAR file as one of its outputs, it adds all those tasks to a list and then tries to register a publish artifact in the “archives” configuration:

tasks.each { task ->
    project.configurations.getByName(
        Dependency.ARCHIVES_CONFIGURATION).artifacts.add(
        new SCAPublishArtifact(task))
}

The result we get is all the submodules produce its own EAR artifact but just the last module (the last in the previous iteration) gets published into our repository rather than all of them.

Notes: Our custom task doesn’t extend the “AbstractArchiveTask” since the actual important work is done remotely. The number of subprojects (SCA modules) may change in the future, their names are arbitrary and using filters would mean to define a single filter for each module whilst we would like to have something more dynamic.


(Peter Niederwieser) #2

Is this a single- or multi-project build? Are you trying to publish multiple artifacts from a single Gradle project? Do you publish to a Maven or Ivy repository?


(Alonso Dominguez) #3

This is a multi-project build, the root project is just a folder containing the ‘build.gradle’, ‘settings.gradle’, ‘gradle.properties’ files and the different submodules.

What I want is to publish each of the artifacts generated into Artifactory (a Maven repository), and it should be an EAR artifact per submodule. Root project should not generate any artifact, we are just interested in submodules.


(Peter Niederwieser) #4

One thing you should do then is to add a single artifact to each project’s ‘archives’ configuration. In your snippet above, you add them all to the same project’s ‘archives’ configuration.


(Alonso Dominguez) #5

Thanks, I got it. I thought that there was some sort of inheritance between subprojects the same way it is with Maven builds.

I changed a bit the plugin code and now I’m just applying the plugin to the subprojects instead of applying it to the root project.