Gradle, Javadoc and JDK version

Multi tool use
Multi tool use


Gradle, Javadoc and JDK version



I have multiple JDKs installed.



In my build.gradle, I set sourceCompatibility = 1.8 to ensure the right one is used. This works fine.


sourceCompatibility = 1.8



However, this seems to be ignored by the Javadoc task (./gradlew javadoc), which fails with an error (error: package sun.net.www.protocol.http is not visible) -- from this question I learned that this is an issue with a new feature in Java 9.


./gradlew javadoc


error: package sun.net.www.protocol.http is not visible



As of now, the project is aimed at Java 8 only. One day it will be upgraded to Java 9, but not today, so I just want to use the Java 8 javadoc generator instead of the Java 9 version.



I checked the task documentation but it doesn't look like there's any option to specify a JDK version. What can I do?



I'm expecting the solution to be a Gradle configuration, so it can be easily shared with the other devs on different machines.



Gradle version in which the behavior was seen (installed through IntelliJ):


------------------------------------------------------------
Gradle 4.4
------------------------------------------------------------

Build time: 2017-12-06 09:05:06 UTC
Revision: cf7821a6f79f8e2a598df21780e3ff7ce8db2b82

Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 10.0.1 (Oracle Corporation 10.0.1+10-Debian-4)
OS: Linux 4.16.0-2-amd64 amd64



Gradle version in which there was a warning instead of a failure of the Javadoc task (installed through Debian's repos):


------------------------------------------------------------
Gradle 3.4.1
------------------------------------------------------------

Build time: 2012-12-21 00:00:00 UTC
Revision: none

Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.10.3 compiled on June 13 2018
JVM: 10.0.1 (Oracle Corporation 10.0.1+10-Debian-4)
OS: Linux 4.16.0-2-amd64 amd64



Edit -- I have found this page that specifies that a "-source release" parameter that is probably the solution to this problem, however I cannot find the way it should be called:


javadoc {
options.addStringOption('-source', '8')
}



This compiles & runs with no warnings (in build.gradle), but doesn't change anything and doesn't appear in /build/tmp/javadoc/javadoc.options.


build.gradle


/build/tmp/javadoc/javadoc.options





In case it wasn't clear, tasks such as 'build' or 'test' work fine without errors on the JDK8 as expected. It's only the Javadoc task that fails.
– CLOVIS
Jul 2 at 12:18





Setting the source compatibility doesn't select a JDK. As you see in your output, you're using Java 10.0.1. Gradle uses the Java version that is in your PATH.
– JB Nizet
Jul 4 at 14:53






Both Java 8 & Java 10 are in my PATH. I want the javadoc doclet to run with Java 8 because some features (like the HTTP classes) were changed in Java 9
– CLOVIS
Jul 4 at 15:39





You shouldn't have two different versions of the JDK in your path. The first one will be picked anyway.
– JB Nizet
Jul 4 at 15:40





@JBNizet I can't change that now, I need both for different projects
– CLOVIS
Jul 5 at 11:59




1 Answer
1



I changed the version available in the path by doing:


export JAVA_HOME=/usr/lib/jvm/default-java






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Dw,9O1k8pF9 TXTkx M PUZkFA4MbOp Dl9wPQ2IP3E X,ZowNCdyN gFV,mlnZE3
ti3,ZxQLbT

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications