0xbe5077ed
0xbe5077ed

Reputation: 4755

Make "gradle javadoc" task work with Java 9

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?

Upvotes: 3

Views: 1462

Answers (2)

stan
stan

Reputation: 95

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.

Upvotes: 2

Thor Rognan
Thor Rognan

Reputation: 124

This worked for me

javadoc {
  inputs.property("moduleName", moduleName)
  doFirst {
    options.addStringOption('-module-path', classpath.asPath)
  }
}

Upvotes: 6

Related Questions