How to set the module path (project Jigsaw) for eclipse projects via gradle?


(Axel Howind) #1


so I have created my first gradle plugin to help build modularized Jars and standalone applications using the Java Platform Module System. It all works rather nicely together when I call gradle from the comand line. But when I import a project into Eclipse using the Buildship plugin, all dependencies end up on the classpath.

I want to find out how to manipulate the module path, i.e. remove all the dependencies from the classpath (that’s the easy part IMHO) and add them to the module path instead.

It works in gradle, but I have to open project properties and manipulate the build path manually each time I run “Refresh Gradle Project”.

Can someone point me in the right direction?


(Axel Howind) #2

Ok, solved.

(Sverre Moe) #3

Is setting this in the gradle eclipse configuration still the suggested workaround, to get this working with Eclipse?

Java modularization was released with Java 9 over a year ago. It should be more than enough time to get proper modularization support in Gradle.

This is the configuration I add to all my projects that is modularized:

eclipse {
    project {
        natures 'org.eclipse.buildship.core.gradleprojectnature'

    classpath {
        file {
            whenMerged {
                entries.findAll { isModule(it) }.each { //(1)
                    it.entryAttributes['module'] = 'true'

                entries.findAll { isSource(it) && isTestScope(it) }.each {
                    it.entryAttributes['test'] = 'true'

                entries.findAll { isLibrary(it) && isTestScope(it) }.each {
                    it.entryAttributes['test'] = 'true'

        defaultOutputDir = file('build')
        downloadSources = true
        downloadJavadoc = true

boolean isLibrary(entry) { return'lib') }
boolean isTestScope(entry) { return entry.entryAttributes.get('gradle_used_by_scope').equals('test'); }
boolean isModule(entry) { isLibrary(entry) && !isTestScope(entry); }
boolean isSource(entry) { return'src'); }