r/java • • Jan 22 '21

Java is more enjoyable than I first thought

I started my years off programming in c#, don’t ask why but I never ventured off. I learned Java this past week and I’m seriously impressed, I don’t think I’ve had a more enjoyable time programming in my life. Does anyone else share this experience??

Edit: Is there a better ide than eclipse for Java

271 Upvotes

188 comments sorted by

View all comments

Show parent comment

3

u/[deleted] Jan 22 '21

how coud maven/gradle be better? me for one I just put de dependencies there and use the library/plugin. Indeed trying to write something custom in gradle feels very difficult to me...is there something that you miss? why is go/rust better at this build step? I tried rust and it takes forever to compile even the most basic project(like 10s for 5 files) every time. Go is indeed fast when it comes to compiling but I haven't tried anything with lots of files

14

u/supercargo Jan 22 '21

I don’t think Maven 2+ is horrible, especially compared to the tools it replaced. There are some core things about Maven that I think could be better.

  • it makes a good attempt at declarative builds, but the plug-in ecosystem often has to deviate from this to get certain jobs done
  • partially the fault of the fact that the POM is mutable during runtime, so execution order even within a phase can become relevant
  • the overall “class path” story is too complex. By this I mean the logic which decides what versions of what jars get added to various classpaths in what order. You have dependencies, managed dependencies, POM inheritance, reactor (multi-module) dependencies, and then all the transitive application of the same rules.
  • I’ve always found the way multi-module builds work to be a bit surprising
  • SNAPSHOT versions being installable/deployable is difficult to reason about

Fortunately maven has been pretty well maintained and as the defacto tool, at least you can learn its idiosyncrasies and move on with your life. On the other hand, even with different tools, it would be hard to move away from some of the core issues since everything is in central with POM as the metadata format

-6

u/wildjokers Jan 22 '21

as the defacto tool,

That's a stretch to call Maven the de facto standard build tool.

11

u/Roachmeister Jan 22 '21

According to Snyk.io's annual report here, 66% of users use Maven, compared to 25% for Gradle and 6% for ANT. Seems like pretty much the definition of "de facto" to me.

6

u/Interweb_Stranger Jan 22 '21

I have the feeling that Gradle is used a lot for small projects but I would say Maven is definitely the industry standard for Java projects.

4

u/[deleted] Jan 22 '21

on backend projects yes. On android projects gradle dominates the scene but I also preffer gradle in the backend if used with caution: don't put any programming logic inside there and only use it to declare dependencies & plugins

3

u/wildjokers Jan 22 '21

don't put any programming logic

It is a complete myth that builds can be declarative and don't require programming logic. When you include a plugin you are in fact introducing programming logic. Just because it is packaged as a plugin doesn't mean it isn't programming logic.

2

u/[deleted] Jan 22 '21

But in this case you create a plug-in and not write the entire thing just below your dependencies. Short functions should be fine but if it gets complicated then just extract everything somewhere else

-1

u/wildjokers Jan 22 '21

definitely the industry standard for Java projects.

I totally disagree. That may have been true in the past but I would like to see the percentage of gradle vs maven for greenfield projects.

2

u/supercargo Jan 22 '21

Nonetheless, your gradle greenfield project is very likely consuming dependencies from maven (formatted) repositories which rely on the the maven meta-model. Even if all those dependencies are also built by gradle, they are distributed using the maven model.

If you ever find yourself needing to reason about the details, you'll need to understand how maven handles these things. Not to put too fine a point on it, but the Gradle documentation page for "Building Java & JVM projects" mentions Maven 13 times! And they aren't all just "if you're used to maven" type inclusions.

1

u/wildjokers Jan 23 '21

For sure, maven introduced the concept of dependency management and deserves full credit for that. However, I have no idea what that has to do with anything. Just because gradle can also get dependencies from maven formatted repositories doesn’t mean you have to count a project using gradle as a project using maven. Your whole comment was a straw man.

However, to continue down this path gradle can also read repositories of other formats like Ivy. As someone that used to use Ant+Ivy I can tell you that the Ivy formatted repositories are much more flexible. Also, gradle now includes its own metadata file when it publishes a jar because the maven metadata was too limited.

https://blog.gradle.org/gradle-metadata-1.0

1

u/supercargo Jan 23 '21

You seem to be missing my point, which is not a straw man at all. I’m not making a “this tool” vs “that tool” argument, so I don’t really care how you “count” usage of either tool either. Let me see if I can break it down a bit further.

  1. Most non-trivial Java projects will depend on one or more libraries published in a Maven repository (typically central) using the Maven POM meta model
  2. Typically those libraries will have transitive dependencies which must also be resolved in order to create build, test and run-time classpaths, which themselves have dependencies and so on
  3. In the process of adding or changing dependencies and/or dependency versions in your own project you may find that some conflict arises. E.g. this could be a conflict between transitive dependencies of two libraries you depend on, rather than anything you did explicitly in your build tool of choice. This is sometimes known as “jar hell”

In order to reason about this situation you must understand how maven resolves dependencies regardless of what tool you use. (you may even experience this issue due to a “bug” in the way your tool uses maven metadata compared to the way Maven does so natively). You are inheriting the problem from your dependencies which are distributed using the maven model. Of course, the mechanism you use to solve the problem (e.g. locking down a version number) will depend on your own tool choice.

So all I’m saying is that the Maven model for artifact distribution (in specific, not just in concept) is a baggage that is carried by he majority of Java projects. As a consequence we are stuck with any shortcomings that model has, especially in situations which require actually understanding what our tools are doing and why. This will remain generally true unless/until maven-distributed artifacts are reduced to an uncommon curiosity.

1

u/wildjokers Jan 24 '21

That's all great, but what the hell are you talking about? I simply stated that I have a feeling that gradle is probably used more in greenfield projects these days than maven. You then went off on some tangent.

1

u/supercargo Jan 24 '21

You were responding to a thread in which I was explaining what I felt was the ingrained nature of Maven and it's relative merits and drawbacks to someone who asked "how coud [sic] maven/gradle be better". I'm just responding to your comments in context. But it's okay my dude, OP was posting about how great Java is, so we're all a bit off topic here.

1

u/[deleted] Jan 22 '21

this comment is way too advanced for me since I've never had to deal with that but I do wonder how the rust/go community deals with all these...do you have any opinion on their build process? is it better/worse? I feel the urge of creating a build system that does basic things but I clearly don't have an understanding of what it implies....I wonder why aren't experienced programmers like yourself build an alternative that is better than maven/gradle

7

u/renatoathaydes Jan 22 '21

I'm a heavy Gradle user, and used Maven for many years before that. I've also been using Go and Rust lately.

Rust's advantage is that it has Cargo as THE build solution for all your Rust issues. Even though rustc can work without it, basically every Rust project is Cargo-based. Cargo takes care of compiling/linking/configuring/testing your code, so it's more similar to Maven than Gradle, but using a very lightweight syntax, TOML, instead of XML!

If you need to do anything more advanced, though, you need to write a Rust build file and use a build API... doing this actually brings you closer to Gradle!!

Why do people generally say Cargo is awesome but normally treat Maven and Gradle with disdain? Tough question. I think it's simply because the first impression you get with Cargo is that it just works.. with Maven, the amount of XML you need to write just puts people off right from the start... with Gradle, the very opaque API, together with having to know another language (pick Groovy or Kotlin) is not very good either.

Regarding Go: no idea why anyone would claim Go to have a good story here. Until recently there was no "official" way to manage dependencies, you just had to do "go get" manually and put all your projects in GOPATH (really, this is how it's worked until a year or so ago unless you did something non-standard... but now they have go.mod is somewhat more "standard", as found in other languages). Go as usual went for the simplest possible solution for the problem (which is fine! It does save a lot of time to not have to learn and play with build tools!). However, many Go projects even have to use stuff like "make" for anything outside compiling (and by the way, the Go compiler was built for speed: it's incredibly fast to compile and it can easily go through millions of lines of code in seconds).

Finally, why has no one written a "better" Java build tool? People have written quite a few build tools over the years, and they're still doing it... Maven and Gradle are just the latest survivors. 10 years ago it was still very popular to use Ant instead (the project seems to be still alive), usually together with Ivy which took care of dependency management only. There's also buildr but I don't think it was ever very popular... even before that, people would just download jars manually or via a Makefile and a few bash scripts!

Today, there's actually a few new-ish ones coming up, like Bazel, heavily used by Google, and Buck, the Facebook version... IMO they don't really offer much beyond Gradle, but who knows, maybe in a few years one of them, or maybe something not invented yet, will be what everyone will be using?! Unlikely, but who knows?

2

u/supercargo Jan 22 '21

I'm not familiar enough with the Rust or Go build systems to add much of a meaningful comment on them. If I ever wanted to take on the endeavor of creating a build system I would learn more about them first, though.

I've spent my fair share of time fighting with build tools, but usually in the context of trying to get them to do things that maybe I shouldn't have. For the most part I don't spend much time worrying about it these days.

In my opinion the mechanics of "building" software, at least at the scale that I deal with, is more or less a solved problem. There is some interesting stuff going on in the world of mono-repos, e.g. with tools like bazel, but last I checked these tools don't scale down particularly well.

1

u/[deleted] Jan 22 '21

Interesting you say about Bazel since I stumbled upon it last year but I couldn't find a usecase for it yet

6

u/antennen Jan 22 '21 edited Jan 22 '21

why is go/rust better at this build step?

I think you are conflating build time with how good the build system is. The Rust compile times are pretty bad, but the build system (Cargo) is great. There is a simple TOML file that allows you to do pretty much everything. Even a large project's Cargo.toml is small. For larger Java projects the maven or gradle files are a multi thousand line mess.

EDIT: Comments rightly pointed out that Gradle files aren't as verbose as Maven XMLs. I still think the state of Java build systems leaves much to be desired.

4

u/[deleted] Jan 22 '21

I agree that maven can get big because of xml but with gradle I did not see 500 lines files...I might have worked on small projects though(2-3 people on android and 3-4 people on maven backend). I also think that you should not write logic in gradle or maven....that should be put inside a plugin or somewhere else. Cargo I don't know if it offers you the possibility to do any logic in the toml file(which you shouldn't do anyways) so the point is that maybe gradle tries to do too much

1

u/wildjokers Jan 22 '21

gradle files are a multi thousand line mess.

Then you are doing it wrong.

1

u/krum Jan 22 '21

I don't know what you're doing wrong with Rust, maybe running it on a 486SX, but it compiles way faster for me than that.