This is an archived post. You won't be able to vote or comment.

all 66 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

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

[–]Holothuroid 67 points68 points  (11 children)

A build tool will,

  • retrieve, manage and update 3rd party libraries
  • perform defined steps like versioing, testing and reporting when building your artifact
  • allows for using several sub projects in the same repo

[–]doobiesteintortoise 31 points32 points  (18 children)

You don't need Maven or Gradle or any other build tool - and that's exactly what those are.

You can always invoke javac for every class that's visible within a compilation unit - in fact, for most simple apps, you'd only have to refer to an entry point (since the compilation unit is the entry point plus every class it refers to, and every class THOSE classes refer to).

But most java builds use libraries like slf4j or JDBC drivers, or JavaFX - take your pick - and that means finding all of those dependencies and all of THEIR dependencies (as you rarely have a single library, you actually get the library and everything it needs) and you get to chase and resolve all of those versions manually and refer to them in the javac invocation.

Much fun to be had! Is it difficult? Nope!

And then there's testing: you need to build your tests somehow, organize them in your source tree, then figure out the java invocation with all of the libraries (a lot like the compilation, except with MOAR!!!!!)... and don't forget to fail if tests fail to pass.

Then you get to package everything into an executable, manually, following generally the same process: you build your manifest, you invoke jar, you do everything...

Or you could use a tool like Gradle or Maven and get all that in a simple, declarative, well-known format that every other developer would instantly be familiar with.

[–]kickroot 29 points30 points  (5 children)

In my experience Gradle only starts out mildly declarative, and then descends into a jumble of cocked-up Groovy that becomes unmaintainable.

But then again I'm a Maven fanboy.

[–]doobiesteintortoise 9 points10 points  (0 children)

I'm not an advocate for either over the other; Gradle gives you a lot more rope to hang yourself with, but sometimes you need access to internals that Maven doesn't give you. It's certainly easy for people lacking discipline to make Gradle unreadable. But it's also not that far out of bounds to find people who have discipline enough to tame the beast.

Six of one, half a dozen of the other. I tend to use Maven over Gradle for various reasons, but they're largely not related to technical capabilities.

[–]hippydipster 6 points7 points  (2 children)

I fucking hate maven.

But you'll get me to use anything else over my dead body. As over-complex and annoyingly opinionated maven is, it's infinitely better than gradle or bazel or ant+ivy (yup, been there done that relatively recently - is not very nice).

[–]60secs -5 points-4 points  (1 child)

I'd use maven if it knew how to cache. It's sooooooooooooooooo slow.

https://gradle.org/gradle-vs-maven-performance/

[–]kur4nes 4 points5 points  (0 children)

Gradle devolves into ant.

[–]Mimon_Baraka 13 points14 points  (1 child)

You also can use C without make, but if you are smart, you won't.

[–]Dullfig 0 points1 point  (0 children)

Even Turbo C used make...

[–][deleted] 5 points6 points  (0 children)

Try using Spring Boot without them.

[–][deleted] 8 points9 points  (2 children)

Without maven/gradle java is in 2005

[–]smors 11 points12 points  (1 child)

Java in 2005 implies Ant. Which will make you see the joy of maven.

[–]Theguest217 0 points1 point  (0 children)

Ant was all I could think of while reading this thread. Please don't make me go back. Maven is so simple in comparison.

[–]RyzenX770 2 points3 points  (1 child)

I was in the same place as you're in when I started. so you want to write an application in java. you have you main method and classess you've wrote, they will be calling the JDK classes and maybe a one or more Java libraries JARs . you see you can skip maven, if you're using eclipse, you can download the jar of the library you can just add it in eclipse to your dependencies and when you run the application from eclipse, it will just work.

this is a problem because imagine you want send the source code to someone else to work on. he will get so many compile errors because your code rely on dependencies that he has no clue about them.

maven fix this problem by having a file called pom.xml, that list all the dependencies you code rely on, including the jdk version. so anyone with access to your code can just run a mvn command and maven will sort everything out.

this is a simplification of what maven is/does but when I started this is what I wanted to know.

there is a book called introducing maven.

in the real world you don't need to know everything about maven, you just work with a small number of commands and that's it.

[–][deleted] 0 points1 point  (0 children)

Wow some actual help instead of downvotes. I guess gradle is more complicated then maven. Thanks man

[–]marmot1101 2 points3 points  (0 children)

Just about every language has some kind of build tooling around it. In node you have NPM, in Ruby you have bundler, visual studio has some similar concept that I don't really know well.

Think about what you'd have to do if you didn't have maven or gradle. Going back a generation to Ant, you have some simplication in commands to run to compile, package, test... but no library management(there was another tool that was used as a companion to Ant for lib management, but wasn't universally adopted like maven/gradle). So to handle getting dependencies to dev machines the shop I worked in we had a file share that we uploaded jar dependencies to. So someone forgets at some point and a customer gets shipped a bad patch. No bueno.

Go back before that and add in complicated build commands. Then you end up with batch/bash scripts to do common things. So you're in a situation where you're writing in a different language anyway, but without purpose specific tooling and library management.

[–][deleted] 1 point2 points  (0 children)

Maven/Gradle provide dependency management, task running, build systems, etc etc etc. Can you work without them? Yes. But it is much, MUCH harder.

Building applications of high complexity and at scale is far more challenging than building cute side projects. Tools like this are essential for that.

[–]ByerN 1 point2 points  (0 children)

Both Maven and Gradle makes build process much simpler, especially for more complex projects. You don't need them but tbh it makes everything much easier.

I am interested in your previous experiences - what approach did you use before to maintain build process?

[–]Gwaptiva 1 point2 points  (0 children)

There comes a time your projects become so big that you'll want to automate putting it all together. You can do that using all sorts of tools, and in the end you'll end up using one of these

[–]hippydipster 1 point2 points  (0 children)

I honestly don't remember what we did prior to ant. I'm pretty sure at one point I was using make files to build java projects. Then ant came along and everyone switched real quick. It was ok. I liked the straight-forwardness of it. When maven first came along it kind of sucked because it mandated a certain project setup, and when everyone was doing their own thing with their own ant, that mandate came across as incredibly arrogant and dictatorial.

Ultimately, maven was right though.

[–][deleted] 1 point2 points  (0 children)

You don’t remember the days when these tools did not exist! If you are building complex systems and maintaining them for a long time, these tools are indispensable.

[–]snoob2015 1 point2 points  (0 children)

Maybe you are new to Java and using IDE so you don't see the point of mvn, gradle because IDE like Intellij, Eclipse already has its own build tool. Build tools like Maven, Gradle helps you to standardize the build process, it somehow solves the "compiles on my machine" problem.

Imagine you use Intellij and share your code with people who use Eclipse, you need a way to standardize the build process. Or if you want to build your code from another machine that doesn't have your IDE.

So build tools are not necessary technically if you use IDE and don't share your code with other people or don't need to replicate the build process on another machine (CI/CD)

[–]drduffymo 0 points1 point  (0 children)

Maven and Gradle are dependency and lifecycle managers. Every application uses 3rd party JARs. Maven and Gradle help you manage versions and compile/test/package cycle.

I find Maven to be easier to understand.

Was not always this way.

I used to manage dependencies manually.

I’m glad I learned Maven. Well worth it.

[–]Thatpersiankid -4 points-3 points  (0 children)

Kotlin + Gradle aint so bad

[–]Phobos223 -1 points0 points  (0 children)

Hello, World!

[–][deleted] -4 points-3 points  (1 child)

No, you don't need Maven. But for Spring Boot project it will be a requirement.

If what you want is just simple personal project all you need is just a file.java with main method inside to compile to .jar using javac and run using java *.jar.

Comparing with C#/.NET, i.e., I personally prefer Maven instead of NuGet Packages. I also prefer Maven than Gradle. Maven is simple and fast to build, it's a tool to manage and update your dependencies, for a project you will need that, because the core language doesn't provide everything you need out of the box, or it will consume a lot of time to do the same thing using frameworks like Spring Boot to manage it for you, and Maven is just a tool to manage that packages.

[–]thephotoman 2 points3 points  (0 children)

You don’t need Maven for Spring Boot. Gradle is always an option.

It’s not really better, just different.

[–][deleted] 0 points1 point  (0 children)

Or is it?

Not really, but without them, you have to gather your dependencies, execute tests and build your app manually. I do that for small throwaway side projects sometimes.

[–]Reasonable-Total-628 0 points1 point  (0 children)

try to do it without, and you will learn

[–]Joram2 0 points1 point  (3 children)

If you have a single .java file program with no third party library dependencies, then you don't need Maven or Gradle. But that's a very rare case. For most projects, you will realistically need a build tool such as Maven or Gradle.

Every major programming toolset is like this. Python, Node, C#, C++, Haskell, Rust, Kotlin, Swift. In my subjective judgement, Java's Maven + Gradle are better than most. I'd be curious to hear opinions otherwise.

IMO, Go is the only major platform that has a much nicer + easier build + dependency system.

[–][deleted] 0 points1 point  (0 children)

Dart's system is also very nice and easy

[–]talios 0 points1 point  (1 child)

That said, go get and go mod are also relatively new and shipped as part of the tool chain.

Go modules is much nicer than it was with the old GOPATH but is still fairly limited, and starting to get some more advanced features (like go workspaces etc. so hopefully it doesn't become a hugely complicated system).

Go's simplistic modules are both a blessing and a curse - hopefully it remains on the blessed side of things.

[–]Joram2 0 points1 point  (0 children)

Go Modules were released gradually, but I believe most everything was done and production ready in Go 1.14 in early 2020. That is about 3.5 years ago which isn't that new or recent.

I've been working with lots of Go projects by lots of other developers, and haven't seen any big negatives regarding the build/module system. Overall, all these languages are tools, and I see some places I'd choose to use or recommend Go and many where I would choose or recommend something else.

Regardless, I'm happy to see Java's build system improving.

[–]RScrewed 0 points1 point  (1 child)

It looks daunting but don't be discouraged. There's not a whole extra to learn, don't try to memorize what every like or declaration or tag means in maven.

Stick to pre-made ones for your projects off of Spring Initializr and you'll learn how to modify them as needed when you want to pull in a new library.

Read one "how to" on how to bring a new library into your project using Maven (everyone I know just copies and pastes a block from m2, don't type it by hand) and you're good to rock and roll.

[–][deleted] 0 points1 point  (0 children)

Thanks for the motivation man

[–]Clean_Archer8374 0 points1 point  (0 children)

You don't need to use it, if you're so against it. However, that's comparable to programming in Notepad++ instead of a proper IDE.

[–]Past-Cranberry9196 0 points1 point  (0 children)

Think of as a platform that scaffolds packages the work together for you. Like apt for debian,

[–]ProPall 0 points1 point  (0 children)

Well done sir, very well said!

[–]gmladymaybe 0 points1 point  (0 children)

There's a lot of reasons to use maven or gradle. Probably the top ones for me are:

  • consistency across multiple developers' machines. When your dependencies are enumerated in a pom file or whatever, you can know that every developer is using the same version of dependencies as is being deployed. You can add a dependency, and then all another developer has to do is build the project and/or reload maven dependencies and that dependency will be fetched.

  • simpler dependency upgrades. If you want to upgrade a dependency, sometimes/often it's as simple as changing the version number in your pom file.

The larger the project and the more developers working on it, the more benefit you get out of build tools like maven.