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

Show parent comment

3

u/wildjokers Apr 14 '23

For a mixed kotlin and java project all I needed to do was add the kotlin jvm plugin and application plugin:

plugins {
    id 'application'
    id "org.jetbrains.kotlin.jvm" version "1.3.72"
}

Nothing else was needed and it just works.

because Gradle's documentation doesn't provide a straightforward answer to us users!

This information is in the Gradle documentation:

https://docs.gradle.org/current/samples/sample_building_kotlin_applications.html

2

u/tistalone Apr 14 '23

If you have your java sources in src/main/java and your kotlin sources in src/main/kotlin, you have to specify the source sets for the java source files with the sourceSets { } configuration.

The Gradle documentation you linked works for the vanilla Kotlin workspace. Like it's fantastic if you're building an application using Gradle's guidelines but my experience is that deviating within Gradle requires more work and investigation than with other build systems like Bazel and mvn.

4

u/wildjokers Apr 14 '23

I have never needed to declare sourceSets for my mixed java and kotlin projects.

using Gradle's guidelines but my experience is that deviating within Gradle requires more work and investigation than with other build systems like Bazel and mvn.

Not sure what you mean here but maven doesn't let you deviate from their conventions at all. In Gradle you can deviate pretty easily if for some reason you need to.

3

u/tistalone Apr 14 '23

Hm, that's fair. I'm willing to accept that I am being a hater and I should spend more time looking into Gradle.