Closed philipp-lenz closed 9 months ago
May relate with https://github.com/eclipse-m2e/m2e-core/issues/1120
I have a similar problem with the jaxws-maven-plugin:2.6: the toolchain is not honored and the plugin is run using Java 17. After investigating, this method https://github.com/mojohaus/jaxws-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/jaxws/AbstractJaxwsMojo.java#L380 returns nulls when run from Eclipse and return the Java 8 location when run from Maven.
It is as if m2e was not reading the %USERPROFILE%\.m2\toolchains.xml
file.
Note that I tried the snapshot release of m2e (2.3.0.20230329-2139) without any result.
The JDK version is not controlled via the maven-comiler-plugin configuration, it is controlled via the Maven toolchain on our side. We have projects configured by the toolchain to be built with JDK11 but when we import such projects in Eclipse then JDK8 is taken.
Do you have the same issue or any recommendation how we can fix this issue?
I'm not aware of a way to define the JDK/Java-version through a tool-chain as it is described in the Guide to Using Toolchains.
You can only specify the desired Java-version in the maven-compiler-plugin (either the release
, or source
and target
property) and can then associate a JDK on your computer to that version through the toolchains.xml
.
From your description I assume you have configured source/target
version 8 in your maven-compiler-plugin configuration and have set up your toolchain to use a JDK11
for java <version>1.8</version>
, haven't you?
In the Eclipse preferences you could do the same by associating a JDK11 for the JavaSE-1.8 execution environment:
It is as if m2e was not reading the
%USERPROFILE%\.m2\toolchains.xml
file.
This should now be fixed with https://github.com/eclipse-m2e/m2e-core/pull/1643. But we still would need a test-case for this issue. If @G-Ork cannot provide a one, @glhez would you be interested to provide a PR with a test-case in org.eclipse.m2e.jdt.tests
in order to verify it works as expected and continues to do so in the future
As per the previous comments, I think this issue is not an Eclipse bug respectively the described problems are fixed. Therefore I'm closing this issue, please let us know if that's not right.
Indeed i've fixed the configuration part in m2e to set the toolchain locations. But there are more layers in maven. Actually i can not guaranty that #1643 will solve your problems.
@philipp-lenz In eclipse things work quite different. The toolchain is in most cases for plain maven execution e.g. on your build server. M2e parses your maven config and configures your eclipse project to use a suitable execution environment. Toolchains end eclipse execution environments are to independent concepts for the same problem. You find an example pom in #1120 as @blacelle mentioned. Also works without a profile. The major part is to configure the compiler for m2e and be sure you have suitable / matching environments configured in your workspace.
@glhez: Can you provide a example project for your use case?
This pom.xml should do the trick: https://github.com/glhez/m2e-core-toolchains-988/blob/master/pom.xml (you can clone the project if you need).
04/02/2024 19:47:47 CET: [INFO] Update started
04/02/2024 19:47:47 CET: [INFO] Using NULL lifecycle mapping for MavenProject: org.github.m2e-core:toolchains-988:1.0-SNAPSHOT @ E:\git\bugtrackers\m2e-core-toolchains-988\pom.xml.
04/02/2024 19:47:47 CET: [INFO] Update completed for 1 poms: local refresh takes 0,00 sec, refresh facades takes 0,00 sec, update config takes 0,00 sec
04/02/2024 19:48:27 CET: [INFO] Using NULL lifecycle mapping for MavenProject: org.github.m2e-core:toolchains-988:1.0-SNAPSHOT @ E:\git\bugtrackers\m2e-core-toolchains-988\pom.xml.
04/02/2024 19:48:48 CET: [INFO] Update started
04/02/2024 19:48:49 CET: [INFO] Using org.eclipse.m2e.jdt.JarLifecycleMapping lifecycle mapping for MavenProject: org.github.m2e-core:toolchains-988:1.0-SNAPSHOT @ E:\git\bugtrackers\m2e-core-toolchains-988\pom.xml.
04/02/2024 19:48:51 CET: [INFO] Adding source folder /toolchains-988/src/main/java
04/02/2024 19:48:51 CET: [INFO] Adding source folder /toolchains-988/target/generated-sources/wsimport
04/02/2024 19:48:51 CET: [INFO] Adding resource folder /toolchains-988/src/main/resources
04/02/2024 19:48:51 CET: [INFO] Adding source folder /toolchains-988/src/test/java
04/02/2024 19:48:51 CET: [INFO] Adding resource folder /toolchains-988/src/test/resources
04/02/2024 19:48:51 CET: [INFO] Update completed for 1 poms: local refresh takes 0,00 sec, refresh facades takes 1,00 sec, update config takes 0,00 sec
04/02/2024 19:48:51 CET: [INFO] Required toolchain: jdk [ version='[1.8,9)' ]
04/02/2024 19:48:51 CET: [ERROR] No toolchain found for type jdk
04/02/2024 19:48:51 CET: [ERROR] Cannot find matching toolchain definitions for the following toolchain types:
jdk [ version='[1.8,9)' ]
04/02/2024 19:48:51 CET: [WARN] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
04/02/2024 19:48:52 CET: [INFO] Copying 0 resource from src\main\resources to target\classes
04/02/2024 19:48:52 CET: [WARN] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
04/02/2024 19:48:52 CET: [INFO] skip non existing resourceDirectory E:\git\bugtrackers\m2e-core-toolchains-988\src\test\resources
And I do have a toolchains for Java 8:
In Maven, this is defined as:
<?xml version="1.0" encoding="UTF8"?>
<!-- Generated by Zeta Bash /e/git/zb/zeta-bash/bin/maven-generate-toolchains on 2024-01-31T00:29:33+01:00 -->
<toolchains xmlns='http://maven.apache.org/TOOLCHAINS/1.1.0'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd'
>
<toolchain> <type>jdk</type> <provides> <version>1.8.0_402</version> <id>JavaSE-1.8</id> <vendor>Temurin</vendor> </provides> <configuration> <jdkHome>E:\apps\portable\java\latest\openjdk-8-hotspot</jdkHome> </configuration> </toolchain>
<toolchain> <type>jdk</type> <provides> <version>17.0.10</version> <id>JavaSE-17</id> <vendor>Eclipse Adoptium</vendor> </provides> <configuration> <jdkHome>E:\apps\portable\java\latest\openjdk-17-hotspot</jdkHome> </configuration> </toolchain>
<toolchain> <type>jdk</type> <provides> <version>21.0.2</version> <id>JavaSE-21</id> <vendor>Eclipse Adoptium</vendor> </provides> <configuration> <jdkHome>E:\apps\portable\java\latest\openjdk-21-hotspot</jdkHome> </configuration> </toolchain>
</toolchains>
I also tried with <id>JavaSE-1.8</id>
in the toolchains plugin but to no success.
Do note that this is a blocker for any project still using JAXB/WS stuff and Java 8 : the maven plugin can't run with Java 17 without some tricks.
@glhez Is there real error in your build or is it just the annoying log entry?
The misguiding log entry should be fixed in the next m2e release with #1637. The toolchain plugin will not be executed in m2e as it is not necessary in eclipse. In the current version of m2e you have to disable the toolchain plugin execution in eclipse builds via lifecycle mapping to get rid of the log entry. Either by XML processing instruction like <?m2e ignore?> (see: New syntax for specifying lifecycle mapping metadata) or by a lifecycle mapping file.
There is a real error in the build: it won't build.
The cause changed from NPE (the toolchains was not provided) to No toolchain found for type jdk: this block the build because jawxs (and compiler) plugin both requires a toolchains that Eclipse won't provide.
And I don't know what toolchains Eclipse provide to maven plugin in this context: I did try
I did not dig into it too much: I did not check what was the content of generated toolchains (I did not run Eclipse in debug mode) but if you have a way easier than debugging, I can try it.
Please don't confuse maven toolchains with what you see in eclipse, this is completely independent and m2e does not supply any toolchains to maven at all base on this.
As a first step you should enable debugging (-X
) and version infos (-V
) and stack traces (-e
) to see whats going on here e.g used maven/java versions and what parameter are used.
Please don't confuse maven toolchains with what you see in eclipse, this is completely independent and m2e does not supply any toolchains to maven at all base on this.
That's explain a lot.
@G-Ork if you wanted a use case for #1643 , then the one I provided should works. Especially since updating Maven project from Eclipse delete resources (#1511) generated by mwnv: having Eclipse capable of executing jaxws project correctly (with JDK8 and no error :)) will alleviate that.
By the way I think it was made recently by @mickaelistria the other way round that meven defined toolchains are visible in eclipse but the other way round would be rather confusing as this would mean it works if you run it from eclipse probably but not on commandline/your CI ...
So depending on your configuration %USERPROFILE%\.m2\toolchains.xml
should apply here.
@glhez I've testet your project and it works for me after changing the pom as suggested. Here is what i've changed:
Ignore toolchain execution in eclipse with livecycle mapping pi
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<?m2e ignore?>
<goals> <goal>toolchain</goal> </goals>
</execution>
</executions>
Removed enforcer plugin You enforce a java version (>=17) that should not work with your toolchain (8~9). But i never used the enforcer may i interpret the config wrong. You should describe your intention for this combo.
You enforce a java version (>=17) that should not work with your toolchain (8~9). But i never used the enforcer may i interpret the config wrong. You should describe your intention for this combo.
That's normal: these are two different use case.
There are some plugins incompatible with Java 8 like git-commit-id-maven-plugin: if you use Java 8 with this plugin, you will get:
Exception in thread "main" java.lang.UnsupportedClassVersionError: (some class)
has been compiled by a more recent version of the Java Runtime (class file version 61.0),
this version of the Java Runtime only recognizes class file versions up to 52.0
With enforcer set to Java 17, you won't get this problem because it should execute first.
@glhez I've testet your project and it works for me after changing the pom as suggested. Here is what i've changed:
- Ignore toolchain execution in eclipse with livecycle mapping pi
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-toolchains-plugin</artifactId> <version>3.1.0</version> <executions> <execution> <?m2e ignore?> <goals> <goal>toolchain</goal> </goals> </execution> </executions>
What the intended purpose of m2e core with toolchains in #1643?
If the purpose is to support it, there should not be any <?m2e ignore?>
in the first place and the plugin should be able to fork a Java 8 process.... and it seems the plugin I used in the past/example seems to have been patched (jaxws-maven-plugin #71) for Java 9 because I've seen the plugin fork a Java 21 process with Process Monitor: the toolchains issue was hiding this.
I do not really have other working use case of toolchains + other plugin.
@glhez This issue is closed and was owned by someone else may not like to participate. This discussion hijacked the dead issue.
Eclipse is more like a simple texteditor that forks some processes. You do not need toolchain execution in eclipse.........
In the next release the execution will be ignored by default. There should be better documentation anyway. I extend the m2e configuration before I debug so deep I understand better. Although the settings are not used in every execution the setting is not useless.
Use the PI. It won't hurt your POM. Only necessary till next release. Read the links provided for lifecycle mapping and learn more. For sure helpfull for larger multimodule buids especially when codegen is involved.
@glhez I think again there is some confusion between different things:
--global-toolchains
on the commandline or on the launch configAnd again you should enable debugging (-X) and version infos (-V) and stack traces (-e) to see whats going on here e.g used maven/java versions and what parameter are used.
So far from the side of "running the build from eclipse", now about the suppression and m2e running some mojos as part of the build inside Eclipse, there for technical reasons build is always run with the JVM you start your eclipse with, so if you project does not run on Java 17 it will only work with a limited feature set in the IDE.
The maven-toolchains-plugin is used to actually select a toolchain and other plugins might use it, it is not meant as a way to select a JDK in general for a given module, nor can it be used to fix a build-plugin
I know how the toolchains works: you use the toolchains plugin to restrict the set of toolchains so that other plugin may use these toolchains.
But we are thinking only in terms of Java: the intent for toolchains, although it might be an obscure part of Maven is to provide tools, not JDK tools, but any tools: the frontend-maven-plugin for example supports m2e but does not supports toolchains while it could have requested node
and npm
as toolchains.
it is not meant as a way to select a JDK in general for a given module
This assertion is false: some plugin allow overriding the global toolchains selection, eg: compiler
The sole use case I could think about is that you wish to build with older version of Java (< 8) and run test with newer version (8) all by remaining binary compatible with older version;
Usually running the build with Java 17 and using release option if you want to compile for java 8 is enough for running code (e.g. surefire / junit) you then can use maven-toolchains-plugin to tell it using a certain JVM to be 100% sure it runs / works on java 8.
As long as you use a toolchain, the maven-compiler-plugin will use it: the release option (eg: <maven.compiler.release>8</maven.compiler.release>
) will fail:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project toolchains-988: Compilation failure
[ERROR] javac: invalid flag: --release
[ERROR] Usage: javac <options> <source files>
[ERROR] use -help for a list of possible options
And again you should enable debugging (-X) and version infos (-V) and stack traces (-e) to see whats going on here e.g used maven/java versions and what parameter are used.
You don't have to use debug here, as you can see it right in the logs:
[INFO] --- toolchains:3.1.0:toolchain (default) @ toolchains-988 ---
[INFO] Required toolchain: jdk [ version='[1.8,9)' ]
[INFO] Found matching toolchain for type jdk: JDK[E:\apps\portable\java\latest\openjdk-8-hotspot]
And that is where I could be fairly confused: you are giving me debug options for Maven (-X, -V, -e) but the problem is only inside Eclipse and m2e-core, with the toolchains not being supported.
The only way I know to print the existing toolchains is by going into debug mode with the m2e-core Oomph installer and since you said in your previous comment that m2e does not supply any toolchains to maven at all base on this I did not even try.
So far from the side of "running the build from eclipse", now about the suppression and m2e running some mojos as part of the build inside Eclipse, there for technical reasons build is always run with the JVM you start your eclipse with, so if you project does not run on Java 17 it will only work with a limited feature set in the IDE.
That's fine by me.
I know how the toolchains works: you use the toolchains plugin to restrict the set of toolchains so that other plugin may use these toolchains.
Then I'm a bit confused about the questions / complains here...
But we are thinking only in terms of Java: the intent for toolchains
No one here does it, this was brought up by you as you are made a connection between Eclipse configured JREs and maven toolchains (where there is no such connection).
This assertion is false: some plugin allow overriding the global toolchains selection, eg: compiler
It is not, you are selecting the javac that the compiler plugin is using to compile, but you can't select a jre that is used to execute the compiler plugin itself.
You don't have to use debug here, as you can see it right in the logs:
I can see what? That everything worls and a toolchain was found so what is now the exact problem to solve?
And that is where I could be fairly confused: you are giving me debug options for Maven (-X, -V, -e) but the problem is only inside Eclipse and m2e-core, with the toolchains not being supported.
I never claimed that, I only said that m2e does not inject / support additional toolchains, for the sole reason that m2e only calls maven and maven do whatever it does if you execute it as a maven build.
So what you show here as a screenshot shows the jdk that is used to run maven, it has nothing to do with any tool-chain configuration.
It is not, you are selecting the javac that the compiler plugin is using to compile, but you can't select a jre that is used to execute the compiler plugin itself.
I never said that. I only mentioned the fact that maven-compiler-plugin use, in order:
And I did a test:
And all "works" (the compilation fails because, well, JAX WS is not really Java 8 compatible without some changes).
I don't expect m2e to handle the edgy case: without any maven.compiler.source/target/release
it selected Java 8 but should have selected Java 21.
I don't think I would want that supported because it would be quite the headache to maintain.
What is now the exact problem to solve?
If we speak about the problem I had in Apr 11, 2023, the problem is gone because there are no longer issues with jaxws plugin.
If we speak about toolchains, these problems were introduced in 2.2.0 (Mojos without a mapping are now executed by default in incremental builds): toolchains is executed, m2e "provides" an empty toolchains and the plugin execution fails because its lacks expected toolchains and you get an error in the pom.xml
Snapshot build seems to ignore this execution by default (probably because of #1637) and that's fine by me: I don't have other use of toolchains. Or they would mean complicated stuff in Maven - which I try to avoid.
Hello all,
we are using the following Eclipse and m2e-Plugin Version:
Eclipse Version: Version: 2022-09 (4.25.0) Build id: 20220908-1902
m2e Plugin: M2E - Maven Integration for Eclipse 2.0.6.20221012-0544 org.eclipse.m2e.feature.feature.group Eclipse.org - m2e
We are using the Maven toolchain to control the JDK used for the projects. It is working fine with Eclipse 2022-06 but it does not work anymore with the new version.
We think it might be linked to this new tab in the Eclipse preferences:
The JDK version is not controlled via the maven-comiler-plugin configuration, it is controlled via the Maven toolchain on our side. We have projects configured by the toolchain to be built with JDK11 but when we import such projects in Eclipse then JDK8 is taken.
Do you have the same issue or any recommendation how we can fix this issue?
Thank you!