# Gradle doesn't add modules to module-path during compile

**URL:** <https://discuss.gradle.org/t/gradle-doesnt-add-modules-to-module-path-during-compile/27382>\
**Category:** Help/Discuss\
**Created:** [June 16, 2018, 10:08pm UTC](https://discuss.gradle.org/t/gradle-doesnt-add-modules-to-module-path-during-compile/27382 "2018-06-16T22:08:46Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![DJViking](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@DJViking](https://discuss.gradle.org/u/DJViking)\
**Post date:** [September 20, 2018, 7:41pm UTC](https://discuss.gradle.org/t/gradle-doesnt-add-modules-to-module-path-during-compile/27382/2 "2018-09-20T19:41:03Z")

</div>

Java Module Madness is here now that JavaFX 11 has been released.  
I have started using it as dependencies.

Already before JavaFX 11 I had to set  
‘–module-path’, classpath.asPath  
for compileJava, compileTestJava, javadoc and test.

I didn’t however need to do it for application plugin run task. Until now.  
With the JavaFX modules I have now also needed to --add-module for each.

This Gradle configuration has grown. In this regard it no longer has an advantage over Maven, which doesn’t need to set all these flags.

I really hope Gradle is working on making Java 9 module support better, and without all this boilerplate configuration.

```
compileJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
            '--module-path', classpath.asPath,
            '--add-modules', 'javafx.controls',
            '--add-modules', 'javafx.fxml',
            '--add-modules', 'javafx.web',
            '--add-modules', 'javafx.graphics',
            '--add-modules', 'javafx.media'
        ]
        classpath = files()
    }
}

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

run {
    doFirst {
        jvmArgs = [
                '--module-path', classpath.asPath,
                '--add-modules', 'javafx.controls',
                '--add-modules', 'javafx.fxml',
                '--add-modules', 'javafx.web',
                '--add-modules', 'javafx.graphics',
                '--add-modules', 'javafx.media'
        ]
    }
}

javadoc {
    inputs.property("moduleName", moduleName)
    doFirst {
        exclude "**/module-info.java"
        options.addStringOption('-module-path', classpath.asPath)
        options.addStringOption('-add-modules', 'javafx.controls')
        options.addStringOption('-add-modules', 'javafx.fxml')
        options.addStringOption('-add-modules', 'javafx.web')
        options.addStringOption('-add-modules', 'javafx.graphics')
        options.addStringOption('-add-modules', 'javafx.media')
        options.addStringOption('-class-path', "")
        options.addBooleanOption('html5', true)
        options.addBooleanOption('verbose', true)
    }
}

test {
    useJUnitPlatform()

    doFirst {
        jvmArgs = [
            '--module-path', classpath.asPath,
            '--add-modules', 'javafx.controls',
            '--add-modules', 'javafx.fxml',
            '--add-modules', 'javafx.web',
            '--add-modules', 'javafx.graphics',
            '--add-modules', 'javafx.media'
        ]
    }
}
```

---

_[View the full topic](https://discuss.gradle.org/t/gradle-doesnt-add-modules-to-module-path-during-compile/27382)._
