Javadoc task fails: Cannot find module org.apache.logging.log4j

Gradle cannot execute the javadoc task when the my project requires the module Log4j.
Running Gradle 4.8 with Java 10.

Log4j 2 is a Java module, but it doesn’t have the module-info.class at the package root. It is instead placed in META-INF/versions/9.

My module-info.java

module no.djviking.movies {

    requires javafx.controls;
    requires javafx.fxml;
    requires javafx.web;
    requires javafx.graphics;

    requires org.apache.logging.log4j;
}

Javadoc task fails:

> Task :javadoc FAILED
Task ':javadoc' is not up-to-date because:
  Task has failed previously.
Starting process 'command '/usr/java/jdk-10.0.1/bin/javadoc''. Working directory: /home/djviking/workspace/movies Command: /usr/java/jdk-10.0.1/bin/javadoc @/home/djviking/workspace/movies/build/tmp/javadoc/javadoc.options
Successfully started process 'command '/usr/java/jdk-10.0.1/bin/javadoc''
/home/djviking/workspace/movies/src/main/java/module-info.java:15: error: module not found: org.apache.logging.log4j
requires org.apache.logging.log4j;

Building gradle without Javadoc works fine.
Is there something I am missing from my javadoc task configuration?

My build.gradle:

final def log4jGroup = 'org.apache.logging.log4j'
final def log4jVersion = '2.11.0'

final def junitJupiterGroup = 'org.junit.jupiter'
final def junitJupiterVersion = '5.2.0'

final def junitPlatformGroup = 'org.junit.platform'
final def junitPlatformVersion = '1.2.0'
dependencies {
    compile group: 'org.controlsfx', name: 'controlsfx', version: '9.0.0'
    compile group: 'com.jfoenix', name: 'jfoenix', version: '9.0.4'
    compile group: 'org.jfxtras', name: 'jfxtras-controls', version: '9.0-r1'

    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
    compile group: 'com.lmax', name: 'disruptor', version:'3.3.7'

    testCompile group: junitJupiterGroup, name: 'junit-jupiter-api', version: junitJupiterVersion
    testRuntime group: junitJupiterGroup, name: 'junit-jupiter-engine', version: junitJupiterVersion

    testRuntimeOnly group: junitPlatformGroup, name: 'junit-platform-launcher', version: junitPlatformVersion
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives jar
    archives sourcesJar
    archives javadocJar
}

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

compileTestJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
            '--module-path', classpath.asPath,
            '--add-modules', 'org.junit.jupiter.api',
            '--add-reads', "$moduleName=org.junit.jupiter.api",
            '--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath,
        ]
        classpath = files()
    }
}

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

test {
    useJUnitPlatform()

    doFirst {
        jvmArgs = [
            '--module-path', classpath.asPath
        ]
    }

    reports {
        html.enabled = true
    }
}

This is annoying. Why javadoc fails when all others go through.

Is this a problem with the javadoc tool or a missing/wrong configuration in Gradle?

Maybe a similar problem which Eclipse have with multi-release JAR modules
https://bugs.eclipse.org/bugs/show_bug.cgi?id=536273
https://bugs.eclipse.org/bugs/show_bug.cgi?id=534624

But I would have thought both javac and javadoc shared similar logic how to find the modules. Considering compile works fine after adding log4j to the modulepath.

The problem looks to be javadoc tool

Exceuting the command as gradle does fails

djviking@machine:~/workspace/movies> /usr/java/jdk-10.0.1/bin/javadoc --class-path ‘’ --module-path ‘/home/djviking/workspace/movies/build/classes/java/main:/home/djviking/workspace/movies/build/resources/main:/home/djviking/.gradle/caches/modules-2/files-2.1/org.controlsfx/controlsfx/9.0.0/8e009b653a2a6eb3336016ad314c040e72395914/controlsfx-9.0.0.jar:/home/djviking/.gradle/caches/modules-2/files-2.1/com.jfoenix/jfoenix/9.0.4/b630dd9c840a8d4610a6f2f38706e21eddfebcd8/jfoenix-9.0.4.jar:/home/djviking/.gradle/caches/modules-2/files-2.1/org.jfxtras/jfxtras-controls/9.0-r1/125ff6b0e22dcd7c9471dd0d849a2f4254b2ad84/jfxtras-controls-9.0-r1.jar:/home/djviking/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.11.0/e6b751e02120c08702d98750f6a80bc25343b7f5/log4j-core-2.11.0.jar:/home/djviking/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.11.0/bede79a3f150711634a3047985517431bf6499f2/log4j-api-2.11.0.jar:/home/djviking/.gradle/caches/modules-2/files-2.1/com.lmax/disruptor/3.3.7/8549fdcbda5d64db98871e64a4cd0045611686d1/disruptor-3.3.7.jar:/home/djviking/.gradle/caches/modules-2/files-2.1/org.jfxtras/jfxtras-common/9.0-r1/db8dbe26d4a41643e46320a1ec9ac193efc59c64/jfxtras-common-9.0-r1.jar:/home/djviking/.gradle/caches/modules-2/files-2.1/org.jfxtras/jfxtras-fxml/9.0-r1/dfd376482bee9a70532f35f97881a8d7785e1e02/jfxtras-fxml-9.0-r1.jar’ -d ‘/home/djviking/workspace/movies/build/docs/javadoc’ -doctitle ‘movies 1.0-SNAPSHOT-SNAPSHOT API’ -html5 -verbose -windowtitle ‘movies 1.0-SNAPSHOT-SNAPSHOT API’ ‘/home/djviking/workspace/movies/src/main/java/no/smeaworks/movies/MoviesController.java’ ‘/home/djviking/workspace/movies/src/main/java/no/smeaworks/movies/MoviesApplication.java’ ‘/home/djviking/workspace/movies/src/main/java/module-info.java’
Loading source file /home/djviking/workspace/movies/src/main/java/no/smeaworks/movies/MoviesController.java…
[parsing started SimpleFileObject[/home/djviking/workspace/movies/src/main/java/no/smeaworks/movies/MoviesController.java]]
[parsing completed 11ms]
Loading source file /home/djviking/workspace/movies/src/main/java/no/smeaworks/movies/MoviesApplication.java…
[parsing started SimpleFileObject[/home/djviking/workspace/movies/src/main/java/no/smeaworks/movies/MoviesApplication.java]]
[parsing completed 3ms]
Loading source file /home/djviking/workspace/movies/src/main/java/module-info.java…
/home/djviking/workspace/movies/src/main/java/module-info.java:18: error: module not found: org.apache.logging.log4j
requires org.apache.logging.log4j;
^
[parsing started SimpleFileObject[/home/djviking/workspace/movies/src/main/java/module-info.java]]
[parsing completed 1ms]
[loading /modules/javafx.controls/module-info.class]
[loading /modules/javafx.graphics/module-info.class]
[loading /modules/javafx.base/module-info.class]
[loading /modules/java.desktop/module-info.class]
[loading /modules/java.xml/module-info.class]
[loading /modules/java.base/module-info.class]
[loading /modules/java.datatransfer/module-info.class]
[loading /modules/java.prefs/module-info.class]
[loading /modules/javafx.fxml/module-info.class]
[loading /modules/java.scripting/module-info.class]
[loading /modules/java.logging/module-info.class]
[loading /modules/javafx.web/module-info.class]
[loading /modules/jdk.jsobject/module-info.class]
[loading /modules/jdk.xml.dom/module-info.class]
[loading /modules/javafx.media/module-info.class]
[loading /home/djviking/.gradle/caches/modules-2/files-2.1/org.jfxtras/jfxtras-controls/9.0-r1/125ff6b0e22dcd7c9471dd0d849a2f4254b2ad84/jfxtras-controls-9.0-r1.jar(/module-info.class)]
[loading /home/djviking/.gradle/caches/modules-2/files-2.1/org.jfxtras/jfxtras-common/9.0-r1/db8dbe26d4a41643e46320a1ec9ac193efc59c64/jfxtras-common-9.0-r1.jar(/module-info.class)]
[loading /home/djviking/.gradle/caches/modules-2/files-2.1/org.jfxtras/jfxtras-fxml/9.0-r1/dfd376482bee9a70532f35f97881a8d7785e1e02/jfxtras-fxml-9.0-r1.jar(/module-info.class)]
[loading /home/djviking/.gradle/caches/modules-2/files-2.1/com.jfoenix/jfoenix/9.0.4/b630dd9c840a8d4610a6f2f38706e21eddfebcd8/jfoenix-9.0.4.jar(/module-info.class)]
[loading /modules/jdk.unsupported/module-info.class]
[done in 322 ms]
1 error

I am getting the same problem with the latest Gradle 4.10-RC1.

Anyone have a solution to this Log4j with building a Java module?

The source for my application is at GitHub

Found there is a bug report on this problem
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8208269

Will just have to wait until it is fixed. I really hope soon.
If it is not fixed before JDK 11 is out, considering it is the first LTS with Java 9 modules, then in order to use Log4j with a java module the log4j must also be a proper module and not a multi-jar.

I found a solution. Not sure if it is a hack, workaround or a real solution

Excluding the module-info.java seem work.

javadoc {
    inputs.property("moduleName", moduleName)
    doFirst {
        exclude "**/module-info.java"
        options.addStringOption('-module-path', classpath.asPath)
        options.addStringOption('-class-path', "")
        options.addBooleanOption('html5', true)
        options.addBooleanOption('verbose', true)
    }
}

I could also remove the options for -module-path and -class-path without any problem.

The solution came to me after reading the TestFX gradle configuration.
https://github.com/TestFX/TestFX/blob/cf9eafe7a0bb16ffc42c06666a987a35b1f043b3/subprojects/testfx-junit5/testfx-junit5.gradle

Edit: However the Javadoc generated has no information about my module.
So I would say, it is a workaround in the meantime to get building work, but Javadoc is “broken” since it does not contain information about modules, yet.