the only way I've found to have maven compile scala sources on the command line using mvn is to add the executions explicitly in the scala-maven-plugin.
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-deprecation</arg>
<arg>-unchecked</arg>
</args>
<jvmArgs>
<jvmArg>-Xms128m</jvmArg>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
However, Eclipse does not like these executions and gives the following errors.
Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.0.1:compile (execution: default, phase: compile)
Plugin execution not covered by lifecycle configuration: net.alchim31.maven:scala-maven-plugin:3.0.1:testCompile (execution: default, phase: test-compile)
Eclipse suggests permanently marking the goals as ignored, but this means a lot of ugly garbage is added to my pom. I mean, XML is already hard to look at. Is there a better way to configure my project to compile the sources with mvn? Following is what Eclipse adds.
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
net.alchim31.maven
</groupId>
<artifactId>
scala-maven-plugin
</artifactId>
<versionRange>
[3.0.1,)
</versionRange>
<goals>
<goal>testCompile</goal>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
m2e requires you install specific m2e plugins.
The one for scala-maven-plugin is m2e-scala: https://github.com/sonatype/m2eclipse-scala
Remove the pluginManagement that disables scala-maven-plugin, and install m2e-scala
http://alchim31.free.fr/m2e-scala/update-site
BTW, latest scala-maven-plugin is 3.1.0, not 3.0.1.
Cheers,
Stéphane
Related
Eclipse version: 2022-09
Eclipse m2e version: 2.0.4
antlr version: 3
antlr3-maven-plugin: 3.5.3
I have a project with a Logic.g file. Everything was working OK on a previous version of Eclipse (where I had installed an m2e antlr connector), meaning the file would be converted to target/generated-sources/antlr3 (LogicLexer.java and LogicParser.java), and somehow be picked up by Eclipse and compile a Logic.tokens file in target, and the LogicLexer.class and LogicParser.class within target.
In Eclipse 2022-09 however, my test classes that use either LogicLexer or LogicParser yield a compilation error in Errors "cannot be resolved to a type".
It's just a problem in Eclipse (nothing changed in the code, and a maven verify works correctly).
The tokens file and the .class are being generated as long as I have the lifecycleMappingMetadata configured (see snippet below).
Question: How can I make the Eclipse project see these compiled classes and remove the compilation errors?
<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<goals>
<goal>antlr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.antlr</groupId>
<artifactId>antlr3-maven-plugin</artifactId>
<versionRange>[3.5.3,)</versionRange>
<goals>
<goal>antlr</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
I am letting Maven copy some dependency files into a specific location for a GWT project. The maven-dependency-plugin does the job and so far it works. The only Problem is that I'm getting an error from Eclipse that says:
Artifact has not been packaged yet. When used on reactor artifact, copy should be executed after packaging: see MDEP-187.
I have tried to change the <phase> but that did not work. How can I get rid of that error and why is it there because Maven builds as intended.
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/war/WEB-INF/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
I got the same error and I solved this issue with a workaround. I have compiled and installed the project with Maven in a console outside Eclipse IDE. After I have refreshed the project inside Eclipse IDE and error has disappeared.
There is a solution similar to s1moner3d answer which doesn't require changes to pom.xml file.
Go to Window > Preferences > Maven > Lifecycle Mappings and click on the Open workspace lifecycle mappings metadata button.
Than add pluginExecution entry like in the code below. If the file is empty, copy the entire content below. You might need to change versionRange.
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>2.10</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
In order for this to take effect go back to Preferences and click Reload workspace lifecycle mappings metadata. Update Maven projects and / or rebuild. The error should be gone.
Useful if you cannot or don't want to modify pom.xml for any reasons but want to stop your Eclipse m2e from executing particular goal of a particular plugin.
I solved by setting the plugin phase to prepare-package. I know it's still a workaround, but I think it's cleaner than compile externally.
<plugins>
[...]
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
[YOUR_CONFIGURATION]
</configuration>
</execution>
</executions>
</plugin>
[...]
</plugins>
EDIT:
This is not fully solving: sometimes it works, other times not.
The final solution is to use the Lifecycle Mapping Maven Dummy Plugin through an eclipse-only maven profile:
<profile>
<id>only-eclipse</id>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<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-dependency-plugin</artifactId>
<versionRange>${maven-dependency-plugin.version}</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
I had to wrap plugins tag under pluginManagement to make the error go away.
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>../../lib/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
I used this answer to fix the problem. That 2017 update to m2eclipse means you don't need to use the pluginManagment xml as in s1moner3d's answer, and so that gets rid of the "POM not found" warning I got for the 'lifecycle-mapping' artifactId tag when I included it.
To summarize:
You don't need a pluginManagment block for org.eclipse.m2e
Add a <?m2e ignore?> tag in your <execution> tag(s) :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<?m2e ignore?>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
...{your configuration} ...
</configuration>
</execution>
</executions>
</plugin>
https://www.eclipse.org/m2e/documentation/release-notes-17.html#new-syntax-for-specifying-lifecycle-mapping-metadata
For those returning to this question, it may be useful to report seeing the same problem in Eclipse against maven-dependency-plugin version 2.8. This was in the package phase:
Artifact has not been packaged yet. When used on reactor artifact, copy should be executed after packaging: see MDEP-187. (org.apache.maven.plugins:maven-dependency-plugin:2.8:copy:copy-proguard:package)
In this case upgrading to 3.1.1 solved the problem:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-proguard</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
...
This issue related to eclipse IDE:
Solution is to update M2E Connector for the maven-dependency-plugin
Steps :
Help ---> Eclipse Marketplace.. then update the plugin.
I'm importing an existing Maven project for Scala. I'm prompted by Eclipse to "Set up maven plugin connectors" for the plugin "maven-scala-plugin" version 2.13.1 but two goals are highlighted red with no optons support available to select.
What plugins are available to support the compile and testCompile goals?
Eclipse is 3.7.2, but I'm not wedded to this version.
You don't need to support the compile and testCompile goals, the compilation is done by scala-ide. You need to add the following mess to your pom.xml:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<versionRange>[3.1.0,)</versionRange>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
<goal>testCompile</goal>
<goal>doc</goal>
<goal>doc-jar</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
This tells your m2e (the maven plugin for eclipse) to ignore the goals which apply to your scala-maven-plugin. You'll have to change the groupId & versionRange as well.
I would like to be able to configure the pom.xml so that when I import it into eclipse it specifies src/main/aspect as an eclipse source folder.
At the moment, importing creates the default source folders but that is all.
What should be done?
Thanks
edit 1
I have configured the aspectj plugin thus:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
<configuration>
<source>${project.build.source}</source>
<target>${project.build.target}</target>
<aspectDirectory>src/main/aspect</aspectDirectory>
<testAspectDirectory>src/test/aspect</testAspectDirectory>
</configuration>
</execution>
</executions>
</plugin>
edit 2
I have configured the m2e plugin thus:
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
aspectj-maven-plugin
</artifactId>
<versionRange>
[1.4,)
</versionRange>
<goals>
<goal>test-compile</goal>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
You shouldn't configure the defaults of the plugin, cause it defines already the src/test/aspect and src/main/aspect and it shouldn't be necessary to configuration something supplemental to compile etc.
Furthermore the problem with eclipse could be based on a missing mapping for your m2e plugin this means to add the following to your build:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<versionRange>[1.4,)</versionRange>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
This might cause you problem in Eclipse not to see the source folder correctly imported.
I believe source is supposed to be a java version, not a directory. Same for target. sources allows you to specify the source directories, and the docs say that if not specified, the java sources of the current project will be used - just one for your project as configured currently.
I would try listing the directories in the sources parameter, and if that didn't work, I'd remove sources and try build-helper:add-source. I'm not sure there's an m2e connector for build-helper-maven-plugin yet so you might have to add a similar mapping to the one khmarbaise mentioned.
I think it would not be added as source folder by Eclipse. you could add it on your own in Java Build Path > Source.
This is not necessary: Then you need to have AJDT plugin installed in and convert the project to AspectJ Project, otherwise the .ajfiles will be full of errors complained by Eclipse. The errors does not affect maven compiling.
In my experience, recognized or not as source would not affect maven compiling the .aj files under src/main/aspect
Both aspectDirectory and aspectTestDirectory have default values as you given. they are not needed if the same as default.
Here below is my pom configuration (didn't try test-compile) and it works:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<!--<Xlint>ignore</Xlint>--><!--bypass xlint warnings -->
</configuration>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.7.2</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
I have a fairly simple Maven project:
<project>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
However, I get the following error in m2eclipse:
Description Resource Path Location Type
maven-dependency-plugin (goals "copy-dependencies", "unpack") is not supported by m2e. pom.xml /jasperreports-test line 60 Maven Project Build Lifecycle Mapping Problem
Why do I care if m2eclipse doesn't "support" this task? Maven does, and that's all I really care about. How can I get this error in my project to go away?
It seems to be a known issue. You can instruct m2e to ignore this.
Option 1: pom.xml
Add the following inside your <build/> tag:
<pluginManagement>
<plugins>
<!-- Ignore/Execute plugin execution -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<!-- copy-dependency plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins></pluginManagement>
You will need to do Maven... -> Update Project Configuration on your project after this.
Read more: http://wiki.eclipse.org/M2E_plugin_execution_not_covered#m2e_maven_plugin_coverage_status
Option 2: Global Eclipse Override
To avoid changing your POM files, the ignore override can be applied to the whole workspace via Eclipse settings.
Save this file somewhere on the disk: https://gist.github.com/maksimov/8906462
In Eclipse/Preferences/Maven/Lifecycle Mappings browse to this file and click OK:
This is a problem of M2E for Eclipse M2E plugin execution not covered.
To solve this problem, all you got to do is to map the lifecycle it doesn't recognize and instruct M2E to execute it.
You should add this after your plugins, inside the build. This will remove the error and make M2E recognize the goal copy-depencies of maven-dependency-plugin and make the POM work as expected, copying dependencies to folder every time Eclipse build it. If you just want to ignore the error, then you change <execute /> for <ignore />. No need for enclosing your maven-dependency-plugin into pluginManagement, as suggested before.
<pluginManagement>
<plugins>
<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-dependency-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
If copy-dependencies, unpack, pack, etc., are important for your project you shouldn't ignore it. You have to enclose your <plugins> in <pluginManagement> tested with Eclipse Indigo SR1, maven 2.2.1
To make it work, instead of ignoring it, you can install the m2e connector for the maven-dependency-plugin:
https://github.com/ianbrandt/m2e-maven-dependency-plugin
Here is how you would do it in Eclipse:
go to Window/Preferences/Maven/Discovery/
enter Catalog URL: http://download.eclipse.org/technology/m2e/discovery/directory-1.4.xml
click Open Catalog
choose the m2e-maven-dependency-plugin
enjoy
Despite answer from CaioToOn above, I still had problems getting this to work initially.
After multiple attempts, finally got it working.
Am pasting my final version here - hoping it will benefit somebody else.
<build>
<plugins>
<!--
Copy all Maven Dependencies (-MD) into libMD/ folder to use in classpath via shellscript
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libMD</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<!--
Above maven-dependepcy-plugin gives a validation error in m2e.
To fix that, add the plugin management step below. Per: http://stackoverflow.com/a/12109018
-->
<pluginManagement>
<plugins>
<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-dependency-plugin</artifactId>
<versionRange>[2.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
I had the same problem when trying to load Hadoop project in eclipse. I tried the solutions above, and I believe it might have worked in Eclipse Kepler... not even sure anymore (tried too many things).
With all the problems I was having, I decided to move on to Eclipse Luna, and the solutions above did not work for me.
There was another post that recommended changing the ... tag to package. I started doing that, and it would "clear" the errors... However, I start to think that the changes would bite me later - I am not an expert on Maven.
Fortunately, I found out how to remove all the errors. Go to Window->Preferences->Maven-> Error/Warnings and change "Plugin execution not covered by lifecycle..." option to "Ignore". Hope it helps.
I know this is old post but I struggled today with this problem also and I used template from this page: http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
<classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
and everything works fine under m2e 1.3.1.
When I tried to use
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I also got m2e error.
Another option is to navigate to problems tab, right click on error, click apply quick fix. The should generate the ignore xml code and apply it .pom file for you.