How do I get Eclipse to resolve classes generated with Maven 2? - eclipse

I'm using Google Protocol Buffers to generate some Java classes for my project. Using Maven 2 and its "antrun" plugin, these classes are freshly generated before compile, output to target/generated-sources and put on the classpath during the build. So building the project from the POM is no problem.
However, Eclipse doesn't know how to resolve the generated class, because the folder it's in doesn't seem to be on the IDE's classpath during development. I'm using m2eclipse and have it manage dependencies for me, so I had expected Maven to take care of this.
How can I get IDE support (code completion etc.) for the generated code?

m2eclipse supports this. First, add the path to your build path:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
Second, add support for that to m2e:
<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>build-helper-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>parse-version</goal>
<goal>add-source</goal>
<goal>maven-version</goal>
<goal>add-resource</goal>
<goal>add-test-resource</goal>
<goal>add-test-source</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
The second step might not be necessary, if your eclipse installation has installed the "org.eclipse.m2e.discovery.lifecyclemapping.buildhelper.xml" plugin. This plugin is available via Window -> Preferences -> Maven -> Discovery. Currently, that does not work here at Eclipse Kepler, therefore, I fetched the JAR (linked from the xml shown in the Catalog URL) and extracted the fragments from org.eclipse.m2e.discovery.lifecyclemapping.buildhelper.xml by hand.

m2eclipse doesn't support this. You must manually add the folder target/generated-sources as a source folder. When you tell m2eclipse to "Update Project Configuration", this will be overwritten and you have to restore it.
Also, make sure that Eclipse looks for changes in the workspace.
There might be some issues, though. Eventually, you'll run into errors that some class can't be compiled because some other class can't be resolved. Code completion will work, though. The root cause of this issue is that Eclipse gets confused when Maven changes class files in target.
To solve this, you must tell Eclipse to compile to a different place than Maven.

What you should see in your project explorer is a container named "Maven Dependencies" in place of the usual "Referenced libraries". This means m2eclipse is managing your build path.
In my case, to achieve this, I checked "Include Modules" and unchecked "Skip Maven compiler plugin when processing resources" on the "Maven" section of Project->Properties.

Personally I resolved this problem by setting up the generated classes as a seperate project and made it a dependency in my main (non-generated) project. I was using wsdl2java to generate webservice classes so the "source" in my sub-project was the wdsl and xsds. Worked well even when the wsdl was changing regularly.

I had this issue with code generated using Maven and wsdl2java and here's what I did in Eclipse Juno to resolve it. Assume my project is named project1:
Right-click project1 and select Properties
Choose Java Build Path from the left and select the Libraries tab
Click Add Class Folder
Select the bin directory and click OK (project1/target/generated-sources/bin)
Click OK and Refresh the project
As an added bonus you can also attach the source code:
Click the arrow next to the new class folder you just created
Click on Source attachment
Click the Edit button
Set the Path to /project1/target/generated-sources/axis2/src
Click OK

Right-click project and select Properties
Choose Java Build Pathfrom the left and select the Source tab
Click Add Folder
Select the bin directory and click OK
(project/target/generated-sources/xxxx) Click OK and Refresh the project

How can I get IDE support (code completion etc.) for the generated code?
Typically I would add the m2e lifecycle-mapping plugin to the pom.xml file as described in #koppor's answer. However adding per-eclipse code to my pom.xml files is not an option at work which is mostly an IntelliJ shop.
My solution first adds the build-helper-maven-plugin to the pom.xml which works fine from the command line but not in eclipse.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
To fix eclipse I installed the Apt M2E Connector from the Eclipse Marketplace. I think things started working right after I restarted and then rebuilt all of my projects. I now see the following in my source dirs:
src/main/java
target/generated-sources
...
Feature!

Did you try to refresh the Eclipse project?
(source: oyvindhauge.com)
When an external tool generate new files or updates old ones, Eclipse will not be able to detect the change until the next request.
Another option would be to define a new Custom builder, specifying for that builder to "refresh resources upon completion":
alt text http://www.cs.lth.se/EDA180/2005/Verktyg/eclipse_refresh.gif

Worked for me (But you will to have to follow this every time so you can add this path in pom.xml)
Right click on your project > Build Path > Configure Build Path
In sources tag, click on [Add Folder] button
Check target/generated-sources/annotations

To generate Java source files from .proto files use Protocol Buffers Plugin which works out-of-the-box in eclipse Oxygen.
Basic usage (see here for detailed description):
make sure that native protoc compiler is installed on your system
update your pom.xml file:
make sure you use at least Java 6 (Java 7+ is recommended)
add plugin invocation
add the corresponding dependency for com.google.protobuf:protobuf-java
put your .proto files inside project's src/main/proto directory
update the project (via Maven -> Update project...)
Example pom.xml:
<project>
...
<build>
<plugins>
<!-- Require at least Java 6 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Generate .java files from .proto definitions -->
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.1</version>
<configuration>
<protocExecutable>/usr/local/bin/protoc</protocExecutable>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.5.1</version>
</dependency>
...
</dependencies>
...
</project>
Some additional notes:
if protoc executable is in the PATH the protocExecutable configuration entry can be omitted
test-only protobuf message definitions can be put into project's src/test/proto directory
I recommend installing Protocol Buffer Descriptor Editor (marketplace link)
Good luck!

Related

How to use build-helper-maven-plugin to create extra directory?

I have a Java Maven project with the following structure. (This is a logical structure, not necessarily the exact directory structure.)
Project
|-Submodule
| |-src/main/java
| |-src/main/resources
| |-src/test/java
| |-src/test/resources
| `-pom.xml
`-pom.xml
In accordance with (my understanding of) Maven standards, the parent pom references the submodule in it's <modules> tag, and the submodule pom references the parent pom as it's <parent>.
Now, my goal is to use Maven to add two new source folders to the submodule, namely src/integrationTest/java and src/integrationTest/resources. I want Maven to "know about" these two folders so that I can execute the tests therein using my Maven testing plugin, maven-pmd-plugin. And I want Eclipse to "know about" these two folders so that they display correctly in Eclipse's graphical Project Explorer.
I was told that the build-helper-maven-plugin plugin could be used to create these additional directories that I needed. So I added the following configuration to my submodule pom:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-integration-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integration-test/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-integration-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/integration-test/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
When I rebuilt the project, Maven didn't generate the directories I wanted. So I took the plugin configuration out of my submodule pom and put it in my parent pom instead. Maven still didn't generate my directories.
At this point, I don't know how to get this plugin working. I'm trying to follow other online tutorials, but I must be doing something wrong. Could anyone explain which pom file is intended to configure build-helper-maven-plugin? And how do I configure Eclipse to display the new Maven project structure correctly?
Thanks for the help!
khmarbaise's comment made me realize my mistake, although I didn't take his advice.
The build-helper-maven-plugin configuration should go in the submodule pom (not the parent pom) where I originally had it. But Maven will not create these directories for you, you create the directories and then Maven uses them.
Once Maven is using your new directories, Eclipse displays them just fine.

How to use maven-m2e-codestyle connector?

According to https://issues.sonatype.org/browse/OSSRH-3293 "Maven m2e Code-Style and Save-Actions connector"
This plugin is executed inside m2e Eclipse plugin when the project is
configured and configures the save-actions and code-styling options of
your maven project so you don't need to commit the .settings files to
your repo
I have not been able to find a sample showing how this connector is supposed to be used. What do I put into my pom.xml to trigger it, how do I know if my eclipse installation has the connector installed?
Does anyone have an example configuration for this connector?
From looking at the source code, it's something like:
<plugin>
<groupId>com.despegar.maven.plugin</groupId>
<artifactId>maven-m2e-codestyle</artifactId>
<version>1.0.3</version>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
<configuration>
<codeStyleBaseUrl>http://some/path/to/eclipse/files/</codeStyleBaseUrl>
<!-- Will not work. Scheme 'file' not registered. -->
<!-- <codeStyleBaseUrl>file://localhost/some/path/to/eclipse/files/</codeStyleBaseUrl> -->
<baseDir>${basedir}/</baseDir>
</configuration>
</execution>
</executions>
</plugin>
The 2 configuration parameters are:
<codeStyleBaseUrl>
<baseDir>
It copies these 3 files:
${codeStyleBaseUrl}/org.eclipse.core.resources.prefs
${codeStyleBaseUrl}/org.eclipse.jdt.core.prefs
${codeStyleBaseUrl}/org.eclipse.jdt.ui.prefs
to:
${baseDir}/.settings/
Note that <codeStyleBaseUrl> must be http/https since it uses HttpClient behind the scenes.

Eclipse javadoc: The type package-info is already defined

OS: Windows 7 x64
Eclipse Platform: 3.7.2.M20120208
m2e: 1.0.200.20111228-1245
Have similar problem as in this bug.
There is a bunch of package-info.java files in /src and /test folders, so they have same package. Eclipse show error:
"The type **package-info** is already defined"
I can delete package-info.java files either in /test or /src to avoid problem indication. But this workaround is not very comfort since I am using SCM and need to delete this files all time after update.
Same for Eclipse Platform 4.2.0.I20120608-1400
You can do this -->
Go to Build path -> configure build path -->
in Source tab -->
select the package (in which you have these problematic package-info.java file)
for eg. project-name/src/test/java
click on exclude -> and in exclusion pattern add "**/package-info.java"
this should solve the problem, as plainly you are asking eclipse to exclude these files, and thus you wouldn't have to delete those files and solving your SCM related issues
There are a few options to solve this:
Move away from package-info.java files, and replace them with package.html files.
Only have package-info.java files in the src/ tree, as the same-named packages in the test/ tree will "overlap" the src/ tree.
Generate javadoc separately for the src/ and test/ trees, as they are probably for different audiences.
If you use maven and m2e for interaction between eclipse and maven. There is a quite clean solution: add a profile to pom.xml that is activated only by m2e and prevents compilation of package-info.java in the test-compile phase. Here a sample :
<profile>
<id>m2e</id><!--This profile is activated when eclipse interacts with maven (using m2e).-->
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<!--eclipse do not support duplicated package-info.java, in both src and test.-->
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<configuration>
<testExcludes>
<exclude>**/package-info.java</exclude>
</testExcludes>
</configuration>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Eclipse + Maven + Groovy: src/test/groovy directory gets removed after update project configuration

I'm developing a Java web project in Eclipse (STS version 2.8.1.RELEASE) with Maven (version 2.2.1) and unit tests written in Groovy. The unit tests are located under src/test/groovy. Furthermore I'm using the m2eclipse plugin for Eclipse (version 1.0) and the Gmaven plugin in Maven (version 1.3).
Building in Maven works without problems: the groovy files are compiled and executed as tests. For the unit tests to work in Eclipse I added the Groovy nature to the project, added the folder src/test/groovy under Configure Build Path... and set the output folder to target/test-classes.
This works until I do an update of the project configuration under Maven -> Update Project Configuration.... After I do this every time the directory src/test/groovy gets removed from the source folders in Eclipse and I have to add it again and set the output directory.
Is there something I am missing or why is Eclipse deleting my source folder configuration every time I do an update of the project configuration?
My GMaven configuration looks as follows:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<configuration>
<providerSelection>1.7</providerSelection>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
Using the builder-helper-maven-plugin helped. Eclipse adds the source folder and sets the output folder correctly. I used the following configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/groovy</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
I had a similar issue, mine was that eclipse was preventing me from writing groovy files into java folder. But you could try the same configuration out, or check out my whole pom at github
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<!-- Source includes is necessary to allow groovy files in the java
folder, else eclipse will throw a filtering exception -->
<sourceIncludes>
<sourceInclude>**/*.groovy</sourceInclude>
</sourceIncludes>
<!-- Download sources will make maven download and attach source files
where available -->
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
After I put in this configuration in the pom, the .classpath got generated properly.
Check out this issue on SoF here. You need to add the build-helper-maven-plugin to get the resources added.
You need to install the groovy-eclipse configurator for m2eclipse. It is available from this update site:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.7/
If you are using m2eclipse v1.0 or later, then choose to install from here:
m2e Configurator for Groovy-Eclipse (Optional)
If you are using an older version of m2eclipse, then install from here:
Groovy-Eclipse m2eclipse integration pre v1.0 (deprecated)
Try by adding your Groovy source directory.

How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds

I am trying to work with Spring Data and Neo4j. I started by trying to follow this guide linked to by the main site. In particular I based my pom.xml off of the "Hello, World!" example file. Here is a snip from my pom.xml for the plugin that is causing the issues...
<plugin>
<!-- Required to resolve aspectj-enhanced class features -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<outxml>true</outxml>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
</aspectLibrary>
</aspectLibraries>
<source>1.6</source>
<target>1.6</target>
</configuration>
<executions>
<!-- ERROR HERE IN ECLIPSE SEE BELOW FOR FULL MESSAGE -->
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
</plugin>
The error I am seeing is:
Multiple annotations found at this line:
- Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.0:compile (execution: default, phase: process-classes)
- Plugin execution not covered by lifecycle configuration: org.codehaus.mojo:aspectj-maven-plugin:1.0:test-compile (execution: default, phase: process-classes)
I am running Eclipse 3.6.2 and m2e 0.13. I'm not a Maven expert, so please be very explanatory in your answers if possible.
I've also tried m2e 1.0.0 via this update site and still get the same error.
In my case of a similar problem, instead of using Andrew's suggestion for the fix, it worked simply after I introduced <pluginManagement> tag to the pom.xml in question. Looks like that error is due to a missing <pluginManagement> tag. So, in order to avoid the exceptions in Eclipse, one needs to simply enclose all the plugin tags inside a <pluginManagement> tag, like so:
<build>
<pluginManagement>
<plugins>
<plugin> ... </plugin>
<plugin> ... </plugin>
....
</plugins>
</pluginManagement>
</build>
Once this structure is in place, the error goes away.
What a mess. I don't remember where I found this but I had to add the following to get M2Eclipse to be happy. Even more sad is that it isn't exactly easy to understand why this tag is needed.
<build>
... various 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.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>test-compile</goal>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
There were a number of other issues with the M2Eclipse plug-in that simply didn't work with Spring Data. In the end I disabled M2Eclipse in favor of the Apache Eclipse plug-in.
In Eclipse Luna 4.4.0, you can chose to ignore this error in preferences
Window > Preferences > Maven > Errors/Warnings > Plugin execution not covered by lifecycle configuration. Select Ignore / Warning / Error as you wish.
Also, in the quick fix (Ctrl + 1) for this error, it gives an option to
mark goal as ignored in Eclipse build in Eclipse preferences (experimental)
This is a cleaner way, as it doesn't modify your pom.xml.
You will need to do a Maven > Update project to fix the same error in any other project as well.
In STS(Spring-tool-suite), you can choose to ignore this error in preferences
Window > Preferences > Maven > Errors/Warnings > Plugin execution not covered by life-cycle configuration. Select Ignore / Warning / Error as your wish.
Then. Right click the project click Maven and update the project then error will gone.
Suggested solution from Eclipse m2e documentation:
Use quick-fix on the error in pom.xml and select Permanently mark goal run in pom.xml as ignored in Eclipse build - this will generate the required boilerplate code for you.
To instruct Eclipse to run your plugin during build - just replace the <ignore/> tag with <execute/> tag in the generated configuration:
<action>
<execute/>
</action>
Alternatively you can instruct Eclipse to run the plugin on incremental builds as well:
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute >
</action>
See https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html .
To solve some long-standing issues,
m2e 1.0 requires explicit instructions
what to do with all Maven plugins
bound to "interesting" phases of
project build lifecycle. We call these
instructions "project build lifecycle
mapping" or simply "lifecycle mapping"
because they define how m2e maps
information from project pom.xml file
to Eclipse workspace project
configuration and behaviour during
Eclipse workspace build.
Project build lifecycle mapping
configuration can be specified in
project pom.xml, contributed by
Eclipse plugins and there is also
default configuration for some
commonly used Maven plugins shipped
with m2e. We call these "lifecycle
mapping metadata sources". m2e will
create error marker like below for all
plugin executions that do not have
lifecycle mapping in any of the
mapping metadata sources.
Plugin execution not covered by lifecycle configuration:
org.apache.maven.plugins:maven-antrun-plugin:1.3:run
(execution: generate-sources-input, phase: generate-sources)
m2e matches plugin
executions to actions using
combination of plugin groupId,
artifactId, version range and goal.
There are three basic actions that m2e
can be instructed to do with a plugin
execution -- ignore, execute and
delegate to a project configurator.
m2e 0.13 introduce a m2e connectors and m2e Market Place to extend m2e features.
It's like the old m2e-extras repository.
You can access the m2e market place from the preferences: Preferences>Maven>Discovery>Open Catalog.
Installing WTP integration solved most plugin issues for me.
Note that the M2Eclipse (m2e) version 1.7.0 available in today's Eclipse Neon release train supports new syntax for specifying lifecycle mapping metadata. As a result boilerplate like this (here we're telling m2e to ignore the goal):
<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.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<versionRange>[1.5.0,)</versionRange>
<goals>
<goal>exec</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
can be replaced with a single line in the plugin's execution node:
<?m2e ignore?>
See the release notes for details.
Change the Maven preferences for plugin execution from error to ignore
As an addendum to the previous answers -- there's a workaround I just discovered for if you can't or don't want to add all this boilerplate to your project POM. If you look in the following location:
{Eclipse_folder}/plugins/org.eclipse.m2e.lifecyclemapping.defaults_{m2e_version}
You should find a file called lifecycle-mapping-metadata.xml where you can make the same changes described in the other answers and in M2E plugin execution not covered.
I had the same problem with Eclipse v3.7 (Indigo) and m2eclipse as my Maven plugin. The error was easily solved by explicitly stating the execution phase within the plugin definition.
So my pom looks like this:
<project>
...
<build>
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<timestampFormat>yyyy-MM-dd_HH-mm-ss</timestampFormat>
</configuration>
<executions>
<execution>
*<phase>post-clean</phase>*
<goals>
<goal>create-timestamp</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
...
Go to Help > Install New Software...
Use this software repository
Make sure "Contact all update sites during install to find required software" is checked.
Install the AJDT m2e Configurator
Source: Upgrading Maven integration for SpringSource Tool Suite 2.8.0 (Andrew Eisenberg)
This should automatically install ADJT if you don't have it installed, but if it doesn't, install AspectJ Development Tools (ADJT) first from "Indigo update site" (according to your Eclipse version).
More info on AspectJ Development Tools site.
Goto workspace/rtc-ws/.metadata/.plugins/org.eclipse.m2e.core/lifecycle-mapping-metadata.xml then create lifecycle-mapping-metadata.xml file and paste below and reload configuration as below
If you are using Eclipse 4.2 and have troubles with mapping and won't put mess into yours pom.xml create new file lifecycle-mapping-metadata.xml configure it in Windows -> Preferences -> Lifecycle mapping (don't forget press Reload workspace lifecycle mappings metadata after each change of this file!). Here is example based on eclipse/plugins/org.eclipse.m2e.lifecyclemapping.defaults_1.2.0.20120903-1050.jar/lifecycle-mapping-metadata.xml
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<goals>
<goal>create-timestamp</goal>
</goals>
<versionRange>[0.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<goals>
<goal>list</goal>
</goals>
<versionRange>[0.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.zeroturnaround</groupId>
<artifactId>jrebel-maven-plugin</artifactId>
<goals>
<goal>generate</goal>
</goals>
<versionRange>[0.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<goals>
<goal>compile</goal>
</goals>
<versionRange>[0.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<goals>
<goal>copy-dependencies</goal>
<goal>unpack</goal>
</goals>
<versionRange>[0.0,)</versionRange>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<versionRange>[1.7,)</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<versionRange>[2.8,)</versionRange>
<goals>
<goal>check</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
I fixed it following blog post Upgrading Maven integration for SpringSource Tool Suite 2.8.0.
Follow the advice on the section called "Uh oh…my projects no longer build". Even when it's intended for SpringSource Tool Suite I used it to fix a regular Eclipse installation. I didn't have to modify my pom files.
I've had the same problem with indigo and a project that needs to generate Java sources from XSD.
I could fix it by supplying the missing life-cycle mapping, as described on this page
This error happens also on neon because of missing m2e connector.
Solution:
hover error and select - Discover new m2e connectors.
It will install new connector and that is it.
Use m2e 0.12, last version from Sonatype.
Where find WTP:
Mouse down on < plugin > in pom.xml and 'Discover new m2e connectors'.
I installed them all what are default checked and it works.
I had the exact same problem after updating m2e and solved it by reinstalling Maven Integration for Eclipse WTP.
As it turns out, I uninstalled it trying to update m2e from version 0.x to 1.x
I was using
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>runSomeAntTasks</id>
<phase>test-compile</phase>
.
.
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
and changed it to
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>runSomeAntTasks</id>
<phase>integration-test</phase>
.
.
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
and the error went away. Maybe it's not recommended to bind an execution to the test-compile phase so finding a different phase might be an alternate solution to adding plugin-management configuration to the maven lifecycle.
I had this problem today. I was using STS 3.4 with its bundled Roo 1.2.4. Later I tried with Eclipse Kepler and Roo 1.2.5, same error.
I've changed my pom.xml adding pluginTemplates tag after build and before plugins declaration but didn't work.
What made the magic for me:
Using jdk 1.7.0_51
Downloaded Roo 1.2.5
Downloaded Maven 3.2.1 (if not, when executes "perform eclipse" this error appears "error=2, no such file or directory")
Configured JDK, Roo and Maven bin directories on my PATH:
export PATH=/opt/jdk1.7.0_51/bin:$PATH
export PATH=/opt/spring-roo-1.2.5.RELEASE/bin:$PATH
export PATH=/opt/apache-maven-3.2.1/bin:$PATH
Made my configuration as following:
(http://docs.spring.io/spring-roo/reference/html/beginning.html)
$ mkdir hello
$ cd hello
$ roo.sh
roo> project --topLevelPackage com.foo
roo> jpa setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT
roo> web mvc setup
roo> perform eclipse
Open with Eclipse (nothing of STS, but I guess it works): Import -> Existing Projects into Workspace
Changing
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.2</version>
into
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.3</version>
solved the problem for me.
I encountered exact the same problem with maven thrift plugin. Here's my solution which requires no need to mess up your pom.xml:
Use command line maven utility mvn
mvn eclipse:eclipse
to create a eclipse project
Import the project in eclipse. Remember to use
File > Import > General > Existing Projects into Workspace
to add the project into your workspace.
This should fix the problem.
This answer is just as good the top plugin-management answer above (which is to say, it's terrible).
Just delete all the offending xml code in the pom.
Done. Problem solved (except you just broke your maven config...).
Devs should be very careful they understand plugin-management tags before doing any of these solutions.
Just slapping plugin-management around your plugins are random is likely to break the maven build for everyone else just to get eclipse to work.
Instead of messing up your pom file, I would suggest you to go to Show View → Markers in Eclipse, select and delete the markers of appropriate errors.
If you are using Eclipse Juno, it could be the issue of Maven Integration For Eclipse WTP . So install the same from Eclipse Market Place.
In Eclipse IDE
Help>>Eclipse Market Place >> type the query wtp and it will show maven integration for eclipse WTP for Juno, install it and update the maven dependencies and enjoy
I got the same error. After doing the following it went away.
Right click on the project.
Select Maven > Update Project...
you can suppress this error in eclipse:
Window -> Preferences -> Maven -> Error/Warnings
I encountered this using Eclipse v4.3 (Kepler) and Maven 3.1.
The solution is to use a JDK and not a JRE for your Eclipse project. Make sure to try maven clean and test from Eclipse just to download missing JAR files.
I followed the GUI hint to finding any connector, and then I found AspectJ Integrator from SpringSource Team. After installation, it was settled.
Most of the answers are about just ignoring error and other suggested solutions doesn't work in my case [for maven-compiler-plugin]. My solution to this problem:
Go .m2 local repository in your system and find org.apache.maven.plugins directory:
C:\Users\[YOUR USERNAME]\.m2\repository\org\apache\maven\plugins
Remove maven-compiler-plugin folder from this directory
You may have to close your IDE (Eclipse)
After that open the IDE again and update project by Maven
In Eclipse right-click on the project root and choose Maven -> Update project...