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>
Related
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.
I'm using maven-bundle-plugin to generate MANIFEST.MF for OSGi container.
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>com.example.mypackage</Export-Package>
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
However, that manifest file got destroyed (overwritten) by Eclipse (4.6.1 Neon) after, f.g Maven/Update Project or Clean/Build.
Is it possible to make Eclipse somehow aware of the maven plugins, and not destroy their output? What should I setup to prevent that (mis)behaviour?
If that issue is not to be fixed with Eclipse, does it work better with IntelliJ, for example? OSGi support within IDE is quite important for me...
I have to change my answer. I missed the part that you define the goal manifest. This is the new and recommended way to use the maven bundle plguin but it requires that you tell the jar plugin to use the existing Manifest.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
old answer
I suspect you are using the Eclipse PDE. The PDE is always working Manifest first. This means it is incompatible with the maven-bundle-plugin.
I recommend to use a plain maven build which we use a lot at apache projects like Apache Karaf or Apache Aries. It lacks the special OSGi support of Eclipse PDE but this sucks anyway.
You can augment this by using the eclipse plugin bndtools. Bndtools now provides maven support to a degree. This means you can now provide maven based OBR indexes for your project and define which bundles to start in a bndrun file. This allows to directly start and debug your OSGi project in Eclipse. See the osgi-chat example on how to do it.
Beware though that bndtools just started with maven support recently. So the current version 3.3.0 still lacks some of the convenience for maven builds.
With my configuration:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.3.0</version>
<extensions>true</extensions>
<configuration>
<manifestLocation>src/main/resources/META-INF</manifestLocation>
<rebuildBundle>true</rebuildBundle>
<instructions>
<Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName>
</instructions>
</configuration>
</plugin>
And the Plugins installed:
m2e Connector: http://download.eclipse.org/m2e-wtp/releases/neon/
BND Tools: http://bndtools.org/
The Eclipse build finally didn't destroy the manifest file. But there were some iterations(maven build, Update Maven Dependencies, Eclipse Build, maven build) necessary. Also beforehand, I deleted all project related settings on the filesystem: .classpath, .project, .factorypath, .settings, .apt_generated, target. Hope that helps.
From reading A Java web project created with Maven is not recognized as such by Eclipse
I add the below plugin to pom.xml to convert my maven project to a web project :
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpmanifest>true</wtpmanifest>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
</plugin>
I then run "Update Project Configuration" but the maven project is not converted to a web project.
If I run the command mvn eclipse:eclipse -Dwtpversion=2.0 the project is then updated. Should updating the .pom file not suffice to convert the maven project to a web project ?
It will not suffice. The plugin configuration needs to be executed, which will not happen by just loading/refreshing it in Eclipse. It gets executed when mvn eclipse:eclipse is run.
I assume we do not have m2e, which does not need this configuration anway.
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
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!