Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » error in running gradle based project with java9+ modules
error in running gradle based project with java9+ modules [message #1823524] Sat, 28 March 2020 07:55 Go to next message
hossein mahdavipour is currently offline hossein mahdavipourFriend
Messages: 9
Registered: December 2017
Junior Member
I started a new gradle project with eclipse and with as simple as possible build.gradle. just added this:
Quote:

compile 'org.apache.commons:commons-math3:3.6.1'

then in module-info.java I added :
Quote:

requires commons.math3;

I got an error with a quickfix to take classpath entries to module path. after applying quick fix I added a simple main and tried to run with eclipse but I get this error:
Quote:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module commons.math3 not found, required by mymodule

I went to run configuration and this is the command eclipse excutes:
Quote:

/usr/lib/jvm/jdk-13.0.1/bin/java -Dfile.encoding=UTF-8 -p /home/hosseinmp76/Documents/eclipse-workspace/mymodule/bin/main -classpath /home/hosseinmp76/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-math3/3.6.1/e4ba98f1d4b3c80ec46392f25e094a6a2e58fcbf/commons-math3-3.6.1.jar -m mymodule/mymodule.Library

And in addition I can run the main with gradle with no problem.
What should I do?
I use eclipse 2020-03 and gradle 6+.
Re: error in running gradle based project with java9+ modules [message #1823531 is a reply to message #1823524] Sat, 28 March 2020 12:14 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
The command line shows that commons-math3 is still on the classpath, not on the module path. What do you see in the project properties at Java > Java Build Path? (You can tell us by showing the contents of file .classpath).

JDT doesn't natively know about any build system like gradle or maven. Are you using buildship to integrate gradle in Eclipse? Maybe buildship has its own configuration option where you decide what's on the classpath vs. modulepath?
Re: error in running gradle based project with java9+ modules [message #1823534 is a reply to message #1823531] Sat, 28 March 2020 13:33 Go to previous messageGo to next message
hossein mahdavipour is currently offline hossein mahdavipourFriend
Messages: 9
Registered: December 2017
Junior Member
Quote:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/resources">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-13/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin/default"/>
</classpath>


http://bayanbox.ir/download/1489235639694527480/eclipse2.png
Re: error in running gradle based project with java9+ modules [message #1823535 is a reply to message #1823534] Sat, 28 March 2020 13:48 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
OK, the entry "Project and External Dependencies" seems to correspond to this:
 <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
    <attributes>
        <attribute name="module" value="true"/>
    </attributes>
</classpathentry>


From a JDT perspective this looks OK, and should put the jar on the modulepath. Details of this entry are the responsibility of org.eclipse.buildship, indeed. There's a theoretical possibility that resolving the contents of this entry drops the "Is modular" property (.classpath: <attribute name="module" value="true"/>). When you open the node for commons-math3...jar, does it again say "Is modular"? From the execution command line it seems, it is marked as not modular.

If "Is modular" is correctly set, then next location to check would be your run configuration (which you can save to a file by selecting "Common > Shared file" in the run configuration dialog).
Re: error in running gradle based project with java9+ modules [message #1823539 is a reply to message #1823535] Sat, 28 March 2020 15:23 Go to previous messageGo to next message
hossein mahdavipour is currently offline hossein mahdavipourFriend
Messages: 9
Registered: December 2017
Junior Member
how to check "Is modular"? in the project properties in java build path(as the picture i showed earlier) if I expand the jar node it is written: Is modular - not modifiable.
the "commons-math3...jar" is not a modular jar it should be added as an automatic module.
and the run config:
Quote:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<stringAttribute key="bad_container_name" value="/mymodule/qq.txt"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/mymodule/src/main/java/mymodule/Library.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_EXCLUDE_TEST_CODE" value="true"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="mymodule.Library"/>
<listAttribute key="org.eclipse.jdt.launching.MODULEPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
&lt;runtimeClasspathEntry path=&quot;4&quot; projectName=&quot;mymodule&quot; type=&quot;1&quot;/&gt;
"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-13/&quot; path=&quot;4&quot; type=&quot;4&quot;/&gt;
"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.buildship.core.gradleclasspathcontainer&quot; javaProject=&quot;mymodule&quot; path=&quot;4&quot; type=&quot;4&quot;/&gt;
"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="mymodule"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="mymodule"/>
</launchConfiguration>


and thank you for your help. I have struggling on this for about two weeks.

[Updated on: Sat, 28 March 2020 15:26]

Report message to a moderator

Re: error in running gradle based project with java9+ modules [message #1823540 is a reply to message #1823539] Sat, 28 March 2020 15:35 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
Quote:
how to check "Is modular"?

Look at your screenshot: just above commons-math3 there's a node "Is modular". Expand the node representing the jar file, and check if it contains another "Is modular" node, or the opposite: "Is not modular"

Quote:
the "commons-math3...jar" is not a modular jar it should be added as an automatic module.

Understood. "Is modular" describes how Eclipse should see the jar, it doesn't look into the jar.

Quote:
and the run config:

This looks OK, also here "org.eclipse.buildship.core.gradleclasspathcontainer" is on the module path. But still buildship is in the loop for populating this container with specific jars. That's why we need to figure out, whether buildship internally marks individual resolved jars as "module=false". I hope we can check this by looking for the nested "Is modular" or "Is not modular".

As an aside I wonder, if JDT should raise an error if a classpath container on the module path resolves to entries that claim "module=false".
Re: error in running gradle based project with java9+ modules [message #1823541 is a reply to message #1823540] Sat, 28 March 2020 15:43 Go to previous messageGo to next message
hossein mahdavipour is currently offline hossein mahdavipourFriend
Messages: 9
Registered: December 2017
Junior Member
sorry I didn't get what should I do now.
Re: error in running gradle based project with java9+ modules [message #1823542 is a reply to message #1823541] Sat, 28 March 2020 15:46 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
Quote:
sorry I didn't get what should I do now.


... and I have no idea, what exactly is unclear :)

Repeating my suggestion: Look at your screenshot: just above commons-math3 there's a node "Is modular". Expand the node representing the jar file, and check if it contains another "Is modular" node, or the opposite: "Is not modular"
Re: error in running gradle based project with java9+ modules [message #1823543 is a reply to message #1823542] Sat, 28 March 2020 15:48 Go to previous messageGo to next message
hossein mahdavipour is currently offline hossein mahdavipourFriend
Messages: 9
Registered: December 2017
Junior Member
it is is not modular
Re: error in running gradle based project with java9+ modules [message #1823545 is a reply to message #1823543] Sat, 28 March 2020 15:54 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
Quote:
it is is not modular


OK, that would be done by buildship. Thus the best place to ask would be: https://discuss.gradle.org/c/help-discuss/buildship
Re: error in running gradle based project with java9+ modules [message #1823547 is a reply to message #1823545] Sat, 28 March 2020 15:55 Go to previous messageGo to next message
hossein mahdavipour is currently offline hossein mahdavipourFriend
Messages: 9
Registered: December 2017
Junior Member
but the jar is really not modular. why should I say "is modular"?
Re: error in running gradle based project with java9+ modules [message #1823548 is a reply to message #1823547] Sat, 28 March 2020 15:58 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1828
Registered: July 2009
Senior Member
Quote:
but the jar is really not modular. why should I say "is modular"?


As I mentioned above, "Is modular" does not describe what's inside the jar, it describes how Eclipse / JDT should see the jar. If it says "not modular" Eclipse will put it on the classpath. And thanks to the concept of automatic modules, it can be seen as a module. That's what counts.

And not *you* should say so, *buildship* should. I am not an expert regarding buildship, so please ask in their forum.
Re: error in running gradle based project with java9+ modules [message #1823550 is a reply to message #1823548] Sat, 28 March 2020 16:01 Go to previous messageGo to next message
hossein mahdavipour is currently offline hossein mahdavipourFriend
Messages: 9
Registered: December 2017
Junior Member
Thank you very much for your great help.
Re: error in running gradle based project with java9+ modules [message #1823569 is a reply to message #1823550] Sun, 29 March 2020 08:54 Go to previous message
hossein mahdavipour is currently offline hossein mahdavipourFriend
Messages: 9
Registered: December 2017
Junior Member
I change the gradle settings and now the jars in java build path are "Is modular" but still I get the same error.
what I added to build.gradle:
Quote:

eclipse {
classpath {
file {
whenMerged {
entries.findAll { it.properties.kind.equals('lib') }.each {
it.entryAttributes['module'] = 'true'
}
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'
}
}
}
}
}


http://bayanbox.ir/download/1462543972289983392/eclipse2-1.png

[Updated on: Sun, 29 March 2020 08:54]

Report message to a moderator

Previous Topic:Please take java.util.Objects methods into account for potential NullPointer checks
Next Topic:Internal compiler error: java.lang.NullPointerException
Goto Forum:
  


Current Time: Mon Oct 26 11:11:18 GMT 2020

Powered by FUDForum. Page generated in 0.02738 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top