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?

0xbe5077ed
  • 4,565
  • 6
  • 35
  • 77
  • 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? – Naman Dec 19 '17 at 17:02
  • @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. – 0xbe5077ed Dec 19 '17 at 17:24
  • 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! – Renato Mar 11 '18 at 15:59

2 Answers2

6

This worked for me

javadoc {
  inputs.property("moduleName", moduleName)
  doFirst {
    options.addStringOption('-module-path', classpath.asPath)
  }
}
  • 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! – 0xbe5077ed Apr 08 '18 at 03:07
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.

stan
  • 95
  • 1
  • 9