Skip to content

Migration of maven projects to gradle

Asterios Raptis edited this page Feb 4, 2020 · 15 revisions

Introduction

A good entry point for get started you can find on my medium.com post.

When you have CI like travis.com you have also commit the two files in the gradle directory which is in the main project directory:

/gradle/wrapper/gradle-wrapper.jar
/gradle/wrapper/gradle-wrapper.properties

add them to the git repository

git add -f gradle/wrapper/gradle-wrapper.jar
git add -f gradle/wrapper/gradle-wrapper.properties

and make gradlew file and gradle-wrapper.jar executable

chmod +x gradlew
chmod +x gradle/wrapper/gradle-wrapper.jar

Don't forget to add any Environment Variables at https://travis-ci.org/username/project/settings that can break your build

clean up maven files

Now you can delete the maven related files and of course eclipse launch scripts from maven. I have my launch scripts in the directory /src/launch

pom.xml
/target
/src/launch

After that is done you can push the feature branch and see if the travis builds successfully. If that's the case than you can merge you feature branch with develop branch.

Migrate license-maven-plugin

In maven we are using the great maven plugin: com.mycila:license-maven-plugin:3.0 To migrate this we can now use the gradle plugin: com.github.hierynomus.license:0.15.0

plugins {
...
    id "com.github.hierynomus.license" version "0.15.0"
}
...

license {
    ext.year="2015"
    ext.owner="Asterios Raptis"
    header rootProject.file('src/main/resources/LICENSE.txt')
    excludes(["**/README",
              "**/README.md",
              "**/LICENSE",
              "**/NOTICE",
              "**/*.xml",
              "**/*.xsl",
              "**/*.xsd",
              "**/*.dtd",
              "**/*.html",
              "**/*.jsp",
              "**/*.jpa",
              "**/*.sql",
              "**/*.properties",
              "**/*.bat",
              "**/*.gradle",
              "**/*.MF",
              "**/*.txt",
              "**/*.vm",
              "**/*.log",
              "**/*.map",
              "**/*.js.map",
              "**/*.tmpl",
              "**/*.js.tmpl",
              "**/*.editorconfig",
              "**/*.lombok.config",
              "src/test/resources/**",
              "src/main/resources/**",
              "out/**",
              "build/**"])
}

For check if the license header need an update execute the command:

gradle licenseFormatTest

For update the license header execute the command:

gradle licenseFormat

For more information go to the gradle plugin page

Migrate the Versions Maven Plugin

In maven we are using the great maven plugin: org.codehaus.mojo:versions-maven-plugin:2.7 To migrate this we can now use the gradle plugin: com.github.ben-manes:gradle-versions-plugin:0.27.0

plugins {
...
    id "com.github.ben-manes.versions" version "0.27.0"
}

For check if dependency versions needs an update execute the command:

gradle dependencyUpdates

For more information go to the gradle plugin page

Migrate from maven-deploy-plugin

In maven we are using the great maven plugin: maven-scm-publish-plugin That executes everything automatically.

In gradle we have to execute the following command:

gradle publish

To publish the project see the documentation of the user guide from Maven Publish Plugin from the gradle home page.

Note: with gradle we have also close and release in sonatype in two steps after the command above.

After this two steps is the release in the maven repository available.

Clone this wiki locally