Friday, 5 February 2016

Moving from Maven to Gradle in under 5 minutes

  • How to move a project from Maven to Gradle
For mainly historic reasons I've been a heavy Maven users for all my projects and not really dipped more than a toe into the 'holy grail' that is Gradle.

So I was pleased to be set the challenge by one of my clients, that as part of the delivery they wanted the code moved from Maven to Gradle.

After a bit of research (as well as some trial and error) I can take you through the steps that should be able to convert a Maven project to Gradle in about 5 minutes. (Note I've used IntelliJ but I would imagine this should be pretty much the same on any other IDE - or even if you're not using an IDE). 

  1. Install Gradle on your machine.  You can get the software from here.
  2. Check out (or copy) your code into a new directory.  This is not strictly necessary but it makes things cleaner.
  3. cd into the directory that contains your pom.xml
  4. Run the command: run gradle init.  This will create a new gradle project creating a build.gradle file based on your pom.xml.  (Note this is an incubator feature but it seems to work quite well).
  5. Create a new IntelliJ project as follows:  File -> New -> Project From Existing Sources. Select the build.gradle file you created in the previous step and choose the following defaults as in this dialog:

    That's really all there is to it. A brand new Gradle project.

    Here are some additional notes I found useful as a Gradle newbie:
    1. If you want to include files you already have in your existing Maven .m2 repo add mavenLocal() as a dependency.
    2. Your dependencies get downloaded here (the equivalent of .m2): 
    3. This is the correct way to define jdk compatibility:def javaVersion = JavaVersion.VERSION_1_8;sourceCompatibility = javaVersion;targetCompatibility = javaVersion;
    4. To see the results of your tests as they are running add this method to your build.gradletest { testLogging {     events "started", "passed", "skipped", "failed", "standardOut", "standardError" }}
    5. If you have repositories that need authentication see here.


    1. Many thanks for sharing this Rational Java article with us here. I find it so constructive and educative at the same time. It has solved the problems that i had before bumping here.

    2. How many people could be the total in number as the participants?I will surely attend there for the betterment of the conference.write my essay

    3. Thanks for the article. It is exactly what i needed

    4. I am running the command mentioned above but nothing happens Run the command: run gradle init. This will create a new gradle project creating a build.gradle file based on your pom.xml. (Note this is an incubator feature but it seems to work quite well).

      1. I tried later again it worked. Thanks for posting such an easy way to migrating the project to gradle!!!!!.

    5. You have brought up a very wonderful points , regards for the post.
      brother printer support


    6. very nice collection of blog post you have posted here thank you very much for posting such blog post.

      Party Hall Booking || Banquet Halls in Delhi || Party Halls in West Delhi

    7. (pubg) is better than anyone might have expected with refreshed tourist spots, trains, and a slight change in season.

    8. I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. Cyberpunk Yellow Jacket

    9. Great information about wilderness for beginners giving the opportunity for new people.
      Future Trunks Jacket

    10. Our the purpose is to share the reviews about the latest Jackets,Coats and Vests also share the related Movies,Gaming, Casual,Faux Leather and Leather materials available Raiders Silver Jacket

    11. wow information are greatful. Thanks for sharing this Rational Java article with us here. Kinemaster Lite

    12. Hi , Thank you so much for writing such an informational blog. If you are Searching for latest Jackets, Coats and Vests, for more info click on given link-Attack on Titan Garrison Regiment Cloak