I Am trying to enable Sonarqube code coverage scan. I work on a Maven project in Eclipse and have already setup a successful Jenkins-build including Sonar-scan.
I already succeeded in using Jacoco locally; I added the Jacoco plugin to the pom.xml and executed jacoco:prepare-agent test jacoco:report via Run As-> Maven build.... After that call the html reports were located in target\site\jacoco and they seem to be correct.
Now I need to make it work in Jenkins but I don't know how to correctly configure the build. Currently the maven goal clean package -fae and an Invoke Standalone Sonar Analysis build step are executed.
I found out that sonar.jacoco.reportPath needs do be set, but I don't know where to set it or where to call the jacoco:report target. Also I am unsure whether I need to add the jacoco plugin to jenkins as well, or if it is sufficient to do so in the maven project.
Any help is much appreciated, also please let me know if there is anything I can do to improve my question.
I finally made it work. In case someone has similar issues I am posting my solution here:
In Jenkins the properties sonar.junit.reportsPath and sonar.jacoco.reportPath need to be configured. No additional goals have to be executed in Jenkins.
In the projects pom.xml one needs to specify
<properties>
<jacoco-maven-plugin.version>0.7.4.201502262128</jacoco-maven-plugin.version>
</properties>
<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.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<versionRange>(,0.7.4.201502262128]</versionRange>
<goals>
<goal>prepare-agent</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The goal prepare-agent has to be executed, but it first generates a
Resource Path Location Type Plugin execution not covered by lifecycle configuration
To resolve that, the pluginManagement block is needed, since it ignores the upcoming issues. Here it is evident to use versionRange and not just version, also this specific version is required, later versions are not working here.
Yes you need to install and configure jacoco plugin in jenkins.
Foolow this link which explains it
https://dzone.com/articles/jacoco-jenkins-plugin
Related
I am using BPM Suite 6 to create a git repository and shell project. I am then connecting to the git repo in my Eclipse IDE.
The Pom file created by BPM Suite web GUI includes the kie-maven-plugin. However Eclipse complains that this "Plugin execution not covered by lifecycle configuration".
From Googling this error a bit I have come to understand that this means Eclipse does not understand when to execute this plugin during Eclipse's build process. It also seems that the 'best' way of fixing this issue is to install an m2e connector for the plugin.
Does such a connector exist?
Does not directly answer the question but I found a workaround in the old user forums:
http://drools-moved.46999.n3.nabble.com/rules-users-Drool-6-0-0-Final-2-question-re-kie-maven-plugin-please-td4027117.html
The workaround is to include in your pom some extra information that tells eclipse how to deal with this plugin. If I understand this correctly, this causes Eclipse to execute the plugin only when it builds the project. This is what the workaround ends up looking like:
<build>
<plugins>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.0.3-redhat-6</version>
<extensions>true</extensions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<versionRange>[6.0.0,)</versionRange>
<goals>
<goal>build</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
This is known Eclipse limitation, as it is not so flexible with custom Maven goals. This is the design way eclipse m2 plugin chose to go. You can chose actions like ignore,
This is what Redhat suggests for maven usage:Redhat guide for Maven usage for Developers
Alternate, you can use IntelliJ what handles this just as it is expected by Maven design for usage.
I work on several project which I often have to make maven-install on them.
Is there a way to execute many maven build one after the other on many projects ?
I hope i'm understandable.
Thanks for help
I was too looking for that.
But didn't get satisfied on Creating just a new main maven project and
add all other projects to build as its modules project.
This way I could trigger all the projects builds by triggering just main project build.
But still, that wasn't digestable.
Well, you can script that and use the -f switch of maven to specify which pom to build one after the other...
If you want to stick with maven, you can make a dedicated pom for invoking the sequence of your build by using the maven exec plugin. But this results a naaasty pom. Use it as last resort, because plugins should be used only once in one phase of the maven lifecycle. In certain cases it might be handy, e.g. you want to be able to run your build on different platforms and don't want to script with python, etc..):
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>mvn</executable>
<arguments>
<argument>-DskipTests=true</argument>
<argument>-f</argument>
<argument>${basedir}/relative/path/to/other/module/pom.xml</argument>
<argument>clean</argument>
<argument>install</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>mvn</executable>
<arguments>
<argument>-DskipTests=true</argument>
<argument>-f</argument>
<argument>${basedir}/relative/path/to/some/other/module/pom.xml</argument>
<argument>clean</argument>
<argument>install</argument>
</arguments>
</configuration>
</plugin>
</plugins>
<build>
<pluginManagement>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
<pluginManagement>
I am configuring a multi-module parent child maven project using maven and eclipse m2e, I am using the latest stuff from eclipse Juno SR1 which is m2e 1.2.0
the parent pom uses the enforcer plugin, so the parent pom.xml has the following in its plugin section
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.1.1</version>
<executions>
<!-- Enforce that all versions of a transative dependency must converge. -->
<execution>
<id>enforce</id>
<configuration>
<rules>
<DependencyConvergence />
</rules>
</configuration>
<goals>
<goal>enforce</goal>
</goals>
</execution>
<!-- Black list certain jars -->
<execution>
<id>enforce-banned-dependencies</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>
commons-logging:commons-logging
</exclude>
</excludes>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
Each of the child projects has an error message saying maven-enforcer-plugin (goal "enforce") is ignored by m2e.
What is the meaning of this message?
How do I configure things to get rid of this message?
do I need to configure the eclipse project settings or the pom.xml settings?
The eclipse maven plugin runs a projects pom.xml file in order figure out how the maven project is configured and translate the maven pom.xml configuration into an eclipse configuration. A pom.xml can reference an arbitrary number of maven plugins and each of those plugins has the potential to leak memory, or do things that are harmful to eclipse. So by default the m2e eclipse plugin ignores any maven plugins unless those maven plugins have a special m2e plugin connector that tells m2e how to integrate the maven plugin into eclipse. In summary m2e is defending the eclipse JVM process against a buggy maven plugin, by saying that for every maven plugin there needs to be an m2e connector to bridge between maven and eclipse.
So to get rid of the warning I added the following to my plugin management section of the parent pom.xml
<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-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
It seems that org.eclipse.m2e:lifecycle-mappingis a maven plugin designed to hold meta data to communicate with eclipse m2e plugin when it processes a maven pom.xml and this information is used to tell eclipse what do with maven plugins that are defined in pom.xml when eclipse runs the pom.xml as part of the eclipse UI.
From m2e version 1.4 and higher:
You can integrate the needed lifecycle-configuration within the pom (parent-pom or project-pom) or you can integrate the informations into the global m2e-configuration within eclipse.
Also you have some quickfix-actions for applying this changes.
The last option is to look for m2e-connectors or to switch over to newer versions of different maven-plugins with integrated m2e-support (e.g. for jaxb-plugins).
Here (for enforcer-plugin) I think, the definition in the pom is the easiest way.
See also: https://www.eclipse.org/m2e/documentation/m2e-execution-not-covered.html
Just an FYI for those of you that have an issue with configuring your IDE in your build model. Keep an eye on this enhancement request currently targeted for the Kepler release:
Bug 350414: Store ignored m2e connectors outside project pom.xml
https://bugs.eclipse.org/bugs/show_bug.cgi?id=350414
For me it was similar issue
I had maven 3.0.3 and java 1.5
and my pom had
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>[3.0.3,2.2.1,)</version>
</requireMavenVersion>
<requireJavaVersion>
<version>[1.7, 1.8)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
As you can see I dont really have met rules, hence I updated Java and got mvn going and I was all set. Hope this helps someone.
Another pitfall exists when having several pluginExecutionFilters. These must be at the right spot in the pom.xml! For me it was gnarly to find as no error or warning of the displacement existed.
This is the right code for having several pluginExecutionFilters:
<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-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action><ignore/></action>
</pluginExecution>
<!-- now here follows the new filter -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.googlecode.maven-java-formatter-plugin</groupId>
...
How to eliminate the “maven-enforcer-plugin (goal ”enforce“) is ignored by m2e” warning by eclipse?
Although the eclipse lifecycle-mapping plugin has worked for me on other projects, I can't change the pom.xml since I am currently working in an IntelliJ shop with my covert instance of Eclipse and I don't want to expose myself by changing all of their pom files to include anything from group org.eclipse.m2e.
After some experimentation, I've found that you can get this warning to not show up by changing the Lifecycle Mappings in the Maven preferences. Frankly I'm not 100% sure what this is doing but I've not seen any side effects so...
In Eclipse, go to: Preferences → Maven → Lifecycle Mappings.
Clicking Open workspace lifecycle mappings metadata which will open the lifecycle-mapping-metadata.xml file in a tab in the background. I assume that this cooresponds to the following file under your workspace subdir:
.metadata/.plugins/org.eclipse.m2e.core/lifecycle-mapping-metadata.xml
Next add the following stanza to the bottom of the file inside of <pluginExecutions>...</pluginExecutions>.
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
Once the XML file is saved you will need to go back to the preferences window and press Reload workspace lifecycle mappings metadata which compiles the file somehow.
Finally you will need to do a maven update-project on all of your projects to see the warnings go away.
Hope this helps.
I am trying to use the maven-warpath-plugin available here. But I keep getting an error in my pom.xml file that says:
Plugin execution not covered by lifecycle configuration: org.appfuse.plugins:maven-warpath-plugin:2.1.0:add-classes (execution: default, phase: generate-sources)
How do I resolve this? Here is my pom.xml snippet for the plugin:
<plugin>
<groupId>org.appfuse.plugins</groupId>
<artifactId>maven-warpath-plugin</artifactId>
<version>2.1.0</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>add-classes</goal>
</goals>
</execution>
</executions>
</plugin>
Eclipse offers me a quickfox tip to "discover new m2e connectors" to resolve this error. I have installed most of the connectors available that seem to apply but the error is still there. Any ideas how I could make this work?
This is the new behaviour of m2e (which replaced the old m2eclipse plugin). To specify what eclipse should do with the plugin you have to configure the build lifecycle mapping in the project's pom.xml - or install a connector (which decides if the plugin needs to be executed in an eclipse build or not) if it exists.
As there seems to be no connector for the maven-warpath-plugin yet you have to define the behaviour in the pom. You can use the second eclipse quickfix for this (Permamnently mark goal add-classes in pom.xml as ignored in eclipse build). This will add the following section to your pom:
<build>
......
<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.appfuse.plugins
</groupId>
<artifactId>
maven-warpath-plugin
</artifactId>
<versionRange>
[2.1.0,)
</versionRange>
<goals>
<goal>add-classes</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
You can change the <ignore> action to <execute> if you want to process the plugin in each eclipse build (on import, clean, ...).
The plugin configuration is eclipse specific and does not make the pom.xml look nicer - but at least it has no influence on the Maven build....
Also see the answer How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds
Error pom.xml: Plugin execution not covered by lifecycle configuration: org.bsc.maven:maven-processor-plugin:3.3.3:process
my project is ProjectA, it's created by maven version 3.3.3 and i used eclipse version 4.5. But when install eclipse version 2021 - 4.20, then I open projectA on eclipse (version 4.20) errors appear in pom.xml: error detail: Plugin execution not covered by lifecycle configuration: org.bsc.maven:maven-processor-plugin:3.3.3:process (execution: process, phase: process-resources)
I don't know why appears on eclipse's new version 4.20. Error appear "execution"
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>3.3.3</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>process-resources</phase>
<configuration>
Thank you very much for help!
I am using eclipse + maven2 to build my applications.
I need to start working with clover.
My question is therefore: from your experience, what is the best way to combine these 3.
I mean, I know there is a clover plugin for eclipse, there is also a clover plugin for maven2 and of course there is maven plugin for eclipse (m2eclipse - which I am already using).
What should I use and how?
Thank you.
Under Eclipse, use the Clover Eclipse Plugin.
Under Maven, use the Maven Clover Plugin. Add a Clover Report to the site generation:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<configuration>
[...]
</configuration>
<executions>
<execution>
<phase>pre-site</phase>
<goals>
<goal>instrument</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
<reporting>
<plugins>
[...]
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<configuration>
[...]
</configuration>
</plugin>
</plugins>
</reporting>
[...]
Optionally, you can check for a test coverage percentage and fail the build in case of non-compliance:
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<configuration>
<targetPercentage>80%</targetPercentage>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>instrument</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The maven build remains the master. Run it using your preferred method (command line or m2eclipse).
I'm using the clover-report along with the automated site generation by maven. For that you just have to add the clover plugin to your POMs reporting section as describes here. That way you can also get a historical report about your code coverage.
Calling/starting the maven process is done via the m2eclipse plugin and that's it. But you could also use all 3 plugins. So for example install the clover plugin for eclipse so that you don't have to generate the whole site again and again when you only want the code coverage (with the clover plugin for eclipse you can see the coverage right inside eclipse) and use the clover maven plugin to generate a "final" code coverage for any released piece of code. The m2eclipse plugin is not really needed for neither clover-maven nor clover-eclipse but it's nice when working with eclipse and maven.