run-forked Does Not Start Jetty Server - maven

I added a jetty-maven-plugin to my build like this:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
<executions>
<execution>
<id>run-jetty</id>
<goals>
<goal>run</goal>
</goals>
<phase>install</phase>
<configuration>
<webAppSourceDirectory>${basedir}/target/repository/</webAppSourceDirectory>
<webApp>
<contextPath>/site</contextPath>
</webApp>
<!-- run only -->
<scanIntervalSeconds>10</scanIntervalSeconds>
<!-- run-forked only -->
<stopPort>9099</stopPort>
<stopKey>stopPlease</stopKey>
<stopWait>10</stopWait>
<waitForChild>false</waitForChild>
</configuration>
</execution>
</executions>
</plugin>
When I run the surrounding Maven project, the Jetty server starts fine and I can browse the webapp at http://localhost:8080/site/
However when I replace the goal run with run-forked I get the following info in the console:
[INFO] --- jetty-maven-plugin:8.1.5.v20120716:run-forked (run-jetty) # project ---
[INFO] Configuring Jetty for project: maven-p2
[INFO] Forked process started
However nothing gets startet at http://localhost:8080/site/. At least there is no webapp there. The OS reports a Java process on port 8080 (two actually) and something listening on 9099 (I guess the stop handler).
I can't seem to figure out how to get run-forked to work as run (just in another JVM). I checked the manual for configuration I'm missing, but couldn't find anything.
mvn jetty:stop works, too and does not print "Jetty not running!", so there is a Jetty somewhere. Just no webapp.
How do I get run-forked to start my webapp?

Updating the Maven plug-in worked, so I guess it's a bug:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.25.v20191220</version>
<configuration>
<supportedPackagings>jar</supportedPackagings>
</configuration>
<!-- Rest of config same as above -->
</plugin>
(Note: I needed to add supportedPackagings additionally to the existing configuration else I got "packaging type [jar] is unsupported".)

Related

Migrating AppEngine application to Java 11 runtime - [http://java.sun.com/jsp/jstl/core] cannot be resolved

So I have an AppEngine application that I'm working on migrating to the Java 11 runtime, and am using the appengine-simple-jetty-main artifact, as outlined in https://cloud.google.com/appengine/docs/standard/java-gen2/war-packaging, to replace the built-in Jetty server of the old Java 8 runtime.
Now if I use mvn jetty:run to bring up my application locally, everything works fine. But when I try to run the appengine-simple-jetty-main wrapper via mvn exec:java -Dexec.args="<my application directory>/target/<application>.war", I hit an issue.
The server starts up fine, and executes various ServletContextListeners that use outside dependencies declared in my pom.xml. I'm also able to navigate to static HTML. When I try to navigate to a JSP Servlet, however, I'm getting the error
HTTP ERROR 500 org.apache.jasper.JasperException: The absolute uri: [http://java.sun.com/jsp/jstl/core] cannot be resolved in either web.xml or the jar files deployed with this application
And likewise, I get this same error when I actually deploy to AppEngine.
As mentioned before, this works just fine when I bypass appengine-simple-jetty-main wrapper using mvn jetty:run, and my pom.xml includes the dependency
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>2.0.0</version>
</dependency>
My build section looks like
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>11.0.11</version>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<deploy.projectId>contra-program</deploy.projectId>
<deploy.version>GCLOUD_CONFIG</deploy.version>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/appengine-staging</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
So I'm a bit flummoxed. Other maven dependencies seem to be getting brought in just fine. It's only the JSTL library that's having issues (so far, at least), and even then, only when I use the appengine-simple-jetty-main wrapper.
The nearest existing question I could find was cannot load JSTL taglib within embedded Jetty server, but I haven't had luck with the provided solutions (though I'm more than happy to admit the possibility that I'm just not applying one or more of them correctly).
Any pointers would be greatly appreciated :-)

Maven: build war but deploy a different artifact?

I have a maven project which builds a WAR and then packs it into a zip file which targets a specific deployment tool. I don't want to upload the WAR as it will be a waste of space.
Is it possible to build the WAR but only upload/deploy the zip in the same pom file?
Edit:
No, the "duplicate" question suggested above does not help the slightest. I have to specify <packaging>war</packaging> and even if I don't, as soon as I use the maven war plugin, it's going to make the war as part of the deployment.
And I also want the other artifacts in the build (source, tests, etc.). I just do not need the war.
Here is a suggested approach to deploy the war or the zip, depending on the need:
The default build will still provide a WAR as output
A profile is added to skip the normal Maven Deploy Plugin execution as part of the deploy phase and add a further execution (obviously not skipped) deploying only the ZIP file via the deploy-file goal, as suggested by #Michal, but not via command line (better as part of the build).
Depending on the need you can of course switch the default behavior from the profile to the default build or even get rid of the default build (just the WAR) at all.
An example:
<build>
<finalName>test-war-zip</finalName>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptor>src/assembly/descriptor.xml</descriptor>
</configuration>
<executions>
<execution>
<id>create-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>deploy-zip</id>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>deploy-zip</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<skip>false</skip>
<file>${project.build.directory}/your.file.here</file>
<repositoryId>your.id.here</repositoryId>
<url>http://something.here</url>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Note the global configuration for the Maven Deploy Plugin and its skip to true. It will effectively skip the deploy goal. A further execution will take care of the ZIP file.
With the approach above, executing the normal build, Maven will keep on deploying the generated WAR, while switching on the profile as following:
mvn clean deploy -Pdeploy-zip
Maven will skip the default execution of the Maven Deploy Plugin (its deploy goal) and execute instead the deploy-file goal during the deploy phase.
As part of the build you will then have:
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) # test-war-zip ---
[INFO] Skipping artifact deployment
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy-file (deploy-zip) # test-war-zip ---
Uploaded: http://the.repository.here (986 B at 3.9 KB/sec)

How to restart JBoss with maven-as plugin before redeploy

I am having headaches trying to setup maven-as-plugin.
My goal is to redeploy an ear before running integration tests.
I want this process to be automatic to integrate it into CI.
The server is a JBoss server (AS 7) running remotely.
Thanks to infamous PermGen space issues of Jboss, I need to restart the server before
deploying the ear. Otherwise, the server will explode every 5 runs or so ...
For that purpose, I have tried to setup a goal "shutdown", with reload=true.
The issue is that maven plugin won't wait for it to be finished before running the next goal (cleaning previous artifacts).
Here is an excerpt of my POM :
<!-- Jboss Deploy/undeploy application EAR -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.5.Final</version>
<configuration>
<!-- JBoss management -->
<hostname>${sanity.tests.jboss.host}</hostname>
<port>${sanity.tests.management.port}</port>
<username>${sanity.tests.jboss.username}</username>
<password>${sanity.tests.management.password}</password>
</configuration>
<executions>
<!-- Reload Jboss to avoid permgen space -->
<execution>
<id>restart</id>
<phase>pre-integration-test</phase>
<goals><goal>shutdown</goal></goals>
<configuration>
<reload>true</reload>
</configuration>
</execution>
<!-- Undeploy previous ear -->
<execution>
<id>undeploy</id>
<phase>pre-integration-test</phase>
<!-- Cleanup : Undeploy -->
<goals>
<goal>undeploy</goal>
</goals>
<configuration>
<matchPattern>rm-app.*.ear</matchPattern>
<ignoreMissingDeployment>true</ignoreMissingDeployment>
</configuration>
</execution>
<!-- Deploy before int test -->
<execution>
<id>deploy</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy-artifact</goal>
</goals>
<configuration>
<name>xxxx</name>
<groupId>xxxxx</groupId>
<artifactId>xxxx</artifactId>
<version>${project.version}</version>
</configuration>
</execution>
</executions>
</plugin>
Any help would be much appreciated.
Try running your undeploy first. If that's the only ear on the AS then the reload will most likely be quick enough for the deploy goal to not timeout.
<goals>
<goal>undeploy</goal>
<goal>shutdown</goal>
<goal>deploy</goal>
</goals>
Unfortunately, I do not know how to increase the timeout of the deploy goal.
I had exactly the same issue. switangs suggestion (first undeploy before restarting JBoss) for sure helps. Another thing i did to add some time between server restart and redeployment was to bind the undeploy and restart of the server to a very early step of the build process (e.g. initialize), whereas the deployment step was bind to process-resources or pre-integration-test as in your case. That worked because i was deploying my artifacts in a separate integration test module, which first copied all relevant server artifacts with maven-dependency-plugin plugin to the ${project.build.directory}/dependency folder as one of the first steps.
But i agree that this is not a very good solution, a blocking restart cli command for standalone JBoss nodes would be much better.
In fact, the shutdown goal won't solve the PermGen issue.
I worked this out by use cli.
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.5.Final</version>
<configuration>
<afterDeployment>
<commands>
<command>/host=master:shutdown(restart=true)</command>
</commands>
</afterDeployment>
<!-- your configuration -->
...
</configuration>
<plugin>
and "master" is the name of host in domain mode.

Getting "Skipping JaCoCo execution due to missing execution data file" upon executing JaCoCo

I'm using Maven 3.0.3, JUnit 4.8.1, and Jacoco 0.6.3.201306030806, and I am trying to create test coverage reports.
I have a project with unit tests only, but I can't get reports to run, I'm repeatedly getting the error: Skipping JaCoCo execution due to missing execution data file when I run:
mvn clean install -P test-coverage
Here is how my pom is configured:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx2048m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
...
<profile>
<id>test-coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<configuration>
<destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</destfile>
<datafile>${basedir}/target/coverage-reports/jacoco-unit.exec</datafile>
</configuration>
<executions>
<execution>
<id>prepare-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- prepare agent for measuring integration tests -->
<execution>
<id>prepare-integration-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<propertyName>itCoverageAgent</propertyName>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
All my tests run successfully. Here is some of the output from Maven:
[INFO] --- jacoco-maven-plugin:0.6.2.201302030002:prepare-agent (prepare-unit-tests) # myproject ---
[INFO] argLine set to -javaagent:/Users/davea/.m2/repository/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002-runtime.jar=destfile=/Users/davea/Dropbox/workspace/myproject/target/jacoco.exec
[INFO]
...
Tests run: 14, Failures: 0, Errors: 0, Skipped: 0
[INFO]
...
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.2.201302030002:prepare-agent (prepare-integration-tests) # myproject ---
[INFO] itCoverageAgent set to -javaagent:/Users/davea/.m2/repository/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002-runtime.jar=destfile=/Users/davea/Dropbox/workspace/myproject/target/jacoco.exec
[INFO]
[INFO] --- maven-failsafe-plugin:2.14.1:integration-test (default) # myproject ---
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO]
[INFO] --- maven-failsafe-plugin:2.14.1:verify (default) # myproject ---
[INFO] Failsafe report directory: /Users/davea/Dropbox/workspace/myproject/target/failsafe-reports
[WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent!
[INFO]
[INFO] --- jacoco-maven-plugin:0.6.2.201302030002:report (jacoco-site) # myproject ---
[INFO] Skipping JaCoCo execution due to missing execution data file
[INFO]
Any ideas what configuration I'm missing?
jacoco-maven-plugin:0.7.10-SNAPSHOT
From jacoco:prepare-agent that says:
One of the ways to do this in case of maven-surefire-plugin - is to
use syntax for late property evaluation:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>#{argLine} -your -extra -arguments</argLine>
</configuration>
</plugin>
Note the #{argLine} that's added to -your -extra -arguments.
Thanks Slava Semushin for noticing the change and reporting in the comment.
jacoco-maven-plugin:0.7.2-SNAPSHOT
Following jacoco:prepare-agent that says:
[org.jacoco:jacoco-maven-plugin:0.7.2-SNAPSHOT:prepare-agent] Prepares a property pointing to the JaCoCo runtime agent that can be
passed as a VM argument to the application under test. Depending on
the project packaging type by default a property with the following
name is set:
tycho.testArgLine for packaging type eclipse-test-plugin and
argLine otherwise.
Note that these properties must not be overwritten by the
test configuration, otherwise the JaCoCo agent cannot be attached. If
you need custom parameters please append them. For example:
<argLine>${argLine} -your -extra -arguments</argLine>
Resulting
coverage information is collected during execution and by default
written to a file when the process terminates.
you should change the following line in maven-surefire-plugin plugin configuration from (note the ${argLine} inside <argLine>):
<argLine>-Xmx2048m</argLine>
to
<argLine>${argLine} -Xmx2048m</argLine>
Make also the necessary changes to the other plugin maven-failsafe-plugin and replace the following (again, notice the ${argLine}):
<argLine>-Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
to
<argLine>${argLine} -Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
I faced a bit of a different issue that returned the same error.
Skipping JaCoCo execution due to missing execution data /target/jacoco.exec
The truth is, this error is returned for many, many reasons.
We experimented with the different solutions on Stack Overflow, but found this resource to be best. It tears down the many different potential reasons why Jacoco could be returning the same error.
For us, the solution was to add a prepare-agent to the configuration.
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
I would imagine most users will be experiencing it for different reasons, so take a look at the aforementioned resource!
One can also get "Skipping JaCoCo execution due to missing execution data file" error due to missing tests in project. For example when you fire up new project and have no *Test.java files at all.
There might a case where some other argline setup or plugin in pom may be overriding jacoco execution order setup.
argLine set to -javaagent:/Users/davea/.m2/repository/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002-runtime.jar=destfile=/Users/davea/Dropbox/workspace/myproject/target/jacoco.exec
One of the example
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<forkCount>5</forkCount>
<reuseForks>true</reuseForks>
<argLine>-Dnet.sf.ehcache.disabled=true</argLine>
</configuration>
</plugin>
After getting rid of argLine from these plugins, jacoco started to work normally.
I know this question is pretty old but if someone like me comes here looking for an answer then this might help. I have been able to overcome the above error with this.
1) Remove the below piece of code from the plugin maven-surefire-plugin
<reuseForks>true</reuseForks>
<argLine>-Xmx2048m</argLine>
2) Add the below goal:
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
I've tried all answers but only the following combination of advice has worked for me. Why? I had very specific requirements:
JaCoCo generates report when build is run from command line: mvn clean verify (Maven 3.6.0)
Intellij IDEA (2019.01) runs my tests as well
It all works in presence of another javaagent defined in surefire plugin
Solution - prepend argLine value in surefire configuration with "late replacement" maven property #{...} as explained in surefire FAQ (my fixed configuration)
How do I use properties set by other plugins in argLine?
Maven does property replacement for
${...}
values in pom.xml before any plugin is run. So Surefire would never see the place-holders in its argLine property.
Since the Version 2.17 using an alternate syntax for these properties,
#{...}
allows late replacement of properties when the plugin is executed, so properties that have been modified by other plugins will be picked up correctly.
Failed first try - define jaCoCoArgLine property in prepare-agent goal configuration of jacoco - the scenario failed my second requirement, IntelliJ IDEA couldn't figure out agent for jmockit I use in the project for static method mocking
When using the maven-surefire-plugin or maven-failsafe-plugin you must not use a forkCount of 0 or set the forkMode to never as this would prevent the execution of the tests with the javaagent set and no coverage would be recorded.
ref: https://www.eclemma.org/jacoco/trunk/doc/maven.html
this is my gist
I was having the same issue. I updated the Jacoco version from 0.6 to 0.8 and updated surefire plugin as well. The following command generated Jacoco reports in site/jacoco/ folder:
mvn clean jacoco:prepare-agent install jacoco:report
My maven configurations are as follows:
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.0</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<forkedProcessExitTimeoutInSeconds>60</forkedProcessExitTimeoutInSeconds>
<forkCount>1</forkCount>
</configuration>
</plugin>
</plugins>
Came accross the same problem just now.
I have a class named HelloWorld, and I created a test class for it named HelloWorldTests, then I got the output Skipping JaCoCo execution due to missing execution data file.
I then tried to change my pom.xml to make it work, but the attempt failed.
Finally, I simply rename HelloWorldTests to HelloWorldTest, and it worked!
So I guess that, by default, jacoco only recognizes test class named like XxxTest, which indicates that it's the test class for Xxx. So simply rename your test classes to this format should work!
FWhat tdrury said:
change your plugin configuration into this:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<executions>
<!-- prepare agent for measuring integration tests -->
<execution>
<id>prepare-integration-tests</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
Edit:
Just noticed one important thing, destFile and dataFile seems case sensitive so it's supposed to be destFile, not destfile.
I struggled for days. I tried all the different configurations suggested in this thread. None of them works. Finally, I find only the important configuration is the prepare-agent goal. But you have to put it in the right phase. I saw so many examples put it in the "pre-integration-test", that's a misleading, as it will only be executed after unit test. So the unit test won't be instrumented.
The right config should just use the default phase, (don't specify the phase explicitly). And usually, you don't need to mass around maven-surefire-plugin.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Try to use:
mvn jacoco:report -debug
to see the details about your reporting process.
I configured my jacoco like this:
<configuration>
<dataFile>~/jacoco.exec</dataFile>
<outputDirectory>~/jacoco</outputDirectory>
</configuration>
Then mvn jacoco:report -debug shows it using the default configuration, which means jacoco.exec is not in ~/jacoco.exec. The error says missing execution data file.
So just use the default configuration:
<execution>
<id>default-report</id>
<goals>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
</configuration>
</execution>
And everything works fine.
I know this is late, but just for anyone else who has this issue and nothing seems to fix it (like I had). Make sure that in you pom, your configuration for jacoco inside plugins is not in turn inside pluginManagement. It seems some sort of default for maven is to put the plugins inside pluginManagement. This is almost unnoticeable until you try to add detailed configurations like for jacoco. In order to add these, you need to add them outside of the pluginManagement, otherwise they are effectively ignored. See my poms below for details.
My old pom (that gave the "Skipping jacoco ..." message):
<project>
...
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
My new pom (that now compiles a working jacoco report):
<project>
...
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
It happens if the path of your project has blank spaces anywhere, such as:
/home/user/my projects/awesome project
the report is not generated. If that is the case, remove those spaces from directory names, such as:
/home/user/my-projects/awesome-project
or move the project to a directory that doesn't have spaces along the way.
About the plugin configuration, I just needed the basic as below:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Jacoco Execution data file is a jacoco.exec file which is generated when prepare agent goal is running. When It isn't generated or the correct path isn't set in configuration, you will get that error message. Because Jacoco use It to build test coverage. This usually occur when you use jacoco maven plugin and surfire or failsafe. To ensure that the jacoco.exec file is generated, you have to add argline in you pom.xml file, not in the surfire configuration but inside a properties tag in you pom.xml file.
<properties>
<argLine>-Xmx2048m</argLine>
</properties>
The execution says it's putting the jacoco data in /Users/davea/Dropbox/workspace/myproject/target/jacoco.exec but your maven configuration is looking for the data in ${basedir}/target/coverage-reports/jacoco-unit.exec.
I have added a Maven/Java project with 1 Domain class with the following features:
Unit or Integration testing with the plugins Surefire and Failsafe.
Findbugs.
Test coverage via Jacoco.
Where are the Jacoco results? After testing and running 'mvn clean', you can find the results in 'target/site/jacoco/index.html'. Open this file in the browser.
Enjoy!
I tried to keep the project as simple as possible. The project puts many suggestions from these posts together in an example project. Thank you, contributors!
My response is very late but for others users
In your case you have to configure failsafe pluging to use the command line agent configuration saved in itCoverageAgent variable.
For exemple
<configuration>
<argLine>${itCoverageAgent}</argLine>
</configuration>
In your maven configuration, jacoco prepare the command line arguments in prepare-agent phase, but failsafe plugin doesn't use it so there is no execution data file.
Sometimes the execution runs first time, and when we do maven clean install it doesn't generate after that.
The issue was using true for skipMain and skip properties
under maven-compiler-plugin of the main pom File.
Remove them if they were introduced as a part of any issue or suggestion.
In my case, the prepare agent had a different destFile in configuration, but accordingly the report had to be configured with a dataFile, but this configuration was missing. Once the dataFile was added, it started working fine.
I faced similar error because tests execution were skipped.
I ran my build with similar system parameter : -Dmaven.test.skip.exec=true
Turning this system parameter to false solved the issue.
I just removed following two lines from properties tag
<jacoco.ut.reportPath>${project.basedir}/../target/jacoco.exec</jacoco.ut.reportPath>
<sonar.jacoco.reportPaths>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPaths>
mvn install -Psonar by default creates jacoco.exec in target directory, so explicit path was not needed in my case.
For others that met similar problem, here is another possible solution:
Our project was running in a Traditional Chinese version of Windows, and when we checked prepare-agent section in maven log, we found that it tried to read the project folder which we put on desktop, through \桌面\...\project\... instead of \Desktop\...\project\.... I think UTF-8 symbol in paths make Jacoco go weird. We moved the project into other place and the issue was fixed.
TL;DR:
Check prepare-agent logs too as jacoco.exec was prepared during that.
2 Other Possibilities
JaCoCo's Maven plugin could be better integrated with Maven to provide more information about it's invocation and incorrect invocations. Nonetheless.
Possibility #1: Custom Arguments In Surefire plugin
Using JPMS module for my project with standard Maven directory layout, basic JSE 11 program, JUnit 5 & JaCoCo, with Eclipse and single module-info.java file (Eclipse 4.13 won't allow 2 module-info.java files in the project's root of the classpath). In order for Surefire to see my test cases I had to use the single <argLine> tag to allow Surefire to gain access using: --add-opens for all of the packages having unit tests:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>
#{argLine}
--add-opens module_name/com.myco.project=ALL-UNNAMED
--add-opens module_name/com.myco.project.more=ALL-UNNAMED
--add-opens module_name/com.myco.project.others=ALL-UNNAMED
</argline>
</configuration>
...
</plugin>
According to Jacoco documentation, you have to directly pass the Jacoco arguments to Surefire since specifying any Surefire arguments using <argLine> overrides Jacoco's defaults. Jacoco's online Maven documentation specifies using #{argLine} to pass Jacoco's arguments to Surefire (https://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html).
Possibility #2: Intermingling Plugins
I also use the maven-javadoc plugin in my <reporting/> section. Incidentally, during the Javadoc reporting phase, it manages to invoke the prepare-agent goal of JaCoCo and gives the OP's error message shortly thereafter (according to maven debug, specifically while the maven-project-info-reports-plugin is configuring the reports to begin generating for maven site) - this despite the fact that my Test phase has already run and dumped a proper jacoco.exec file in the build output directory. It may be safe to ignore this warning, my JaCoCo report renders fine in my Maven Site. However, if you're seeing it during the execution of a JaCoCo goal, it probably shouldn't be ignored.
Tips
If you're having doubts about the file getting created, watch the directory where the file is supposed to appear during the build. Generating the file is a fairly slow process. See my other answer here: https://stackoverflow.com/a/75465187/2336934
Do your best to keep to all the defaults as much as possible, simpler is better.

Running Cargo From Maven antrun Plugin

I have a maven (multi-module) project creating some WAR and EAR files for JBoss AS 7.1.x.
For one purpose, I need to deploy one generated EAR file of one module to a fresh JBoss instance and run it, call some REST web service calls against it and stop JBoss. Then I need to package the results of these calls that were written to the database.
Currently, I am trying to use CARGO and the maven ant run plugin to perform this task.
Unfortunately, I cannot get the three (maven, ant run and CARGO) to play together. I don't have the uberjar that is used in the ant examples of cargo. How can I configure the ant run task so that the cargo ant task can create, start, deploy my JBoss? Ideally the one unpacked and configured by the cargo-maven2-plugin in another phase?
Or, is there a better way to achieve my goal of creating the database?
I cannot really use the integration-test phase, as it is executed after the package phase. So, I plan to do it all in compile phase using ant run.
To clarify again:
I need to do the following: start JBoss; deploy a WAR; wait until the startup of the WAR is complete; deploy an EAR file; wait until the EAR has initialized it's database; Call some web services in the implemented by the EAR; stop JBoss; package the database.
All these steps need to be strictly sequential.
The following part gives you an impression how to do that. You must change the details. In the given case i use a Tomcat. This will download the Tomcat archive uncompress and install Tomcat locally...
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<wait>false</wait>
<container>
<containerId>tomcat${tomcat.major}x</containerId>
<zipUrlInstaller>
<url>http://archive.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
<extractDir>${project.build.directory}/extract/</extractDir>
<downloadDir>${project.build.directory}/download/</downloadDir>
</zipUrlInstaller>
<output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
<log>${project.build.directory}/cargo.log</log>
</container>
<configuration>
<home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
<properties>
<cargo.logging>high</cargo.logging>
<cargo.servlet.port>9080</cargo.servlet.port>
<cargo.tomcat.ajp.port>9008</cargo.tomcat.ajp.port>
</properties>
</configuration>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
<configuration>
<deployer>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>mod-war</artifactId>
<type>war</type>
<pingURL>http://localhost:9080/mod-war</pingURL>
<pingTimeout>30000</pingTimeout>
<properties>
<context>mod-war</context>
</properties>
</deployable>
</deployables>
</deployer>
</configuration>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>

Resources