Wednesday, January 24

Migrating from Maven to Gradle - maven-assembly-plugin

When you have maven-assembly-plugin and you need to migrate it to Gradle you will probably use copy or zip tasks.

This is the Maven code we want to convert

This is the assemblyDescriptior.xml file



This is the resulting Gradle code


Let's break it down.
In my case all the assembly plugin did was to collect files from several directories and zip them all together.

I've used the ability to Gradle to run Groovy code and created a Zip task which copy files from each of the directories specified in the assemblyDescriptor.xml file.

The real work is done in line 23-24 where we take each folder and put it inside the zip file.

Finally in line 21-37 we provide the zip file as an artifact of this project so it can be consumed by other projects. This allow us to consume it as Gradle dependency in the following way:

dependencies {
    deploymentConf project(path: ':mqm-server-root:mqm-pom:mqm-deployment-conf', configuration: 'deploymentZip')
}

Notice the configuration part at the end.

No comments:

Post a Comment