Please explain Jake Warton's views on toolchain (https://jakewharton.com/gradle-toolchains-are-rarely-a-good-idea/)

I was reading Jake Warton’s article on toolchains but couldn’t fully understand it. He mentioned that when he used the toolchain, the JavaDoc was compiled using JDK 8, making it non-searchable. As a result, he decided not to use the toolchain and instead opted for the latest JDK.

Why can’t he just update the Java version in the toolchain and use it? I have very limited knowledge of Gradle and toolchains, which is why I can’t fully grasp his article. Could someone please explain his pain point?

Retrofit toolchain migration: Configure project's languageVersion via toolchain by Goooler · Pull Request #3834 · square/retrofit · GitHub
Retrofit toolchain remove: Remove the use of toolchains by JakeWharton · Pull Request #4055 · square/retrofit · GitHub

Well, afair I disagree with most what is written there, or see it as non-issue and pretty opinionated and one-sided.

Not using a toolchain is imho a very bad idea, as you then again couple the toolchain used to build and run your code to the toolchain used to run Gradle, which might be fine for personal projects or highly controlled environments, but is pretty bad for all others.

Why can’t he just update the Java version in the toolchain and use it? Sure he could, he also mentions that in the article, and it would anyway be better if he did to decouple the two Java versions that should be totally separate and unrelated. Why he does not do it, you have to ask him.

Thanks for the reply,

How he was able to compile java doc with JDK 9 while he has used Java 8 in project(without toolchain) and why it is not possible using toolchain?

Without toolchain you couple the version to run Gradle to the version that is used to build and run your code.
So to build JavaDoc with Java 9 he had to run Gradle with Java 9.

As I said already, it is possible without problems, that’s why I said most points in that blog post I either don’t agree or see as non-issue.

You can configure for each task which toolchain it should use, configuring the global one is just the default for all tasks supporting it.

You can for example configure Java 8 toolchain globally and configure for all JavaDoc tasks that they should use Java 21 toolchain.

Or you can configure Java 21 toolchain globally and set release on all compile tasks to 8.

Anyway is better than coupling the toolchain used to build and run your code to the toolchain used to run Gradle imho. :slight_smile:

As I said, that post is imho very opinionated and one-sided. :slight_smile:

Thanks a lot.
I learnt a lot during this discussion.

1 Like