Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M2E wrongly uses enforcer requireJavaVersion to configure projects #1099

Closed
Bananeweizen opened this issue Nov 29, 2022 · 6 comments · Fixed by #1137
Closed

M2E wrongly uses enforcer requireJavaVersion to configure projects #1099

Bananeweizen opened this issue Nov 29, 2022 · 6 comments · Fixed by #1137

Comments

@Bananeweizen
Copy link
Contributor

Since eclipse-tycho/tycho#1740 all the classpaths in Tycho use Java 17 on my machine. That's clearly wrong, at least these 2 projects had other settings before (and they use specific other source/target values in their POMs):
grafik

I have Java 8, 11, 17 in my workspace preferences and I have all necessary EE levels mapped in the workspace preferences.

@HannesWell
Copy link
Contributor

HannesWell commented Nov 30, 2022

This is a bit strange. IIRC the StandardVMType/-classpath entries for those projects were the same when I tested it.
But now it is java-17 for me as well.

I hope this isn't another regression from #981.
Will look into this in the next days.

The relevant class is probably AbstractJavaProjectConfigurator:

String executionEnvironmentId = getExecutionEnvironmentId(options);
String buildEnvironmentId = getMinimumJavaBuildEnvironmentId(request, monitor);
addJREClasspathContainer(classpath, buildEnvironmentId != null ? buildEnvironmentId : executionEnvironmentId);

@HannesWell
Copy link
Contributor

While analyzing the problem I noticed that Tycho in general and therefore the projects you mentioned have a maven-enforcer-plugin execution with a requireJavaVersion rule configured:

https://github.com/eclipse-tycho/tycho/blob/3098bd215d5be0b8b00cd3e87bc35f4d1463d5be/pom.xml#L446-L448

Since in the properties section <min.jdk.version>17</min.jdk.version> is configured the build has to be performed with Java-17 and therefore I think M2E does everything right when it sets the JRE_CONTAINER to Java-17.
Please add your remarks to #842 (comment), if you think this is a false assumption.

@Bananeweizen
Copy link
Contributor Author

Bananeweizen commented Dec 4, 2022

To my understanding the requireJavaVersion rule is meant to clarify the version of the JVM that Maven itself runs on. It does not say anything about the source, target or other compiler/testing/runtime related Java levels of the modules being worked on.
See https://github.com/apache/maven-enforcer/blob/master/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVersion.java
Since Maven maps the compiler source/target level for each module via toolchains and then uses the matching JRE, m2e should not set any other level. Not in the prefs and not in the classpath. It will work (if at least the prefs are at the right level), but it's absolutely not recommended to have a wrong JRE version on the classpath. That's why the warning from JDT is shown in the first place. Also it's not even necessary that m2e tries to be more clever than JDT there. If m2e finds a compiler source setting of 13 in the POM, and I don't have any JRE matching 13, then it should still set the prefs and classpath to 13. In Eclipse I will later select another installed JRE (like 17) to be mapped in the Java > Execution Environments preferences, and everything will be fine.

@Bananeweizen Bananeweizen changed the title wrong java versions added to classpath M2E wrongly uses enforcer requireJavaVersion to configure projects Dec 4, 2022
@kwin
Copy link
Member

kwin commented Dec 9, 2022

It does not say anything about the source, target or other compiler/testing/runtime related Java levels of the modules being worked on.

Neither does the underlying JRE Library do that, that is configured separately in the Eclipse JDT Compiler settings.

The reason why m-e-p configuration is evaluated is that the project's JRE Library is also used for running Maven from Eclipse by default (

private IPath getJREContainerPath(IContainer basedir) throws CoreException {
and
workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, path.toPortableString());
) and would therefore fail if any of the Maven plugins require a newer JRE.

I agree that on the long term it would be good if m2e would establish a separate configuration for the JVM used to run Maven (but currently this is the project's JRE system library).

kwin added a commit to kwin/m2e-core that referenced this issue Dec 12, 2022
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099
kwin added a commit to kwin/m2e-core that referenced this issue Dec 21, 2022
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099
kwin added a commit to kwin/m2e-core that referenced this issue Dec 21, 2022
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099
kwin added a commit to kwin/m2e-core that referenced this issue Dec 21, 2022
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099
kwin added a commit to kwin/m2e-core that referenced this issue Dec 21, 2022
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099
kwin added a commit to kwin/m2e-core that referenced this issue Dec 21, 2022
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099
HannesWell pushed a commit to HannesWell/m2e-core that referenced this issue Jan 11, 2023
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099
@reckart
Copy link

reckart commented Jan 23, 2023

I'm using Maven with:

  • the toolchains plugin and compiler source/target properties to ensure compatibility with Java 1.8
  • the enforcer plugin to ensure that the Maven process runs at least on Java 11 because I use the maven-bnd-plugin which requires Java 11

The annoying thing is that since m2e now looks at the enforcer plugin instead of the compiler target means that in Eclipse, stuff is compiled against Java 11 and not against Java 8 as the toolchains/compiler properties indicate.

Please, it would be great if you could switch back to the old behavior.

HannesWell added a commit to kwin/m2e-core that referenced this issue Feb 27, 2023
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099

Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
HannesWell added a commit to kwin/m2e-core that referenced this issue Feb 27, 2023
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099

Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
HannesWell added a commit to kwin/m2e-core that referenced this issue Feb 27, 2023
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099

Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
HannesWell added a commit to kwin/m2e-core that referenced this issue Feb 28, 2023
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099

Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
HannesWell added a commit to kwin/m2e-core that referenced this issue Feb 28, 2023
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099

Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
HannesWell added a commit to kwin/m2e-core that referenced this issue Feb 28, 2023
The value is automatically derived from maven-enforcer rule requireJava

This closes eclipse-m2e#1134
This closes eclipse-m2e#1099

Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
HannesWell added a commit to kwin/m2e-core that referenced this issue Feb 28, 2023
The value is automatically derived from maven-enforcer rule requireJava

Closes eclipse-m2e#1134
Closes eclipse-m2e#1099
Closes eclipse-m2e#1120

Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
@HannesWell HannesWell linked a pull request Feb 28, 2023 that will close this issue
HannesWell added a commit to kwin/m2e-core that referenced this issue Feb 28, 2023
The value is automatically derived from maven-enforcer rule requireJava

Closes eclipse-m2e#1134
Closes eclipse-m2e#1099
Closes eclipse-m2e#1120

Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
@HannesWell
Copy link
Contributor

Please try the latest m2e release to verify that the issue is fixed as expected:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants