How do I configure the Maven WAR plugin to execute the "inplace" goal by default? - maven

I’m using Maven 3.2.3 and the Maven War 2.6 plugin. I would like the “inlace” goal of the Maven WAR plugin to execute by default (without my having to explicitly specify “war:inlace” on the command line). So I created a profile to include the below
<profile>
<id>dev</id>
<activation>
<property>
<name>!flag</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}/src/main/webapp/WEB-INF/classes</directory>
</fileset>
<fileset>
<directory>${project.basedir}/src/main/webapp/WEB-INF/lib</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<useCache>true</useCache>
<workDirectory>/tmp/${project.artifactId}/war/work</workDirectory>
</configuration>
<goals>
<goal>inplace</goal>
</goals>
</plugin>
</plugins>
</build>
</profile>
Using “mvn help:active-profiles”, I have verified this profile is being used when I run “mvn clean install” on my WAR project. However, the WAR is not assembled in place. For instance, I get the output
[INFO] Packaging webapp
[INFO] Assembling webapp [myproject] in [/Users/davea/Dropbox/workspace/myproject/target/myproject]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/davea/Dropbox/workspace/myproject/src/main/webapp]
[INFO] Webapp assembled in [17460 msecs]
Also I notice there are no “classes” or “lib” resources in my src/main/resources/WEB-INF folder. What do I need to configure differently to get my WAR to be built in-place?

This can probably be classified as a duplicate of How to get Maven to run war:exploded but not war:war with a small twist. Instead of exploded it needs to be inplace:
<pluginManagement>
<plugins>
<plugin>
<!-- don't pack the war -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<!-- optional, depends on your setup -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
<executions>
<execution>
<id>default-war</id>
<phase>none</phase>
</execution>
<execution>
<id>war-inplace</id>
<phase>package</phase>
<goals>
<goal>inplace</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
<pluginManagement>

The WAR Plugin is responsible for collecting all artifact dependencies, classes and resources of the web application and packaging them into a web application archive.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
</plugin>

Related

How do I create an additional jlink artifact on my jar project?

Using the maven-jlink-plugin, I want to create an additional jlink zip file.
I have configured it like so:
<profile>
<id>jlink</id>
<build>
<plugins>
<!-- to be able to package the application using jlink, all dependencies MUST have a module-info.java. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jlink-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>create-runtime-image</id>
<phase>package</phase>
<goals>
<goal>jlink</goal>
</goals>
<configuration>
<launcher>memeforcehunt=memeforcehunt.app/io.github.alttpj.memeforcehunt.app.cli.MemeforceHuntApp
</launcher>
<modulePaths>
<modulePath>${project.build.directory}/modules</modulePath>
</modulePaths>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
But when I try to execute mvn package -Pjlink, I get an error message: There is already an artifact attached to the project.
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.657 s
[INFO] Finished at: 2020-12-17T14:33:04+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jlink-plugin:3.0.0:jlink (create-runtime-image) on project memeforce-app: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them. -> [Help 1]
But I cannot add a classifier to the jlink-plugin?
Tag request
maven-jlink-plugin => maven-jlink-plugin
This was a known issue, reported in MJLINK-49 and MJLINK-26, and solved via MJLINK-52 - classifier support. This will be available in version 3.1.0.
Solution for the upcoming 3.1.0 version
Just add a classifier. It will be supported.
Workaround for pre-3.1.0 versions
However, you can create the archive using a workaround.
Change your packaging to <packaging>jlink</packaging> and add a jar execution:
<packaging>jlink</packaging>
<!-- … -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>create-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>appjar</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugins>
</build>
You will get two artifacts out of your project:
groupId:artifactId:version:jlink
and
groupId:artifactId:version:jar:appjar
Please note that the jar will now have a classifier.
Tag request
maven-jlink-plugin => maven-jlink-plugin

Integrate jQAssistant in Maven build using profile and running server

I'm trying to integrate jQAssistant into my existing Maven build. I have a hierarchy of POMs, but basically the top POM defines what the build does. That's where I have my <pluginManagement> and my build plugins that are always used. I also have a couple of Maven profiles for special builds.
So, I want to scan all classes during build time and aggregate the results into a running server to have a fully populated Neo4J database after the build of all my Maven modules. The database should contain my whole code base.
Analysing and checking would be a different step, I don't want to do that directly when building a Maven module.
The examples I see all build a local database and then check the classes against it. As far as I understand it, I would have to run the server as a daemon and then configure the Maven plugin to use the 'bolt' URI to populate it - is this right?
Also, since I don't want to slow down the 'normal' build, I added a Maven profile to active the jQAssistant scan. However, this only works on my top POM, but doesn't work in any other Maven project/module. The inheritance of profiles is a normal and expected Maven feature - so what am I doing wrong?
Here's my parent POM. Just to see whether the profile is active, I added PMD as well:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<groupId>foo</groupId>
<artifactId>parent</artifactId>
<version>1.50.0-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
</plugin>
</pluginManagement>
</build>
<profile>
<id>architecture</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</project>
When I run mvn clean package -P architecture on a Maven project with that parent POM, I see the following output, which shows that the profile is active:
09:30:12.316 [INFO]
09:30:12.316 [INFO] --- maven-pmd-plugin:3.5:pmd (default) # util-type ---
09:30:15.073 [INFO]
09:30:15.073 [INFO] --- maven-pmd-plugin:3.5:cpd (default) # util-type ---
09:30:15.976 [INFO]
However, jqassistant-maven-plugin is nowhere.
Now, if I add it to my normal <build> plugins:
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
then I see the following output for mvn clean package for my parent POM:
10:38:14.252 [INFO] --- jqassistant-maven-plugin:1.5.0:scan (scan) # parent ---
10:38:15.684 [INFO] Loaded jQAssistant plugins [CDI, Common, Core Analysis, Core Report, EJB3, GraphML, JAX-RS, JPA 2, JSON, JUnit, Java, Java 8, Java EE 6, Maven 3, OSGi, RDBMS, Spring, TestNG, Tycho, XML, YAML].
10:38:15.952 [INFO] Connecting to store at 'file:/C:/jp/maven-parents/parent/target/jqassistant/store/'
10:38:20.058 [INFO] Initializing embedded Neo4j server 3.x
10:38:20.078 [INFO] Resetting store.
10:38:21.515 [INFO] Reset finished (removed 8453 nodes, 29427 relations).
10:38:22.372 [INFO] Entering C:/jp/maven-parents/parent/target/failsafe-reports
10:38:22.378 [INFO] Leaving C:/jp/maven-parents/parent/target/failsafe-reports (1 entries, 4 ms)
However, in my Maven project, I don't see any jQAssistant output.
Starting mvn help:effective-pom -Parchitecture gives me the same output for the parent project and the Maven module:
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>pmd</goal>
<goal>cpd</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
<configuration>
...
</configuration>
</plugin>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
</execution>
</executions>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
</plugin>
In my projects I have a parent POM with the following plugin management section:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<version>${jqassistant.version}</version>
<configuration>
<useExecutionRootAsProjectRoot>true</useExecutionRootAsProjectRoot>
</configuration>
<executions>
<execution>
<id>scan</id>
<goals>
<goal>scan</goal>
</goals>
</execution>
<execution>
<id>analyze</id>
<goals>
<goal>analyze</goal>
</goals>
<configuration>
<failOnSeverity>MAJOR</failOnSeverity>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
I also defined the following profile, which I use to run jQAsssistant:
<profile>
<id>verify-architecture</id>
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
Using mvn -P verify-archicture clean install I can scan and analyze my projects.
Here we are, some years later :-)
And coming back to my mistake!
The problem here was the Maven phase. The jQAssistant plugin Mojo scan has the Maven phase post-integration-test by default.
However, we never do mvn clean install in my company, we only do mvn clean package and install using Jenkins, Nexus etc. etc.
So, it was my fault to not force the plugin to the package phase.
That's how it works:
<profile>
<id>jqassistant</id>
<build>
<plugins>
<plugin>
<groupId>com.buschmais.jqassistant</groupId>
<artifactId>jqassistant-maven-plugin</artifactId>
<executions>
<execution>
<id>scan-software</id>
<phase>package</phase>
<goals>
<goal>scan</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Clear local maven repository via maven-plugin on install phase

I'd like to delete the content of my entire repository (.m2/repository) before the installation phase. Of course I don't want to do it by hand so I am looking for a plugin which does the magic. So far I came across maven-clean-plugin and I am trying to use it as follows:
<build>
<sourceDirectory>src/</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filesets>
<fileset>
<directory>${settings.localRepository}/</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
<executions>
<execution>
<id>auto-clean</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I expect this to wipe out the entire repository before downloading the new artifacts, and finally to remove the target folder from the modules. Removal of target folders works, however the wiping out the repository is kinda not working. It does wipe out the repository, however then maven complains about some artifacts required are missing so the compilation fails and returns such errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.3:resources (default-resources) on project com.google.protobuf: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.3:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:2.3 or one of its dependencies could not be resolved: Could not find artifact org.apache.maven.plugins:maven-resources-plugin:jar:2.3 -> [Help 1]
I feel like I am pretty close to the solution. Probably I just need to tweak the parameter tags of the plugin.
Could anyone give an idea?
If you clean the entire local repository you also delete all plugins which are needed by maven and was downloaded before clean runs. You should use the dependency plaugin for delteing only jars which are dependecies of your Project:
mvn dependency:purge-local-repository
In pom you can use it like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>purge-local-dependencies</id>
<phase>clean</phase>
<goals>
<goal>purge-local-repository</goal>
</goals>
<configuration>
<resolutionFuzziness>groupId</resolutionFuzziness>
<includes>
<include>org.ambraproject</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>

JaCoCo not generating jacoco.exec until after skipping JaCoCo execution

I'm having trouble generating AHP reports via JaCoCo in one of my modules. When the build starts, I see JaCoCo correctly setting argLine with:
[INFO] jacoco.agent.argLine set to -javaagent:<...>/.m2/repository/org/jacoco/org.jacoco.agent/0.7.2.201409121644/org.jacoco.agent-0.7.2.201409121644-runtime.jar=destfile=<...>/target/jacoco.exec
However, the .exec hasn't been created yet by the time maven tries to run JaCoCo:
[INFO] Skipping JaCoCo execution due to missing execution data file:<...>/target/jacoco.exec
The jacoco.exec does eventually get created, after maven has skipped JaCoCo execution. Therefore, I can still generate AHP reports, if I re-run the build without cleaning.
I've seen in various other questions that I need to be careful using Maven Surefire with JaCoCo. However, I don't explicitly use argLine in my Surefire plugins, or in any plugin for that matter. I'm starting to wonder if one of the other plugins is hijacking the argLine parameter automatically like JaCoCo does.
Here is a list of all plugins used:
jacoco-maven-plugin
vertx-maven-plugin
maven-resources-plugin
maven-dependency-plugin
maven-surefire-plugin
maven-failsafe-plugin
maven-surefire-report-plugin
maven-assembly-plugin
I do see one suspicious message in the build output:
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) # <module> ---
[INFO] Changes detected - recompiling the module!
I'm not sure if that's relevant, but it appears twice before the Skipping message, and doesn't appear in a module where JaCoCo works properly.
Any ideas?
*edit - Here's the jacoco config
<plugins>
<...>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</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>
<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.7.2.201409121644,)
</versionRange>
<goals>
<goal>prepare-agent</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
I'm not sure exactly what that plugin management part is doing, but commenting it out doesn't fix anything. I've also tried putting the JaCoCo plugin config above the surefire/failsafe config in case order mattered for plugins sharing the same goals, but that didn't help either.
*edit 2 - Looks like the problem was surefire's includes. Commenting them out somehow fixes JaCoCo's .exec generation, and JaCoCo works properly.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<!-- <includes>
<include>**/unit/**/*Test*.java</include>
</includes> -->
</configuration>
</plugin>
Anyone know why?
Just an addition to the answers already given.
It could happen that in your maven-surefire-plugin configuration you already use the argLine configuration to override something like the memory used. If you do so the argline set by jacoco-maven-plugin will not be used failing to generate the jacoco report.
In this case assign a property name to the jacoco-maven-plugin config and then reference it in your maven-surefire-plugin argLine parameter.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<!-- prepare agent for measuring unit tests -->
<execution>
<id>prepare-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<append>true</append>
<destFile>${sonar.jacoco.reportPath}</destFile>
<!-- Sets the VM argument line used when unit tests are run. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
</executions>
</plugin>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<printSummary>false</printSummary>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<argLine>${surefireArgLine} -Xmx1024m -noverify</argLine>
</configuration>
</plugin>
To solve this issue I would use the following three steps:
Determine which plugin execution is producing the jacoco.exec file. To do that, you could run Maven with debug logging enabled (mvn -X) and look for the jacoco.agent.argLine property name or its value in the output. You could also have a look at the effective POM (mvn help:effective-pom) in case the relevant configuration comes from the parent POM. Note that my guess is that it's an execution of the maven-failsafe-plugin.
Determine the phase that plugin is executed in. E.g. for maven-failsafe-plugin this would likely be integration-test.
Change the configuration of the JaCoCo plugin so that the report goal is executed later in the build lifecycle. E.g. if the jacoco.exec file is produced in the integration-test phase, you could execute the report goal in the post-integration-test phase.
In my case the solution was what #massimo mentioned, i was overriding memory values inside <surefireArgLine> tag, after i removed the tag it started generating the report and showed code coverage.
for me one of the reason for exec file not getting generated is when i placed the prepare-agent , prepare-package goals inside plugin section of pluginManagement
when i tried the same outside pluginManagement , i was sucessfully able to run the same and jacoco-exec file was generated using mvn clean install command
my pomfile is as below :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mmt</groupId>
<artifactId>jacoco</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>jacoco</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<argLine>-Xms256m -Xmx1524m -XX:MaxPermSize=256m -Duser.language=en</argLine>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</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>
</project>
I did not find any solution, but I did the following:
mvn clean jacoco:prepare-agent install
create file jacoco.exec, but execute mvn sonar:sonar not create File.
Solution:
Step 1:
mvn clean jacoco:prepare-agent install
Step 2:
copy file jacoco.exec from /src/main/resources
Step 3:
Add next plugin on pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${basedir}/target/</outputDirectory>
<resources>
<resource>
<directory>
${basedir}/src/main/resources/ </directory>
<includes>
<include>jacoco.exec</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
<configuration>
<encoding>cp1252</encoding>
</configuration>
</plugin>
Step 4:
mvn clean install
Step 5:
mvn sonar:sonar
READY
Add my section Plugins
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>cp1252</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${basedir}/target/</outputDirectory>
<resources>
<resource>
<directory>
${basedir}/src/main/resources/ </directory>
<includes>
<include>jacoco.exec</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-folder</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<filtering>false</filtering>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
<configuration>
<encoding>cp1252</encoding>
</configuration>
</plugin>
<!-- Plugin Sonar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</version>
<configuration>
<destFile>${project.build.directory}/jacoco.exec</destFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${basedir}/target/jacoco.exec</destFile>
<dataFile>${basedir}/target/jacoco.exec</dataFile>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
I also faced the same problem where jacoco plugin was added to parent pom, and jacoco.exec file was generating for one of the sub modules. I had to remove the argLine arguments of maven surefire plugin, then it got generated.

Maven ear plugin multiple artifacts content

Lets assume that I have a web project and several environments where it could be deployed. And I want Maven to build several artifacts at once (e.g. for dev an prod). I have an A-war module and an A-ear module (which contains A-war). Each war artifact could contain information which is related only to its environment.
First I configured a pom.xml file for A-war module:
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<id>package-prod</id>
<phase>package</phase>
<configuration>
<classifier>prod</classifier>
<webappDirectory>${project.build.directory}/${project.build.finalName}-prod</webappDirectory>
<webResources>
<resource>
<directory>src/env/prod</directory>
</resource>
</webResources>
</configuration>
<goals>
<goal>war</goal>
</goals>
</execution>
<execution>
<id>package-dev</id>
<phase>package</phase>
<configuration>
<classifier>dev</classifier>
<webappDirectory>${project.build.directory}/${project.build.finalName}-dev</webappDirectory>
<webResources>
<resource>
<directory>src/env/dev</directory>
</resource>
</webResources>
</configuration>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<finalName>A-war</finalName>
</build>
This works fine - 2 *war*s are created in target folder: A-war-prod and A-war-dev.
Now I want to build ear artifact for each of these war.
Here is the main content of pom.xml in A-ear module:
<dependencies>
<dependency>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>prod</classifier>
<scope>provided</scope>
<type>war</type>
</dependency>
<dependency>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>dev</classifier>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>package-dev</id>
<phase>package</phase>
<configuration>
<classifier>dev</classifier>
<version>5</version>
<modules>
<webModule>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>dev</classifier>
<contextRoot>/A-war</contextRoot>
<bundleFileName>/A-war.war</bundleFileName>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>
<execution>
<id>package-prod</id>
<phase>package</phase>
<configuration>
<classifier>prod</classifier>
<version>5</version>
<modules>
<webModule>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>prod</classifier>
<contextRoot>/A-war</contextRoot>
<bundleFileName>/A-war.war</bundleFileName>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>A-ear</finalName>
</build>
It also builds 2 ear**s: A-ear-dev.ear and A-ear-prod.ear. And each of these *ear*s contains an A-war.war artifact. And everything would be fine except of one small detail: these **war files are the same. I mean A-ear-dev.ear contains A-war-dev.war (which is renamed to A-war.war) but A-ear-prod.ear contains the same A-war-dev.war instead of its own A-war-prod.war.
Moreover when I'd changed the order of executions (moved creating of prod higher than dev) then these *ear*s both contained A-war-prod.war.
As I can see from maven output, when starting building ear**s it copies the first war into the folder for the first **ear but for the second it does not:
[INFO] --- maven-ear-plugin:2.8:ear (package-dev) # A-ear
---
[INFO] Copying artifact [war:gr.id:A-war:dev:0.0.1-SNAPSHOT] to [/A-war.war]
[INFO] Including custom manifest ....
[INFO] Copy ear sources to ...
[INFO] Building jar: <location>\A-ear\target\A-ear-dev.ear
....
[INFO] --- maven-ear-plugin:2.8:ear (package-prod) # A-ear ---
[INFO] Copy ear sources to ...
[INFO] Including custom manifest file ...
[INFO] Building jar: <location>\A-ear\target\A-ear-prod.ear
So maybe anyone has an idea on how to force maven copy war file each time?
As I found out, when Maven is copying war file into the temp directory, it doesn't rewrite it - if there is a file with the same name, then it will not be replaced. So after the first artifact copying, it copied always the first artifact which is pointed in execution module.
All other artifacts were not copied. So this artifact was placed in all result ears.
So the solution for this issue is to specify working directory for each execution tag, like:
<execution>
<id>package-prod</id>
<phase>package</phase>
<configuration>
<workDirectory>target/prod</workDirectory>
<classifier>prod</classifier>
<version>5</version>
<modules>
<webModule>
<groupId>gr.id</groupId>
<artifactId>A-war</artifactId>
<classifier>prod</classifier>
<contextRoot>/A-war</contextRoot>
<bundleFileName>/A-war.war</bundleFileName>
</webModule>
</modules>
</configuration>
<goals>
<goal>ear</goal>
</goals>
</execution>

Resources