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 and toolchain #1588

Closed
tschoellhorn opened this issue Oct 30, 2023 · 8 comments
Closed

m2e and toolchain #1588

tschoellhorn opened this issue Oct 30, 2023 · 8 comments

Comments

@tschoellhorn
Copy link

Hi,

a few days ago I have installed Eclipse 2023-09 (4.29.0) on Windows with which uses m2 2.4.100.20230827-1557.

Now I have problems with an imported multi-module maven project using the maven-tool-chains-plugin. In the sub-modules errors are shown. Compilation with my integrated maven wrapper (same version as in Eclipse) work fine.

The errors suggest, that the toolchain.xml-file could not be successfully resolved - yet in other projects the more or less same setup works.

So, is this a user error or a bug? Is there something I can do to prevent this problem in my version?

Cheers,
Tino

The stack-traces go like this:

Failed to execute mojo org.apache.maven.plugins:maven-toolchains-plugin:3.0.0:toolchain {execution: default} (org.apache.maven.plugins:maven-toolchains-plugin:3.0.0:toolchain:default:validate)

org.eclipse.core.runtime.CoreException: Failed to execute mojo org.apache.maven.plugins:maven-toolchains-plugin:3.0.0:toolchain {execution: default}
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeMojo(MavenExecutionContext.java:340)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.lambda$0(MavenExecutionContext.java:291)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:394)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:275)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:290)
	at org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant.build(MojoExecutionBuildParticipant.java:57)
	at org.eclipse.m2e.core.internal.builder.MavenBuilderImpl.lambda$2(MavenBuilderImpl.java:153)
	at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:986)
	at org.eclipse.m2e.core.internal.builder.MavenBuilderImpl.build(MavenBuilderImpl.java:133)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:164)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder$1.method(MavenBuilder.java:1)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.lambda$1(MavenBuilder.java:109)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:394)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:228)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.lambda$0(MavenBuilder.java:100)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:394)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:275)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:214)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:83)
	at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:192)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1079)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:207)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:300)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.apache.maven.plugin.MojoFailureException: Cannot find matching toolchain definitions for the following toolchain types:
jdk [ version='11' ]
Please make sure you define the required toolchains in your ~/.m2/toolchains.xml file.
	at org.apache.maven.plugins.toolchain.ToolchainMojo.execute(ToolchainMojo.java:109)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
	at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeMojo(MavenExecutionContext.java:338)
	... 32 more

@tschoellhorn
Copy link
Author

I found a solution, which solves my problem - yet it seems like a bug. Adding a lifecylemetadata-entry to the configuration of m2e resolves the issue:

<plugin>
        			<groupId>org.eclipse.m2e</groupId>
        			<artifactId>lifecycle-mapping</artifactId>
        			<version>1.0.0</version>
        			<configuration>
        				<lifecycleMappingMetadata>
        					<pluginExecutions>
        					<pluginExecution>
        						<pluginExecutionFilter>
        							<groupId>
        								org.apache.maven.plugins
        							</groupId>
        							<artifactId>
        								maven-toolchains-plugin
        							</artifactId>
        							<versionRange>
        								[3.1.0,)
        							</versionRange>
        							<goals>
        								<goal>toolchain</goal>
        							</goals>
        						</pluginExecutionFilter>
        						<action>
        							<ignore></ignore>
        						</action>
        					</pluginExecution>
        					</pluginExecutions>
        				</lifecycleMappingMetadata>
        			</configuration>
        		</plugin>

@david-pace
Copy link

david-pace commented Nov 2, 2023

@tschoellhorn thanks for providing the snippet, where exactly did you add it? I tried adding it in <build>/<pluginManagement>/<plugins> in my root POM but every time I run Maven -> Update Project this error occurs in nearly all of my projects. Any idea what I'm doing wrong? My Eclipse version is 2023-09 (4.29.0) as well.

@tschoellhorn
Copy link
Author

I added it at the same level as you. The weird thing is that you can build the project directyl with mvn / mvnw - but the integration is the problem. Maybe you still have another version of the maven-toolchains-plugin? And it might be worth a try that you click on the hint which Eclipse shows in your pom. There you might be able to add this snippet directly from the hint.

Sorry, that I could not be of more help.

@HannesWell
Copy link
Contributor

I found a solution, which solves my problem - yet it seems like a bug. Adding a lifecylemetadata-entry to the configuration of m2e resolves the issue:

Glad you found a solution. Btw. you could also use the processing-instrucction based approache as it is documented here:
https://eclipse.dev/m2e/documentation/release-notes-17.html#new-syntax-for-specifying-lifecycle-mapping-metadata
This is basically a one-liner at you configuration of the toolchains-plugin instead of a full plug-in config.

I haven't looked in detail into your problem, but to be able to do that a minimal reproducer project would be good.

@G-Ork
Copy link
Contributor

G-Ork commented Jan 2, 2024

I have tried the solution and using the xml processing instructions for the lifecycle mapping do not work for me at all. The problem is not the execution of the plugin. You ca see from the stack-trace above that it is executed.

The maven-toolchains-plugin is just a simple plugin to read the project desired toolchain and match it against the known toolchains (in moste cases ~/.m2/toolchains.xml) and select one. If no matching definition is found it logs the message similar to this:

Cannot find matching toolchain definitions for the following toolchain types: jdk [ version='11' ]

The problem is the initialization of the known toolchains. Here some Links to understand the problem:

As you can see someone reinvented the wheel of loading the configuration and missing essential parts.

@G-Ork
Copy link
Contributor

G-Ork commented Jan 3, 2024

I have to admit that I was wrong. The toolchains plugin execution is in most cases not necessary in eclipse m2e build context. The m2e launcher configures the project correctly. So Ignoring the toolchains plug within eclipse is a solution and works in most cases:

Example
<plugin>
  <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>
  <configuration>
    <toolchains>
      <jdk>
        <version>${maven.compiler.target}</version>
      </jdk>
    </toolchains>
  </configuration>
</plugin>

@G-Ork
Copy link
Contributor

G-Ork commented Jan 3, 2024

I've created a PR #1638 to ignore the plugin by default within m2e.

@HannesWell
Copy link
Contributor

As you can see someone reinvented the wheel of loading the configuration and missing essential parts.

There is indeed some duplication, but that's not someone wanted to reinvent something, but because there are (unfortunately) differences in Maven executed in the CLI and in the IDE. If you have specific suggestions how we can reuse existing code, a PR is of course welcome. :)

Anyway, I think we can consider this fixed with

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

No branches or pull requests

4 participants