Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 540274 - m2e doesn't put multi-release jar files on the module path
Summary: m2e doesn't put multi-release jar files on the module path
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: m2e (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Fred Bricon CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-18 14:45 EDT by Alex Foster CLA
Modified: 2021-04-19 13:22 EDT (History)
2 users (show)

See Also:


Attachments
maven projects for testing (9.51 KB, application/zip)
2018-10-21 14:50 EDT, Till Brychcy CLA
no flags Details
maven projects for testing with module names that differ from project names (8.80 KB, application/zip)
2018-10-21 15:17 EDT, Till Brychcy CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Foster CLA 2018-10-18 14:45:51 EDT
In my run configurations Maven Dependencies are under Classpath Entries on the Dependencies tab and I cant see any way to move them to Modulepath Entries. This causes an error when I try to run my project: 

Error occurred during initialization of boot layer
java.lang.module.FindException: Module org.apache.logging.log4j not found, required by server

If I take the command line it gives me from the "Show Command Line" button and edit it to move all of the classpath arguments to the modulepath (and remove the javaw.exe part) and put that in the VM arguments section and remove all dependencies from the Dependencies tab then it runs without an error.
Comment 1 Till Brychcy CLA 2018-10-18 15:17:11 EDT
(you may have to right-click on the project and choose "Maven > Update Project").

The Maven Dependencies container is shown on the classpath, but its contents are actually put on the module path by m2e, if they are mentioned in the module-info.java.
Other dependencies are put on the class path. 

Note that test-only dependencies (like junit), which can not be referenced in the module-info.java, are this way kept on the class path, but test code is automatically configured to read the unnamed module, so this should work.
Comment 2 Alex Foster CLA 2018-10-18 15:49:01 EDT
(In reply to Till Brychcy from comment #1)
> (you may have to right-click on the project and choose "Maven > Update
> Project").

I tried "Maven > Update Project" and now the line "requires org.apache.logging.log4j;" in my module-info.java shows an error "org.apache.logging.log4j cannot be resolved to a module". Also Maven Dependencies in my build path is now under the Classpath section, I think it was under Modulepath before. There are also errors where I try to import and use log4j.
Comment 3 Till Brychcy CLA 2018-10-18 16:00:15 EDT
As I wrote, the location of the maven dependencies container doesn't matter, the invidual entries contained in it should have the "is modular" attribute set if they are in the module-info.java

But if I remember correctly, org.apache.logging.log4j is a multi-release jar file (and has the module-info.class in the META-INF/...) folder, there may still be an issue with this
Comment 4 Alex Foster CLA 2018-10-18 16:11:46 EDT
Yes, log4j's module-info.class is in META_INF/versions/9, and log4j-api-2.11.1.jar under Maven Dependencies in the build path has a field "is not modular - non modifiable".
Comment 5 Alex Foster CLA 2018-10-18 16:14:43 EDT
Eclipse shows log4j's module-info.class as being next to the META_INF folder though, not inside it as it actually is in the jar.
Comment 6 Till Brychcy CLA 2018-10-18 16:17:12 EDT
(In reply to Alex Foster from comment #5)
> Eclipse shows log4j's module-info.class as being next to the META_INF folder
> though, not inside it as it actually is in the jar.

This ist just Eclipse's view which shows that it actually handles this correctly. But m2e needs to set the module attribute, which it doesn't.
Comment 7 Till Brychcy CLA 2018-10-18 16:19:47 EDT
I can reproduce the problem with this pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>test</groupId>
	<artifactId>test</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.7.0</version>
				<configuration>
					<source>9</source>
					<target>9</target>
					<showWarnings>true</showWarnings>
					<showDeprecation>true</showDeprecation>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-api</artifactId>
			<version>2.11.1</version>
		</dependency>
	</dependencies>
</project>

and this src/main/java/module-info.java:
module test {
	requires org.apache.logging.log4j;
}

(actually completion of the module name works)
Comment 8 Till Brychcy CLA 2018-10-18 16:34:17 EDT
org.eclipse.m2e.jdt.internal.InternalModuleSupport.getModuleName(File) doesn't support multi-release jar files.
Comment 9 Eclipse Genie CLA 2018-10-19 02:51:36 EDT
New Gerrit change created: https://git.eclipse.org/r/131170
Comment 10 Alex Foster CLA 2018-10-19 06:22:41 EDT Comment hidden (obsolete)
Comment 11 Till Brychcy CLA 2018-10-19 06:59:20 EDT Comment hidden (obsolete)
Comment 12 Alex Foster CLA 2018-10-19 08:19:03 EDT Comment hidden (obsolete)
Comment 13 Till Brychcy CLA 2018-10-21 09:00:10 EDT
org.eclipse.m2e.jdt.internal.InternalModuleSupport.getRequiredModules(File) needs the same change.
Comment 14 Till Brychcy CLA 2018-10-21 14:50:19 EDT Comment hidden (obsolete)
Comment 15 Till Brychcy CLA 2018-10-21 14:54:27 EDT Comment hidden (obsolete)
Comment 16 Till Brychcy CLA 2018-10-21 15:17:45 EDT
Created attachment 276337 [details]
maven projects for testing with module names that differ from project names
Comment 17 Till Brychcy CLA 2018-10-21 15:21:34 EDT
I've attached some projects for manual testing (I haven't found any java-9 related infrastructure in the m2e-core-tests project on github).

baseA and baseB are two simple modular projects consisting just of module-info.class where baseA declares mod_baseA and baseB declares mod_baseB.

multi is a project that creates a multi-release jar just with module-info, where the module name in version 9 is multiA and requires mod_baseA; and in version 10 the module name is multiB and it requires mod_baseB

To test, do "mvn install" for baseA, baseB and multi using the command line (and java >=10). Do not import these into eclipse (at least not multi, or disable workspace resolution for the projects that need it)

Then import test9 and test10 as maven project into eclipse.

Both projects should compile without errors (but note: module-info in test9 requires multiA and the one in test10 requireds multiB)

Verify that baseA is shown as modular in the "Maven Dependencies" Container of test9 and baseB is not modular
Verify that baseA is shown as not modular in the "Maven Dependencies" Container of test10 and baseB is shown as modular
Comment 19 Fred Bricon CLA 2018-11-24 15:30:01 EST
Thanks for the patch Till, it works as advertised. 
Merged as http://git.eclipse.org/c/m2e/m2e-core.git/commit/?id=090aeb23dae6ab331d8fffb158b563bc88c19d51

As for missing Java 9+ tests, we definitely need to set it up. I know how to do it (register fake rtstubs.jars as test JREs, like in JDT/JDT.LS tests), but don't have the bandwidth to do it right now
Comment 20 Denis Roy CLA 2021-04-19 13:22:33 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/