Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migration from Maven 2/3 to Gradle

I have been looking into Gradle and looks pretty interesting. I think being able to write your scripts in any other language than XML is pretty cool, and it is not clear to me whether polyglot Maven POM files are still a feasible option.

I am working on a project that uses Maven 2.2.1 as build tool. This project:

  • is multi-module
  • uses (also our own) plugins
  • relies on an Artifactory proxy repository

Are there any experiences out there on migrations from Maven to Gradle? Gotchas, pain points, corner cases? Any sort of experience is very welcome.

like image 854
Gonzalo Garcia Lasurtegui Avatar asked Oct 10 '11 22:10

Gonzalo Garcia Lasurtegui


People also ask

How do I migrate to Gradle?

Import a Gradle-based IntelliJ project If you are already using Gradle with your IntelliJ project, you can open it in Android Studio using the following steps: Click File > New > Import Project. Select your IntelliJ project directory, and click OK. Your project will open in Android Studio.

Can you mix Maven and Gradle?

Short answer: yes. There's no conflict between having two independent build scripts for the same project, one in Maven and one in Gradle.

Can I use Gradle instead of Maven?

In the end, what you choose will depend primarily on what you need. Gradle is more powerful. However, there are times that you really do not need most of the features and functionalities it offers. Maven might be best for small projects, while Gradle is best for bigger projects.


4 Answers

The migration from Maven to Gradle isn't as easy as from Ant to Maven (at the least at the moment). You can easily reuse Ant scripts and make them first class citizens in your Gradle build. There's a task on the Gradle roadmap for deep import of Maven builds as well.

So far I migrated two enterprise Maven builds to Gradle. Both of them were multi-module projects using standard Maven plugins. I basically rewrote the builds the Gradle way which requires at least some knowledge about Gradle. Based on my experience you can easily get the same build running in Gradle as well. Gradle doesn't really box you in here and is fairly flexible. Along the way you might find yourself having to write a custom plugin that doesn't exist yet depending on what Maven plugins you are using. However, there's already a wide breath of plugins out there. So far I haven't run into a real roadblock yet. Even though the Gradle documentation is pretty good you might find yourself reading a lot of Gradle forum posts to find the solution to one of your problems. Some of the standard Maven features are not supported out-of-the-box e.g. a provided scope or WAR inplace. However, there're easy ways around it. I haven't used Artifactory repositories. The ones I dealt with were Nexus repositories. As far as I know the Gradle guys have good support for Artifactory though. Edit: JFrog provides a Artifactory Gradle plugin.

A good way to start is to use the migration tool Maven2Gradle which let's you generate a Gradle script from your Maven build. Personally, I didn't use it yet. I developed the Gradle build side-by-side with the Maven build which didn't cause any trouble. Maven put its output under target, Gradle under build. Make sure you prepare your team for the change. Let them try out the Gradle build and get familiar with the tool.

Once you are fully migrated you'll be very happy about the maintainability and extensibility of your build. It's very easy to add custom build logic and you're going to be grateful that you left XML-land. In terms of performance you are not going to make a step back as well. The incremental build feature does its job very well.

like image 79
Benjamin Muschko Avatar answered Sep 25 '22 11:09

Benjamin Muschko


You may also want to read through this write-up of my experience porting a maven project to gradle.

like image 43
Raghuram Avatar answered Sep 27 '22 11:09

Raghuram


You can always change the buildDir to be 'target' under gradle if you want the build output to go under 'target' instead of 'build' like maven:

buildDir = 'target'
like image 43
Arun Gopalpuri Avatar answered Sep 25 '22 11:09

Arun Gopalpuri


maven2Gradle seems to have been replaced with being able to run gradle init from the command line (though it's a rather experimental feature). It seems to work ok for doing some basic Gradle setup from a Maven project.

like image 25
Jon Onstott Avatar answered Sep 24 '22 11:09

Jon Onstott