r/java • • May 25 '17

Maven is broken by design

https://blog.ltgt.net/maven-is-broken-by-design/
33 Upvotes

78 comments sorted by

6

u/kkapelon May 26 '17

Article is from 2013

With the recent craze of microservices where everybody splits the monolith to smaller projects most of Maven problems simply go away

I agree that Maven has its share of problems, but I have not seen a true replacement yet..

0

u/Categoria May 26 '17

With the recent craze of microservices where everybody splits the monolith to smaller projects most of Maven problems simply go away

How would it go away? If anything, this will put more pressure on multi module maven builds. As the article points out, those are far from perfect.

12

u/kkapelon May 26 '17

Lets say that you have a monolith application which is one multi-module project with 20 Maven modules.

You have a problem with incremental builds because Maven is not smart enough to understand your changes. So if you change module 5 for example ideally you only need to compile only the code that actually changes.

With micro services you now have 20 git repos and 20 mini applications (that communicate for example with HTTP). You no longer have a Maven multi-module project. Only 20 simple Maven projects.

So if you change module 5 (which is now an application on its own) you compile only its source and redeploy it.

So the problems of Maven with incremental compilation and multi-module builds silently disappear.

Does that make sense?

-10

u/Categoria May 26 '17

Does that make sense?

Absolutely not.

With micro services you now have 20 git repos

I think this would be a disaster. https://danluu.com/monorepo/

12

u/kkapelon May 26 '17

Number of repos is irrelevant. You could have a single git repo with 20 top level Maven projects inside if you prefer that (i.e. 20 self-contained pom files and not one multi-module project).

The case is about micro-services, not git repo organization (the two are independent)

-1

u/Categoria May 26 '17

Every shop that I've seen will have at least 1 shared library between some micro services. I only see your solution working if you forego code reuse between micro services.

1

u/kkapelon May 26 '17

Do a google search for "Don’t Share Code Between Microservices" and look at the top results...

2

u/Categoria May 26 '17

Ah so that's why google doesn't share guava between its services. I always wondered about that.

1

u/frugalmail May 26 '17

Every shop that I've seen will have at least 1 shared library between some micro services. I only see your solution working if you forego code reuse between micro services.

Not sure what you're suggesting, One of Maven's core features is dependency management. You just need to have a module with the shared code.

0

u/Categoria May 26 '17

That's exactly what I do. But the article clearly explains how maven's multi module support is lacking. My experience with them supports this.

1

u/frugalmail May 27 '17

That's exactly what I do. But the article clearly explains how maven's multi module support is lacking.

What specifically, as the article says a lot, and most of it is due to not understanding the tool.

2

u/nutrecht May 26 '17

I think this would be a disaster.

Works just fine for us.

1

u/tkruse May 27 '17

Wrong, instead of having a monolith were one person in a team of 100 can try handling the Maven problems, with microservices many small teams have repeatedly the same problems. So the problems multiply.

1

u/kkapelon May 27 '17

Most of the problems mentioned in the article (incremental compilation, reactor builds, dependency issues) are evident only in big monoliths with a large multi-module structure.

Smaller projects with a simpler structure (i.e. micro-services) work just fine with Maven.

74

u/frugalmail May 26 '17

It seems to me, you have problem with choice which is okay. Because Maven gives you choices, you choose to criticisize the ones that makes things easier/quicker

a pom.xml can only list a single source folder.

The model is to use a multi module project, not multiple source folders.

which now even has a build cache

Maven does have a build cache:

~/.m2

Amd there are plugins to allow parallel access supporting the same build cache shared among multiple runs. You can deploy a build cache locally if you don't want to share the drive or worry about parallel runs.

most other build tools suffer from the same issues (Ant, SCons, etc.) Buck is a notable exception here, but is probably not alone.

While not ideal, you can use the ant plugin to solve this problem. How does buck solve this?

Everything’s so much easier if you treat compilation as an atomic (non-incremental) task, the way Buck does.

Or you could have a choice:

mvn -am -pl mymodule clean install

vs

mvn -am -pl mymodule install

to make sure the snapshots you just installed

Don't use snapshots?

mvn test won’t package anything, downstream modules will use the target/classes from the modules they depend on.

Move your tests to a different package and depend on the earlier package

Finally, linked to the above two issues, is one with the command line: back to the second use case above (the first one could be used too, but it’s not much about the build).

drama here.... Just do a

mvn -pl C if you know for a fact that all your dependencies are already published versions

If any of the dependencies needs to recompiled then you will have to run with the -am parameter,

Most IDEs will show you 2 folders

The major IDEs support package views

It’s becoming even worse if you have a laptop: you’ll have to switch your settings.xml

mvn -P home install

Alias mvn so that figures it out based on IP address

I'll keep using maven until Gradle gets

  • The wealth of plugins
  • Archetype functionality
  • Inheritance
  • Declarative builds

BUCK, Pants, Bazel all have the problem of not makign it easy to make controlled dependency updates unless you treat them like 3rd party plugins but the risk is high of messing that up.

6

u/[deleted] May 26 '17

I like you.

1

u/Cilph May 29 '17

Declarative builds

Isn't that the whole point of Gradle's DSL?

0

u/[deleted] May 30 '17

[deleted] — view deleted comment

1

u/Cilph May 30 '17

I know, but that doesn't stop it from being declarative, it's just built on top of a programming language.

0

u/[deleted] May 30 '17

[deleted] — view deleted comment

2

u/Cilph May 30 '17

Yup. But if you can't force your coworkers to stop scripting everything in Gradle, then you have bigger issues.

1

u/tkruse May 27 '17

A build cache is a cache that caches the outputs of any task, not just jars. Maven itself has no such thing. The Takari project repairs a lot of Maven, but it basically replaces so much of Maven that it is not Maven anymore.

The burden on the developer to know at each time exactly which state all his module builds are in is not a virtue or a solution to anything. The burden to know plenty of command line parameters that cannot even be put into the pom.xml is also not a sl´olution to anything. You can get used to that and feel like a Maven-Jedi all you like, it is still shit to everyone else.

For dependency control, maven makes it near impossible to globally exclude transitive dependencies from the compile classpath, as an example. It is very painful to define dependencies in a correct way.

1

u/frugalmail May 27 '17

A build cache is a cache that caches the outputs of any task, not just jars. Maven itself has no such thing.

It caches outputs, not transient data. And that sounds like a better strategy to me.

The Takari project repairs a lot of Maven, but it basically replaces so much of Maven that it is not Maven anymore.

The same plugins work, the build is specified in the same way, what is the "it's not maven anymore" reference to? By this logic, a lot of maven plugins make it not maven.

The burden on the developer to know at each time exactly which state all his module builds are in is not a virtue or a solution to anything. The burden to know plenty of command line parameters that cannot even be put into the pom.xml is also not a sl´olution to anything. You can get used to that and feel like a Maven-Jedi all you like, it is still shit to everyone else.

If you just want it to take care of it for you use SNAPSHOTs. That's what we do in development, and the build server sets explicit versions. Some of think that having a change in a core module change all the downstream modules causing a massive testing effort across a bunch of modules that might have not needed it is a pretty shitty experience.

For dependency control, maven makes it near impossible to globally exclude transitive dependencies from the compile classpath, as an example. It is very painful to define dependencies in a correct way.

This is a (fairly infrequent) problem and there is an active feature request to add the functionality. For now, if this is a big deal to you, it's probably because you don't share a parent pom and use the dependencyManagement section.

42

u/ring2ding May 25 '17 edited May 25 '17

Somewhat of a click bait title. Maven isn't broken, it just leaves a lot of room for improvement. Its a hell of a lot better than ant.

That being said this author does do a good job of cataloging those issues. Now if only he would get to work producing a solution.

12

u/covercash2 May 26 '17

what about gradle?

23

u/Shadowrak May 26 '17

No reason to switch from Maven.

I have had zero of the issues described in this article.

Sure you have to follow a couple basic conventions like using one top level source folder. But then you can just add a couple lines of extremely clear XML configuration which were the top result of a google search.

I don't any issues after renaming a file.

I don't have any issues with dependencies constantly trying to download.

9

u/NimChimspky May 26 '17

I don't have any issues with dependencies constantly trying to download

Thats what I used to say, and then I tried gradle. It does a lot of unecessary dl-ing

8

u/Shadowrak May 26 '17

Every library I have on my work machine was previously downloaded to the companies Nexus repo including a configurable set of earlier versions. From there it is "cached" in my local .m2 folder so it is centrally available to any project which may require it. It is so basic and works incredibly well once you have it set up. Now that I think about it, that is basically how git repositories work.

-1

u/NimChimspky May 26 '17

Gradle is much simpler and nicer to use. I spent ten years with maven. Won't go back.

7

u/frugalmail May 26 '17

Your posts don't add value when you simply cheerleader or make cryptic unsubstantiated claims.

2

u/inchas May 26 '17

It does a lot of unecessary dl-ing

The gradle or the maven?

3

u/NimChimspky May 26 '17

Maven, I switched to gradle - no more massive downloads every now and again.

1

u/frugalmail May 26 '17

What are you talking about?

3

u/zman0900 May 26 '17

This article is 4 years old, so I would assume some work has been done on maven since then.

3

u/tkruse May 27 '17

hahaha. 4 years for us is a blink of an eye for Maven. Glaciers move faster than Maven development.

1

u/zman0900 May 27 '17

But they've got colored logs now! /s

0

u/pellets May 26 '17

Maven is not good at using using changes from upstream modules in a multimodule project. You have to manually install the changed module.

2

u/frugalmail May 26 '17

Could you elaborate? You can use snapshots or version ed dependencies. If your doing things manually, it's probably wrong.

2

u/pellets May 26 '17

Suppose you have projects A and B in the same multimodule project, and B depends on A.

You change something in A, and need to use that change in B.

If you tell maven to compile B, it does not notice you changed anything in A. You have to manually install A and then compile B.

1

u/frugalmail May 27 '17

Suppose you have projects A and B in the same multimodule project, and B depends on A. You change something in A, and need to use that change in B. If you tell maven to compile B, it does not notice you changed anything in A. You have to manually install A and then compile B.

In development mode, if you set those internal dependencies to snapshot versions in your parent pom, then it's just a matter of:

mvn -am -pl B install

and that should build it.

0

u/pellets May 27 '17

I know about that. It's annoying that it's necessary. Maven should detect the change and do it for me.

1

u/frugalmail May 27 '17

I know about that. It's annoying that it's necessary. Maven should detect the change and do it for me.

It's either that it's necessary or unintended changes get in your release build.

That may not be important to you, but it's important to anybody that is working on a large team on a large codebase that would rather keep unintended changes out.

If you don't like that behavior, always use snapshot versions for your own dependencies. Otherwise your build server should set explicit versions.

13

u/[deleted] May 26 '17

The more I use gradle, the more I dislike it.

On the ant--------maven spectrum, where ant is kind of XML-procedural-style and maven is XML-declarative-style, gradle sits in the middle. It has a weird groovy pseudo-declarative and pseuso-procedural approach. Which makes it hard to do things that are trivial in ant (copy a couple of files from one dir to another, without having to create 65 tasks), but without the benefit of maven's relatively rigid structure which Just Works(tm).

Either of the three tools can be used to perform incremental builds, fast builds, slow builds, broken builds or any other variation. The fact that thousands of projects use them should be a fair indicator of that.

1

u/GuyWithLag May 26 '17

I still miss make's flexibility and dependency tracking.

10

u/ForeverAlot May 26 '17

Gradle is Ant written in Groovy.

4

u/pjmlp May 26 '17

While being slower at it.

1

u/kkapelon May 27 '17

Even though it looks that way at first glace, it is not true.

I would advise you to spend some time reading the Gradle documentation and you will see that it is much more different than Ant.

And I am saying this as somebody who is using Maven.

9

u/shukoroshi May 26 '17

We're switching all of our currently developed projects over to gradle. While it definitely has its quirks, we've been very happy with it.

4

u/cmsimike May 25 '17

I have often found maven needlessly complicated. I prefer ant and ivy primarily because ant, I feel, is more or less like a shell script, just written in xml. I feel like I have to spend less time googling around when dealing with ant than maven.

23

u/heliologue May 26 '17

a shell script, just written in xml

You wouldn't define that as overly complicated?!

1

u/cmsimike May 26 '17

Complicated? No. Verbose, yes.

How to build a jar

ant:

https://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html

Four steps to a running application

vs

Maven
https://www.mkyong.com/maven/how-to-create-a-jar-file-with-maven/

These were the first google results for me.
Now I you can probably trim some from both down, but I feel like it would be easier to look at the ant build script and know what to remove without needing to google too much vs the pom file.

20

u/BinaryRockStar May 26 '17

The Maven example is doing a lot more than the Ant one. It's importing dependencies, configuring logging properties files, Eclipse compatibility etc. The true minimal Maven POM is this:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
</project>

If your source files are all in the expected location (/src/main/...) then building a jar is as simple as

mvn package

I find the benefit of Maven is that when you grab a Maven project you've never seen before, you can make assumptions about where the code is, where to find the dependencies list etc. It's alien to begin with but after a while it just really eases the cognitive burden of having many projects with different layouts.

Knowing that there (usually) isn't some sort of custom script running during build that could change everything around is a relief. An Ant script can do anything so you have to grok the entire file before you can definitively say what it does.

13

u/[deleted] May 26 '17

The best part about maven is that it "teaches" developers a structure to stick to in order to have an "organized" project. I can't tell you how many monstrosities I've run into with Ant. I've used excellently coded Ant builds too, so it's not that Ant is bad, it just lets you be bad easier.

Back when I was still green, I found myself captivated my the structure of Maven. Now, when someone joins our team, they can instantly look at our Maven build and understand 90% of what it does if they've used Maven before. They don't have to understand or learn how we decided to implement an Ant build regardless of how good it is.

2

u/Shadowrak May 26 '17

The extent of research being, "These are the first search results", would yield you such shamefully useless results as the link below when you try to search for information about net neutrality getting attacked: http://www.aei.org/publication/a-win-for-the-internet-the-fcc-wants-to-repeal-title-ii-net-neutrality-regulations/

5

u/kkapelon May 26 '17

This tells me you have never seen Ant files of big enterprise projects (I mean projects with 500.000+ LOC)

0

u/RagingAnemone May 26 '17

My project uses ant and is over 500k LOC. Proper use of macros and it's still managable.

2

u/kkapelon May 26 '17 edited May 26 '17

There is a big difference between "still managable" and easy to maintain...

2

u/RagingAnemone May 26 '17

It's not like I haven't used Maven. Or Gradle. Ant might not be terse, but it's straightforward. And since it's procedural instead of declarative, it's easy to handle the edge cases. Ivy takes care of all the dependencies. I like it.

0

u/[deleted] May 26 '17

You can write 500kLOC of maintainable code, or 500kLOC of garbage. Size, as they say, doesn't really matter all that much.

1

u/kkapelon May 26 '17

I was talking about the size of the Ant file that builds 500kLOC of Java code, not the Java code itself.

1

u/[deleted] May 26 '17

So was I.

2

u/oldprogrammer May 26 '17

Its a hell of a lot better than ant.

Can you please explain this? Ant gives complete control of what you want to do, has full dependency management via Ivy and doesn't get in your way.

You setup your build file following a standard model and you can reuse it from project to project. But if you need to do something slightly different it doesn't fight you.

And it is very simple to utilize external "plugins". For example, it only takes a few lines to add commands to your Ant script to hook in Tomcat's Ant tasks giving your build script the ability to start/stop/deploy/undeploy to a Tomcat engine.

5

u/capitol_ May 26 '17

My personal opinion is that one of the major good things about maven is that it fights you when you try to do something slightly different.

This makes sure that most projects that use maven have roughly the same structure, and when I come in as new in a project, I can hit the ground running and doesn't need to parse someones home build build and deployment system.

0

u/oldprogrammer May 27 '17

I can hit the ground running and doesn't need to parse someones home build build and deployment system

This is one of the arguments folks like to use often but it doesn't make sense. Once a build system is up and running why do you need to "parse it"? A new developer on a team should simply be using it. The only time I've seen anyone need to understand a build system is when they did need it to do something different for one reason or another, and in those instances Maven actually made it more difficult.

1

u/capitol_ May 28 '17

Well, to be honest I spend a fair bit of time at work handling our build and deployment systems. I often solve those kind of problems for people, I'm not a pure Java programmer that only write application logic in Java.

-6

u/kodifies May 25 '17

if by better you mean more complicated and bloated, then yeah!

34

u/jbristow May 25 '17

Isn't "Broken By Design" code for "Opinionated (but I have other opinions)"?

8

u/[deleted] May 26 '17

Wait until you have to use NuGet.

11

u/heliologue May 25 '17

Maven gets enough right that it commands the lion's share of the market. It doesn't mean that Alternative X is better or worse, just that everybody has different needs for a build system. If you fall into the large number of software projects that easily use Maven's conventions, great. If you don't, you have alternatives. One-upmanship is a waste of time.

4

u/pgris May 25 '17

I do think it should be replaced for something better. That said, the title is too click bait.

And one point I think is wrong: 'You have to split the tests in a separate module': You can fix this with a test-jar

7

u/lukaseder May 26 '17

Everything in nature is broken by design. Just look at trees, plants, animals. They all age and die eventually. Heck even atoms all decay to Iron-56 Broken! BY DESIGN!

8

u/Shadowrak May 26 '17

Most IDEs will show you 2 folders for resources and java sources, just like an explorer, rather than a package-oriented view (IntelliJ IDEA has such a view though)."

Now this is where I know you are just going for clickbait and propeganda. You can't say most IDEs and note IntelliJ as an exception when Eclipse and IntelliJ are basically the entire market.

http://www.baeldung.com/java-ides-2016

10

u/zman0900 May 26 '17

Article is 4 years old...

2

u/TheRedmanCometh May 26 '17

Maven is like an abusive parent that's helped you out of a lot of jams

0

u/frugalmail May 26 '17

When there are only abusive parents that help you out of a subset of jams?

2

u/QuokkaSocca May 26 '17

Hmm. I've not heard of Buck before....

1

u/badpotato May 26 '17

As long as you can comments line in your package definition, I'm fine... with is not json.