You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "jira-importer (via GitHub)" <gi...@apache.org> on 2025/02/01 20:31:58 UTC
[I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
jira-importer opened a new issue, #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265
**[Gili](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=cowwoc)** opened **[MJLINK-27](https://issues.apache.org/jira/browse/MJLINK-27?redirect=false)** and commented
Karl Heinz Marbaise closed MJLINK-7 referencing [a Stackoverflow post](https://stackoverflow.com/questions/46573572/java-9-possible-to-have-2-modules-with-same-name-on-module-path/46574200#46574200) to prove that module names must be unique. In fact, this Stackoverflow post says the exact opposite. The bottom half of the post states that modules in separate directories **are** allowed to have the same name. The bottom of the post concludes:
> That makes it possible to have the same module in different directories.
It doesn't have to be the same module per-se. It is possible for two different implementations with the same module name to reside on the module path, so long as the modules reside in different directory. This is useful for "class shadowing". In my particular case, I ship a no-op implementation of a module by default but users can insert a working implementation in front of the module path to enable the feature.
Please reopen this issue or continue its work here.
---
**Affects:** 3.0.0
**Attachments:**
- [module-shadowing.zip](https://issues.apache.org/jira/secure/attachment/12950777/module-shadowing.zip) (_16.42 kB_)
**Issue Links:**
- [MJLINK-28](https://issues.apache.org/jira/browse/MJLINK-28) Add WARNING in case of duplicate module names
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101470
**[Gili](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=cowwoc)** commented
[Robert Scholte](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=rfscholte) I'll see what I can do about that test project. In the meantime, take a look at https://github.com/apache/maven-plugins/blob/bfa65c310d7f16671db672773f73fd64f05edfd0/maven-jlink-plugin/src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java#L327
That code assumes that two modules won't share the same name, which we now know is incorrect. I would start by fixing that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101477
**[Gili](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=cowwoc)** commented
Note that I did not include the JLink plugin in this testcase, because I've never used it before. I would appreciate you updating the testcase to using the jlink-maven-plugin now that you understand the expected behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101468
**[Gili](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=cowwoc)** commented
I asked Alan Bateman for clarification and [he wrote](http://jigsaw-dev.1059479.n5.nabble.com/Clarification-needed-regarding-modulepath-containing-multiple-modules-with-the-same-name-tp5718248p5718251.html):
> if you've got say two directories on the module path and they
> both contain module M then M will be found in the first directory, the M
> in the second directory will be ignored.
>
> The linked comment about it being an error to have a directory on the
> module path containing multiple versions of the same module is also correct.
So this plugin's behavior is incorrect.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101483
**[Gili](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=cowwoc)** commented
Okay, I wasn't aware that this plugin is processing a list that was already processed by plexus-java to ensure that only the first entry exists per module name. That makes sense. You can go ahead and close this issue.
For anyone else running across this issue in the future, see https://github.com/codehaus-plexus/plexus-languages/blob/58e724cab3723a85dcf4bdbb2c121cb1a9a9773a/plexus-java/src/main/java/org/codehaus/plexus/languages/java/jpms/LocationManager.java#L230 for the plexus-java filtering process.
Thanks Robert!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101469
**[Robert Scholte](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=rfscholte)** commented
[Gili](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=cowwoc) Plexus-Java does some cleaning up of duplicate modules, picking the first one. Not sure if that's the real problem of this issue, so can you provide a testproject to make the discussion easier to continue?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101475
**[Gili](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=cowwoc)** commented
[Robert Scholte](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=rfscholte) Attached. I am expecting three things:
1. Consist ordering rules throughout all Maven plugins (e.g. compiler, jlink, etc): if the compiler will be passed modules in the same order mentioned by \<dependency> then I expect the first plugin to always win.
2. The same pom.xml file should always result in the same build/runtime behavior (deterministic behavior). If you guys are using HashMap or some other collection that does not guarantee order, we run the risk of getting a different modulepath ordering at every run.
3. Swapping the order of the dependencies should result in main() outputting "the other" plugin. So if you used to get "plugin1" as output, swapping dependencies should result in "plugin2" getting output.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101463
**[Karl Heinz Marbaise](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=khmarbaise)** commented
So based on what I've read in the http://openjdk.java.net/jeps/261 which is the following (quote from the JEP261):
> When searching a module path for a module of a particular name, the module system takes the first definition of a module of that name. Version strings, if present, are ignored; if an element of a module path contains definitions of multiple modules with the same name then resolution fails and the compiler, linker, or virtual machine will report an error and exit. It is the responsibility of build tools and container applications to configure module paths so as to avoid version conflicts; it is not a goal of the module system to address the version-selection problem.
I would like to emphasize the following:
> if an element of a module path contains definitions of multiple modules with the same name then resolution fails and the compiler, linker, or virtual machine will report an error and exit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101466
**[Gili](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=cowwoc)** commented
Karl,
http://openjdk.java.net/jeps/261 defines an element as a JAR file or a directory.
> When searching a module path for a module of a particular name, the module system takes the first definition of a module of that name
I want to emphasize this sentence. They wouldn't talk about using the first match if having multiple modules with the same name always failed.
> if an element of a module path contains definitions of multiple modules with the same name then resolution fails and the compiler, linker, or virtual machine will report an error and exit.
Let's break this down piece by piece.
* A JAR file cannot contain multiple files with the same path, hence it cannot contain multiple modules with the same name.
* The only element that may contain multiple modules with the same name is a directory.
* Hence, if a directory contains multiple modules with the same name then resolution will fail.
* If multiple JAR files contain a module with the same name, then the first match on the module path is used.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101481
**[Robert Scholte](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=rfscholte)** commented
> the actual output by maven-jlink-plugin is correct.
This is what I would expect.
> In spite of the aforementioned bug in getModulePathElements(), which still needs to be fixed.
The current result is by design. plexus-java has the option to divide path elements over the modulepath and classpath. It walks through the tree of all required modules, but this only works if it knows which modules are in the end selected by the JRE, hence it already picks the first module in case there are multiple with the same name.
All required information is available in the [ResolvePathsResult](https://codehaus-plexus.github.io/plexus-languages/plexus-java/apidocs/org/codehaus/plexus/languages/java/jpms/ResolvePathsResult.html). The lazy solution would be to simple put all `pathElements()` on the modulepath, but why?
If you want to include all modules with name X, you need to add a setter to the request ( e.g. setAllowDuplicateModules() ) and adjust the implementation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101479
**[Gili](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=cowwoc)** commented
I've updated the testcase to use maven-jlink-plugin.
In spite of the aforementioned bug in getModulePathElements(), which still needs to be fixed, the actual output by maven-jlink-plugin is correct. I can swap the dependency order and the first entry always shadows the second when I run "bin\java.exe -m com.company.main/com.company.main.Main" from the generated JAR file.
In its current form, getModulePathElements() will always be missing one of the "plugin" dependencies. Which one gets dropped is undefined. The expected behavior is for this method to return both the modules.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [MJLINK-27] Code incorrectly assumes that two modules won't have the same name [maven-jlink-plugin]
Posted by "jira-importer (via GitHub)" <gi...@apache.org>.
jira-importer commented on issue #265:
URL: https://github.com/apache/maven-jlink-plugin/issues/265#issuecomment-2629101474
**[Robert Scholte](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=rfscholte)** commented
I'll wait for the test before continuing the discussion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org