Make "gradle javadoc" task work with Java 9
Asked Answered
R

2

3

I have a multi-module Gradle Java project using source/target = 1.9/1.9. There are two modules, my.base and my.dependsOnBase. The my.base module has no other dependencies:

module my.base {
    exports my.base.foo;
    exports my.base.bar;
}

The my.dependsOnBase module has only a single dependency, which is my.base:

module my.dependsOnBase {
    requires my.base;
    exports my.dependsOnBase.baz;
}

When I run $ gradle javadoc it works fine on my.base. But when it gets to my.dependsOnBase I get the following error output:

/path/to/my $ gradle javadoc

> Task :dependsOnBase:javadoc FAILED
/path/to/my/dependsOnBase/src/main/java/module-info.java:26: error: module not found: my.base
    requires my.base;
                     ^
1 error


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':dependsOnBase:javadoc'.
> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '/path/to/my/dependsOnBase/build/tmp/javadoc/javadoc.options'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
7 actionable tasks: 3 executed, 4 up-to-date

Earlier in the project I was able to get Java compilation, which suffered a similar problem, working using:

compileJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
                '--module-path', classpath.asPath,
        ]
        classpath = files()
    }
}

But those properties aren't directly applicable to the Gradle javadoc task.

How can I get my Javadoc working?

Rahmann answered 19/12, 2017 at 16:51 Comment(3)
Could you update the javadoc task details used in the question? Also, did you try ensuring the my.base module exists in the module path while executing that task as well?Jarl
@nullpointer, I didn't try it yet because I don't know Gradle well and I can't understand how to set the javadoc task modulepath within Gradle (blind copy/paste of the compileJava block definitely didn't work). I don't have an explicit javadoc task within my build.gradle - I'm just using whatever the java plugin already provides.Rahmann
This is a bug in Gradle's JavaDoc task... even using the new 'org.gradle.java.experimental-jigsaw' plugin, this problem is still happening as of Gradle 4.5.1. But the answer by @Thor Andreas Rognan did work for me!Milord
C
6

This worked for me

javadoc {
  inputs.property("moduleName", moduleName)
  doFirst {
    options.addStringOption('-module-path', classpath.asPath)
  }
}
Concision answered 6/2, 2018 at 21:33 Comment(1)
I'm still having this issue as of Gradle 4.6, but Thor Andreas Rognan's answer solves the problem for me in the meantime. Thank you Thor!Rahmann
A
2

I tried this on Gradle 7.1 and couldn't get it working, but after a little tinkering found adding this snippet made things work:

tasks.withType(Javadoc) {
    doFirst {
        options.modulePath = [] + classpath.files
        options.classpath = []
    }
}

The [] + ... seems to be a necessary workaround to make a list from the org.gradle.api.internal.file.UnionFileCollection returned by Gradle. Alternatively you could use new ArrayList(classpath.files) to achieve the same.

Adherent answered 29/6, 2021 at 16:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.