Versions Maven Plugin in Eclipse - eclipse

How can I add the Versions-Maven-Plugin to my Eclipse projects ??
I tried the Add Plugins menu option but it doesn't seem to be able to find the plugin.

To check maven plugin version in eclipse:
Click Window –> Preferences –> Maven –> Installation . It will show you installation window with Maven version.

You have to add the versions maven plugin into the reporting part of your pom to create appropriate reports about dependency updates.
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>1.3.1</version>
<reportSets>
<reportSet>
<reports>
<report>dependency-updates-report</report>
<report>plugin-updates-report</report>
<report>property-updates-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
You can not install the versions-maven-plugin in Eclipse, cause the version-maven-plugin is a Maven plugin and not a Eclipse plugin. But not an bad idea.

Related

Eclipse IDE import maven project error

I have a maven project which work with maven command (for example mvn install)
but when I try to import it into eclipse I got error /complaining about pom.xml
The error message from eclipse is :
Plugin execution not covered by lifecycle configuration: com.google.code.maven-replacer-plugin:replacer:1.5.3:replace (execution: default,
phase: process-sources)
Below is the snippet of pom.xml which eclipse complains
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>src/main/java/com/xyz/Version.java.template</file>
<outputFile>src/main/java/com/xyz/Version.java</outputFile>
<replacements>
<replacement>
<token>#buildtime#</token>
<value>${maven.build.timestamp}</value>
</replacement>
<replacement>
<token>#pomversion#</token>
<value>${project.version}</value>
</replacement>
</replacements>
</configuration>
</plugin>
Any hints will be more than welcome!
Since you have shared incomplete pom , I am assuming , you do not have pluginManagement tag in your pom.xml.
Put your plugin blocks inside pluginManagement tag. E.g.:
<build>
<pluginManagement>
<plugins>
<plugin> ... </plugin>
<plugin> ... </plugin>
</plugins>
</pluginManagement>
</build>
The cause of this error is that Eclipse is unable to match some of the Maven build phases to its own build model, because Maven's is more sophisticated than Eclipse's (In this case, it is the process-sources phase, which some plugin is bound to).
But Eclipse offers a way to ignore this plugin, so that this error won't show up again. Open the POM and set the Overview tab. You should see the error message upside. Pass the mouse over and click on it. A popup must appear showing three options. You may chose between the last two:
Mark goal replace as ignored in pom.xml: If you click on this one, Eclipse will modify the POM file to add some declarations that will make Eclipse ignore this plugin.
Mark goal replace as ignored in Eclipse preferences: Though this one, Eclipse will modify its own configuration (Window > Preferences > Maven > Lifecycle Mappings) to ignore this plugin on every POM, from now on.

Maven and eclipse: remove JRE System Library

I am building a project against the CrEme VM Library. I want to configure maven and eclipse, to build only against this JAR. But m2eclipse "Update Project configuration" automatically adds the "JRE System library". I can fix it, by removing it in eclipse project classpath, but i want to configure it only in the pom.xml (and not checkin the eclipse settings).
I tried to do this:
// ...
<dependency>
<groupId>ch.sbb.cis-infra.mobile</groupId>
<artifactId>vmclasses</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
// ...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.3</source>
<target>1.3</target>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
<debug>off</debug>
<compilerArguments>
<bootclasspath>''</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
But still, m2eclipse adds the "JRE System Library [JRE_1.3]".
Compilation on command line is correct, but in eclipse I can't see compile problems.
How can I remove the JRE in eclipse using the pom.xml configuration?
(Eclipse Helios SR2, m2e plugin 0.12.1)
Well, IMHO (I'm not sure) JRE container in Eclipse is because of Java nature of the project, not the Maven integration. Try to disable Maven nature of the project and JRE will be still there. If you have Maven-managed Java project (and your POM says that) Java nature in Eclipse is enabled causing JRE to be attached to the project.

How to configure maven install to skip tests in eclipse?

Is it possible to configure run as maven install in eclipse to skip unit tests? If so, how can it be done?
Ensure Maven is configured for your project
Right-click on your project
Go to 'Run As'
Select 'Run Configurations'
In the left-hand column, right-click 'Maven Build' and select 'New'
Select the base directory (the project) you want to build from
Write 'install' and any other goals you want in the 'Goals' field
Click the 'Skip Tests' radio button
Click Run!
accordig to maven's document you can write this in you pom.xml:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
It depends on maven test plugin that you use. You can try add parameter -Dmaven.test.skip=true to your build configuration.
You can put the property maven.test.skip in a profile in your pom. And then you activate this profile in eclipse in the project properties of maven in eclipse.
At the Run configurations there is a Maven Build type of Run configuration. At that you could set up the standard Maven skipTests parameter.
Putting this in my Pom.xml turned off the tests for me - but at maven build, not at maven install.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>
</configuration>
</plugin>

what does the wtpversion mean in the Eclipse plugin?

using maven, what does the wtpversion mean in the Eclipse plugin?
wtp adds web application support to eclipse. If you want to develop Maven based web applications with Eclipse, you should rather use Eclipse m2eclipse plugin.
As for wtpversions, this link has a mapping of wtpversion and eclipse versions.
This is the abbreviation of Eclipse Web Tools Project and you can use in maven > pom.xml under the <build> tag:
<!-- Eclipse project -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<!-- Always download and attach dependencies source code -->
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<!-- Avoid type mvn eclipse:eclipse -Dwtpversion=2.0 -->
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
From: How To Create A Web Application Project With Maven

m2eclipse sets JDK compliance to 1.4

Using eclipse 3.5, when I create a new maven project, m2eclipse automatically adds J2SE1.4 to libraries and Compiler Compliance Level to 1.4 (Project properties > Java Compiler).
My JRE system library is 1.6 and my default compiler compliance level is 1.6. I don't even have 1.4 installed.
Can I make m2eclipse use my default settings and prevent it from modifying project settings?
It should follow the maven-compiler-plugin configuration:
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
(even if, as mentioned in this thread, it won't work for aspect-j)
This thread reminds us about the difference between m2eclipse within eclipse, and a maven script:
One thing worth to mention that this only applies to "the development mode" when m2eclipse is configuring Eclipse tools such as JDT, AJDT and WTP according to the configuration from pom.xml. This is how you normally code and debug your application, run unit tests (with Run as... / JUnit test) or run on web app server (Run as... / Server app).
However if you use Run as... / Maven build..., or create corresponding launch config from the Run/Debug menu, then you can select JVM that is used to launch Maven and all your compiler configuration will be respected in the same way it is respected in the command line.
So:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable><!-- path-to-javac --></executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
</plugin>
</plugins>
m2e does not (and cannot) use external java compiler, so it will just ignore these configuration parameters. m2 only considers source/target maven-compiler-plugin parameters.
The JDK compliance level is derived from the maven project, not the other way around. In other words, you need to configure the maven compiler plugin for 1.6 level compliance and then m2eclipse will derive the appropriate settings under Eclipse:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
The pom.xml is the master, not m2eclipse.
In summary I did an mvn eclipse:eclipse on the project and an F5 refresh of the project in Eclipse and this configured the Java compliance setting correctly.
My set-up as follows. Using Kepler. Java 1.7 configured as default in preferences in Eclipse (as mentioned already, seems to be ignored anyway in deference to whatever is found in the pom.xml). I imported a bunch of Maven projects into Eclipse. All showed up as Java compliance level 1.4 and even the build path of the projects lists the Java 1.4 runtime. I double checked 1.7 is correctly specified in the pom.xml by requesting the effective pom on the command line to confirm the setting is present and correct in the pom:
mvn help:effective-pom -Doutput=eff.xml
This showed the correct setting was present:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<fork>true</fork>
</configuration>
</plugin>
Guessing the problem is with the import part of the m2e plugin, version showing in Eclipse is:
1.4.0.20130601-0317