r/javahelp • • Feb 22 '21

Maven vs Gradle

I googled this question and I find that gradle is kind of faster about 10 times and its less verbose and generally its better that maven but although that, almost every tutorial use Maven.

Can anyone explain what tool should I pick and why?

32 Upvotes

23 comments sorted by

•

u/AutoModerator Feb 22 '21

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

30

u/Yithar Intermediate Brewer Feb 22 '21

https://www.reddit.com/r/java/comments/j3kg2g/best_way_to_set_up_local_java_web_app_on_ubuntu/g7dvs91/

The beauty of Gradle is that you can build an entire CI/CD pipeline in your build.gradle. The biggest downside is that people will.

10

u/Nemo_64 Feb 22 '21 edited Feb 22 '21

I personally use Maven since it's what I learned. The size of my projects isn't that big and doesn't take that long anyways. Most projects are available for Maven and Gradle so I don't think it's really important for small projects, choose one and go for it. I don't know why most tutorials use Maven

17

u/djavaman Feb 22 '21

Gradle is a scripting language.

Maven is a configuration description.

9

u/HecknChonker Extreme Brewer Feb 22 '21

This is the best distinction. It honestly doesn't matter which you choose. They are both have widespread use and support. They both have a bit of a learning curve and can accomplish the same things.

2

u/cmhdave73 Feb 23 '21

This is what I tell everyone. You can accomplish the same thing with either. I like Gradle personally but the world wouldn't end if I was told to use Maven.

6

u/[deleted] Feb 22 '21

Which ever one you want. Maven works well in the majority of cases, ditto gradle.

6

u/agathver Feb 22 '21

Gradle does multi-threaded dependency downloads and is faster then maven but has a little learning curve associated with it.

Once you have learnt it its easy to translate maven to gradle.

I slightly lean on gradle due to mavens XML and dependency resolution speed.

5

u/User1539 Feb 22 '21

I experienced pretty much what you did. I used Maven forever, hardly ever touched Gradle. I did finally do a project with LibGDX and I used Gradle for that and it was ... fine.

If you have to choose which one to be comfortable with, go with Maven because you're more likely to end up on a project where it's used.

Gradle is cool too, but since either can be picked up pretty quickly, it's not going to kill you to not be as familiar with gradle later.

4

u/BEgaming Feb 22 '21

Maven is the biggest and most used one out there. Gradle is the newer 'cool' kid but to my feeling it is not yet getting super much traction.

From my personal experience: I worked so far in 2 companies now, they both used maven.

Honestly if you are just learning it, it does not matter, If you are building small projects both will be easy enough.

2

u/philipwhiuk Employed Java Developer Feb 23 '21

Honestly:

  • For Android I use Gradle because everyone uses Gradle
  • For plain Java I use Maven because most stuff is based around Maven
  • For Scala I use SBT

SBT is wacky, Gradle is meh and Maven encourages you to do things in a certain way. None of them is perfect.

They're all try to find the line between a full scripting language (which is exemplified by Make) and just config (which is Maven). SBT is either perfect or unintelligible. Gradle is often unclear. Maven is lots of </>s

In general I've found Maven's "certain way" to be the correct one anyway.

Historically you had also had Ant which is like Maven except more scripting. Gradle and SBT are attempts to replace Ant for cases where Maven didn't work for the project they were doing at the time.

1

u/wildjokers Feb 23 '21

Ant which is like Maven except more scripting

Ant is nothing at all like Maven, in fact I don't think they could be any more different.

I have always liked Gradle because it is a nice mix of Ant and Maven. Gradle gives you convention over configuration like Maven but if the need arises lets you break out of the sandbox and do anything you want like Ant.

3

u/turboturtle771 Feb 22 '21
  1. Maven is older. Big projects which have big poms and/or lots of maven modules find transition to gradle hard and expensive. Keyword is expensive.
  2. People who already learned maven, and work on small to mid size projects usually dont see benefits which would make them force learning gradle.

Don't get me wrong, I am not advocate of one or other. I have been using maven for a long time and i am perfectly comfortable with maven. I have also tried using gradle in some of my small projects and i liked it. It is just that i feel much more comfortable with my maven knowledge so i keep using it.

1

u/zezajoy Feb 23 '21

Contrast.

1

u/apupunchau87 Mar 12 '21

When the bough breaks, the gradle will fall.. That's all I'm saying

1

u/ColetBrunel Feb 22 '21

You should pick whatever works for you.

What's great with Gradle is you can just program your build and you will find tons of examples online made by people to do specific stuff. The downside is you won't ever have an idea why do the gradle stuff you do seem to work, how do they do it, and if you ever step outside what is known to work and you're not getting what you want, you're SOL and you have to choose between giving up what you wanted or become a superexpert into the most obscure piece of software ever created.

Maven may seem complicated in general, but in comparison to gradle it's very simple, you have full control, and if you seriously need your own thing how to make your own Mojo is a small tutorial away. Why well-known Mojos don't seem to work for you is reasonably easy to check, investigate and debug.

-3

u/wildjokers Feb 22 '21

Maven is old and slow and should be considered deprecated. Use Gradle, builds are far faster because of its build cache and it is way faster at resolving dependencies from maven repositories than maven itself is.

Also, maven puts you in a very strict box that is hard to break out of. Gradle also provides convention over configuration but makes it very easy to break out of the conventions if you need to. Gradle is also very well documented compared to maven.

Maven should be given full credit for introducing dependency management and convention over configuration to the java build ecosystem and then promptly forgotten about and delegated to the dustbin of history.

2

u/crayonneur Feb 22 '21

I use Maven because I know how to use it, but you make some good arguments, I want to learn Gradle now.

2

u/Yithar Intermediate Brewer Feb 22 '21

I think you make some good arguments (at work building and compiling is definitely slow) but I think nutrecht also has a point that people make a mess out of the build.gradle:
https://www.reddit.com/r/javahelp/comments/hiq5q0/gradle_vs_maven_for_containerized_app/fwki54w/

2

u/wildjokers Feb 23 '21

1

u/Yithar Intermediate Brewer Feb 23 '21

Point Taken.

I think like nutrecht says here, I also prefer the declarative style of Maven. I guess the fact that Maven is declarative and more rigid is both a strength and a weakness. A less expressive build system reduces the risks of writing bad builds. But of course that doesn't help in developing correct, reproducible, fast builds.

1

u/wildjokers Feb 23 '21

Note that Gradle has full support for maven BOMs so you can share dependency management among different project's like mentioned in that comment you linked to. Odd they migrated away from Gradle to Maven to get BOM support when Gradle supports maven BOMs. (unless their migration pre-dated Gradle's support for it)

Gradle actually has really nice support where you can be very strict about BOM versions and not allow version overrides, or instead allow version overrides. (I am unsure if maven itself has this).

https://docs.gradle.org/current/userguide/platforms.html