Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to to tell Eclipse/Buildship/Gradle to add dependencies to the Modulepath

I am trying to use Eclipse, Buildship, Gradle to develop java 9 applications.

Eclipse: Oxygen Buildship: 2.2.0 Gradle: 4.3.1

I am looking for a way to tell Buildship/Gradle to add Project and External Dependencies to the Modulepath rather than the Classpath.

Here's a representation of what I see when I configure my Eclipse project Java Build Path.

Properties for TestMain

Java Build path

Source   |   Projects   |   Libraries   |   Order and Export
                        ---------
Modulepath
   - JRE System Library [JavaSe-9]

Classpath                            
   - Project and External Dependencies
      - Access rules: No rules defined
      - External annotations: (None)
      - Native library location: (None)
         - coreutil-9.4.1.jar
         - slf4j-api-1.7.2.1.jar
         - ...

When I try to reference the automatic module coreutil in module-info.java I get the error coreutil cannot be resolved to a module.

If I manually add coreutil-9.4.1.jar to the Modulepath then the coreutil module becomes visible. This is a problem, however, since it is impractical to manually add over 60 libraries in some cases. Moreover, each time I Refresh Gradle Project they are all removed from the Modulepath.

Thanks for help.

Gaëtan

like image 268
Gaëtan Sheridan Avatar asked Oct 28 '25 03:10

Gaëtan Sheridan


1 Answers

After talking to Donát Csikós at gradle (thanks Donát) adding the following to the build.gradle file solves the problem:

apply plugin: 'eclipse'

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

boolean isModule(entry) {
    // filter java 9 modules
    entry.kind == 'lib'  // Only libraries can be modules
}
like image 98
Gaëtan Sheridan Avatar answered Oct 31 '25 07:10

Gaëtan Sheridan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!