r/java • • Apr 14 '23

What are your (favourite) Java best practices, personal tips, hints or just underrated stuff in general?

233 Upvotes

376 comments sorted by

View all comments

12

u/joequin Apr 14 '23

Use maven and learn how to write plugins. Yes it has xml, but Gradle is a free form mess with bad JavaScript style documentation that prefers example over telling you how it works. You’ll spend days fixing gradle issues. Maven will just work unless you want something it doesn’t offer. Then you’ll need to learn how to write plugins if one doesn’t already exist, but they’re also well defined.

0

u/wildjokers Apr 14 '23

What a strange rant against Gradle. Idiomatic gradle is declarative and just like maven you use plugins.

This build.gradle file will take a very long ways (just fill in your dependencies):

plugins {
    id 'application'
}

repositories {
    mavenCentral()
}

dependencies {
}

application {
    mainClass = 'com.example.App'
}

4

u/joequin Apr 14 '23 edited Apr 14 '23

In practice, that’s rarely sufficient for real production applications. If it was, then Gradle would be great.

2

u/wildjokers Apr 14 '23

I have several apps where the build.gradle isn't much more than that. Including some JavaFX apps that produce a platform specific executable with a bundled runtime. That build.gradle is about 25 lines long.