Jacoco Maven Plugin - Plugin execution not covered by lifecycle configuration - maven

I'm new to Maven and want to use the Jacoco Maven Plugin to build my projects.
I've set up an example project with TestNG the only dependency.
Here is part of the pom.xml:
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.2.201302030002</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
And i get this error:
Plugin execution not covered by lifecycle configuration: org.jacoco:jacoco-maven-
plugin:0.6.2.201302030002:prepare-agent (execution: default, phase: initialize)
What am I doing wrong ?
Cheers

You can ignore the plugin goal, adding something like this to your pom.xml
<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.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<versionRange>[0.5,)
</versionRange>
<goals>
<goal>prepare-agent</goal>
</goals>
</pluginExecutionFilter>
<action>
<!-- m2e doesn't know what to do with jacoco,
let's ignore it or annoying error markers appear
see http://wiki.eclipse.org/M2E_plugin_execution_not_covered
-->
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>

As this is related to the Eclipse Maven plugin, alternatively this can be set locally in Eclipse's preferences. Moving the configuration out of the project's pom file helps the code simple and clean, free of IDE particulars.
Go to Eclipse --> Preferences --> Maven --> Lifecycle Mappings. Add lifecycle-mapping-metadata.xml as the following:
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<versionRange>[0.5,)</versionRange>
<goals>
<goal>prepare-agent</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
Reload the life-cycle mappings file and then Maven --> Update Project

Eclipse now offers a quick fix to disable the warning and save those in user preferences (in Eclipse --> Preferences --> Maven --> Lifecycle Mappings lifecycle-mapping-metadata.xml as noted by #iker-aguayo ) so you don't have to manually create or edit the file. This is useful in cases where you can't update the pom (such as using an open source project where you cannot commit.)

I eventually chose to ignore the plugin and use the CLI mvn command instead for the test with code coverage.
Inside your Eclipse IDE, right click on the red color-marked warning for the
jacoco-maven-plugin. You should three options in the popup to fix the warning, choose to ignore the warning, that would result an automatically generated section in your pom.xml, that started with a line of comments,
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
At a command line, run the mvn command before each checkin, and that should trigger the test goal with coverage,
$mvn clean package

This problem is specific to Eclipse, as outlined on the M2E wiki. Sorry I can't help more than that, as I don't use Eclipse.

Related

Intellij: skipTests flag not recognized

I got the following maven configuration in my pom.xml The skipTests variable is highlighted red by Intellij Ultimate 2018.1 as
Cannot resolve symbol 'skipTests'
But why? This is a common maven environmental variable.
<build>
<plugins>
<plugin>
<!-- exec yarn -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
...
<execution>
<id>yarn-test</id>
<phase>process-test-classes</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>yarn</executable>
<skip>${skipTests}</skip>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
I solved the issue by putting the intellij ignore comment
<!--suppress MavenModelInspection -->
on that particular pom line.
Try to restart Intellij Idea, sometimes the errors disappear only when you restart it. If that doesn't work, try to change the version of your Maven.
EDIT
Check this link, I think that will help you How to disable pom.xml validation in IntelliJ IDEA

Regarding updating pom file

I am working on a continuous integration tool and here i need to integrate jacoco plugin after checking out. I do not want to enforce developer to add jacoco plugin while checkin instead i would like to add it while running the jenkins based continuous integration tool.
Is it possible to achieve any of these options?:
1. to modify the pom file checked in by the developer and inject the dependency and plugin required for jacoco?
OR
to add the jacoco plugin super pom and mention that in jenkins configuration.
I tried this super pom approach, and it was reading super pom from a common repository, but not generating jacoco-exec file. I used below in super pom.
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
pom
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<configuration>
<destFile>${basedir}/target/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any help will be appreciated. Thanks
You can create a separate profile in the pom.xml, name it as jenkins profile and include jacoco plugin in that profile. You can then configure the mvn command in your jenkins job to include -P jenkins_profile_name. So the build would be done using the jenkins profile configuration.
Mark the existing profile as default and developers won't need to do anything specific.
For more details, refer to maven documentation for build profiles:
http://maven.apache.org/guides/introduction/introduction-to-profiles.html

appengine-maven-plugin not auto deploying code after code changes

I've a appengine maven project which uses the newly recommended module structure. So I've a ear module which in turn contains 2 war sub modules. I'm using run mvn appengine:devserver from ear directory to run the code. I want maven to deploy any code change as soon as I save it so I can refresh the browser and see the changes but that doesn't seem to work. Here's my ear pom.
target/${project.artifactId}-${project.version}/*/WEB-INF/classes
org.apache.maven.plugins
maven-ear-plugin
2.8
5
lib
war
com.google.appengine
appengine-maven-plugin
${appengine.target.version}
2
<dependencies>
<dependency>
<groupId>com.blah.app</groupId>
<artifactId>A</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.blah.backend</groupId>
<artifactId>B</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
Following the recommendation on https://developers.google.com/appengine/docs/java/tools/maven I've added in the buildOuputput directory under build directive and also specified
<configuration>
<fullScanSeconds>2</fullScanSeconds>
</configuration>
under appengine-maven-plugin plugin. I've also enabled compile on save option in netbeans but maven doesn't seem to be scanning the classes folder and deploying the changes while devappserver is running.
Right now I'm stuck in clean build/deploy cycle for every small change. I'd really appreciate any help on this.
I managed to get it working in Eclipse by calling war:exploded from compile phase and adding a mapping in m2e configuration, so that it runs it in incremental builds in Eclipse. I am not sure how that would work in Netbeans, but maybe my solution for Eclipse will help you.
Here are the relevant portions of my pom:
This is the part that configures war:exploded execution:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<archiveClasses>true</archiveClasses>
<webResources>
<!-- in order to interpolate version from pom into appengine-web.xml -->
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
This is the part configures m2e (it goes in the build section of pom.xml):
<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.apache.maven.plugins
</groupId>
<artifactId>
maven-war-plugin
</artifactId>
<versionRange>
[2.4,)
</versionRange>
<goals>
<goal>
exploded
</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>true</runOnConfiguration>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>

OSGi and Virgo tools : impossible to add a maven project (using bnd maven plugin)

I'm new to OSGi, coded only a few bundles and deployed them manually.
Some friends of mine told me about Virgo and Virgo tools, which allows you to auto-deploy bundles you manage with eclipse.
I'm currently trying to set all this up. I have virgo-tomcat-server-3.5.0.RELEASE, along with virgo tools 1.0.0, all of this installed on a Spring Tool Suite 3.1.0.RELEASE (in case you don't know, this last one includes the m2eclipse plugin).
My bundle is a maven project. It uses the bnd plugin and here's its configuration
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>fr.tpepio.mtg.model</Export-Package>
</instructions>
</configuration>
<executions>
<execution>
<id>build-manifest</id>
<phase>compile</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
You can see that I export only one package. I also try to make m2eclipse to dynamically generate my manifest.mf file when eclipse compiles my classes.
I finally get to the issues I'm facing.
Since I import my bundle as a maven project into STS, I have to add the Virgo facet to it. And as soon as I update my maven configuration, it kind of screws my projects and I get the following error :
Java compiler level does not match the version of the installed Java project facet.
Appart from my (shitty) maven configuration, I have found myself unable to add my project into the virgo server, which endlessly tells me
null reason : null
Does someone has any clue ?
Hurray ! Problems solved.
First : about the java compiler and facet's java version. Telling maven that your sources are coded in 1.6, and must be compiled in 1.6 will resolve the problem. Code is the following :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<inherited>true</inherited>
<configuration>
<verbose>false</verbose>
<encoding>${java.compiler.encoding}</encoding>
<fork>true</fork>
<source>${java.compile.version}</source>
<target>${java.compile.version}</target>
</configuration>
I still don't understand why it resolves this problem, since both my project configuration and STS configuration could only use java 6... I believe this is because my sources where compiled as 1.5 java sources.
Second : adding the maven bundle project to virgo.
Configure correctly bnd, by running its "manifest" goal in the right maven phase (e.g. : after your classes have been compiled), and tell him where he can find the manifest. This solves the "null reason : null" issue (maybe virgo should have said : "could not find manifest.mf... ?).
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-ClassPath>.</Bundle-ClassPath>
<Export-Package>
[packages you want to export]
</Export-Package>
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<manifestLocation>src/main/resources/META-INF/</manifestLocation>
</configuration>
</execution>
</executions>
Add this goal to the m2eclipse lifecycle mapping. This refreshes your manifest after each occurence of the phase you indicated in your bnd configuration (here : the process-classes phases). Otherwise, m2eclipse has no way to understand when it should call your 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>
<!-- Maven Bundle Plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<versionRange>[2.3.7,)</versionRange>
<goals>
<goal>manifest</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
Hope this wil help.

How to tell YUI compressor maven plugin to output to WAR file and/or source directories?

I'm trying to add YUI compressor to my JSF eclipse maven project. I'm not a maven professional, I just use the m2e maven plugin to resolve my dependencies and to right click my project und export it to a .WAR file. At this point, the YUI compressor plugin is working and compresses all css and javascript files as soon as I change and save a resource (i.e. a html file). My problem is, that it's neither putting the compressed files back to MyProject/src/main/webapp/resources/css|js nor into the resulting .WAR file. It puts them into MyProject/target/app-0.01-SNAPSHOT/resources/css|js which seems to be of no (?) use. How can I set it up to put the files into the .WAR file and into the original input-directories (so i can see and include them in my html files)? I have read a couple of threads here, but couldn't find the solution.
Here is the relevant part from my pom.xml:
<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<!-- I was playing around with this. At this point, the following does the same as the default
setting, i.e. putting the files into the /target/ directory, which is not what i want/need. -->
<configuration>
<sourceDirectory>${project.basedir}/src/main/webapp/resources/js</sourceDirectory>
<outputDirectory>${project.build.directory}/${project.build.finalName}/resources/js</outputDirectory>
</configuration>
</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>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<versionRange>[1.3.0,)</versionRange>
<goals>
<goal>compress</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

Resources