Passing vm arguments to exec-maven-plugin - maven

Guys I have upgraded my project to Java 17 that's why I need these lines to VM to my program works without error.
=--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED
My project is working but I have another sub project which I use for testing purposes.It is run on JavaFX and it need previous arguments to work correctly.
I have tried adding as CommandLineArgs and arguments but still arguments are not passing through to vm and giving errors.
<profile>
<id>smoke</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy jars for tests</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>false</includePluginDependencies>
<stripVersion>true</stripVersion>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<classpathScope>test</classpathScope>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>false</includePluginDependencies>
<executable>${env.HOME}/java/bin/java.exe</executable>
<workingDirectory>${project.build.directory}</workingDirectory>
<arguments>
<argument>-javaagent:${env.HOME}/wildfly/standalone/lib/ext/agent.jar</argument>
<argument>-classpath</argument>
<argument>lib/*;classes</argument>
<argument>-DJBOSS_HOME=${JBOSS_HOME}</argument>
<argument>-DJAVA_HOME=${env.HOME}/java</argument>
<argument>-Duser.home=${env.USERPROFILE}</argument>
<argument>-Djava.library.path=${JBOSS_HOME}/bin</argument>
<argument>-DTESTING_FROM_COMMANDLINE=true</argument>
<mainClass>com.test.GenerateSmoke</mainClass>
<commandlineArgs>-Dexec.args=--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED</commandlineArgs>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
If you have any idea please let me know.Thanks

I had a similar issue when running tests with the maven-surefire-plugin.
In my case I added it like this into the pom:
<configuration>
<argLine>${argLine} --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
Maybe it is the same in your case.

The plugins configuration options are documented here: https://www.mojohaus.org/exec-maven-plugin/exec-mojo.html
commandlineArgs or -Dexec.args are both an alternative option to override the entire executed command line you specify. These can not be used together with (other) arguments.
So you either define the entire java command line to execute as:
arguments in the pom, or
commandlineArgs in the pom, or
exec.args as an environment variable (so mvn exec:exec -Dexec.args=...)
You should be able to add the arguments to your current plugin configuration like so:
<configuration>
<arguments>
<argument>...</argument>
<argument>--add-opens</argument>
<argument>java.base/java.lang=ALL-UNNAMED</argument>
<argument>--add-opens</argument>
<argument>java.base/java.util=ALL-UNNAMED</argument>
<argument>...</argument>
</arguments>
</configuration>
Depending on what you run these arguments might need to be inserted in a specific place, so the order of these arguments matters.
That is where you can experiment with substituting the ... in my example with your current arguments.
As a test i've ran a java -jar with these options, and that works. I've enabled the maven argument -X for debug logging.
[DEBUG] Executing command line: [some\path\jdk-17.0.2\bin\java.exe, --add-opens, java.base/java.lang=ALL-UNNAMED, --add-opens, java.base/java.util=ALL-UNNAMED, -jar, my.jar]
And if i make an "accidental" typo in my add-opens we see that these arguments are indeed parsed by the java process:
[DEBUG] Executing command line: [some\path\jdk-17.0.2\bin\java.exe, --add-typo, java.base/java.lang=ALL-UNNAMED, --add-opens, java.base/java.util=ALL-UNNAMED, -jar, my.jar]
Unrecognized option: --add-typo
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Related

jmeter-maven-plugin libraries management

I have such plugin configuration in my pom.xml
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>${jmeter.maven.plugin.version}</version>
<configuration>
<jmeterExtensions>
<artifact>kg.apc:jmeter-plugins-json:2.4</artifact>
<artifact>kg.apc:jmeter-plugins-casutg:2.1</artifact>
</jmeterExtensions>
<junitLibraries>
<artifact>com.microsoft.sqlserver:sqljdbc4:4.0</artifact>
</junitLibraries>
<testFilesIncluded>
<jMeterTestFile>${tests.include}</jMeterTestFile>
</testFilesIncluded>
<jMeterProcessJVMSettings>
<xms>2048</xms>
<xmx>2048</xmx>
</jMeterProcessJVMSettings>
<customPropertiesFiles>
<!-- Custom property file -->
</customPropertiesFiles>
<propertiesJMeter>
<!-- Some properties that I pass into jmeter -->
</propertiesJMeter>
</configuration>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
</plugin>
After I run mvn clean verify I get such libsat /target/jmeter/lib/:
json-path-2.1.0.jar
json-path-2.2.0.jar
and in log file I see that jmeter fails from time to time with such exception:
jmeter.extractor.json.jsonpath.JSONPostProcessor: Error processing JSON content in Select Team Name, message:Could not compile inline filter : [?(#.id=="29011")]
Note that this [?(#.id=="29011")] is only a part of expression. Full expression is looks like similar to this: $.teamData[?(#.id=="29011")].name
I expect that this error somehow related to this multiple libs
Use last version of the plugin which has solved this issue as described in release notes:
https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/blob/master/CHANGELOG.md

How to set classpath for mvn exec:exec?

I'm trying to have mvn exec:exec (or mvn exec:java) run my program with a local jar in the classpath. However the jar fails to load:
Exception in thread "main" java.lang.Error: Unable to load voice directory. java.lang.ClassNotFoundException: com.sun.speech.freetts.en.us.cmu_us_slt_arctic.ArcticVoiceDirectory
at com.sun.speech.freetts.VoiceManager.getVoiceDirectories(VoiceManager.java:211)
at com.sun.speech.freetts.VoiceManager.getVoices(VoiceManager.java:111)
at com.sun.speech.freetts.VoiceManager.getVoice(VoiceManager.java:521)
at xpress.audio.TTS.<init>(TTS.java:66)
at xpress.audio.TTS.<init>(TTS.java:62)
at xpress.audio.AudioProducer.main(AudioProducer.java:18)
Running the program directly from the CLI using java works:
C:\XpressAudio\target\classes>java -cp "C:\XpressAudio\target\XpressAudio-1.0-SN
APSHOT-jar-with-dependencies.jar;C:\XpressAudio\cmu_us_slt_arctic.jar;C:\XpressA
udio\en_us.jar;C:\XpressAudio\*" xpress.audio.AudioProducer
Here's the <build> part of my pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<mainClass>xpress.audio.AudioProducer</mainClass>
</configuration>
<dependencies>
<dependency>
<groupId>cmu_us</groupId>
<artifactId>slt_arctic</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/cmu_us_slt_arctic.jar</systemPath>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Could someone tell me how should I edit the pom.xml such that mvn exec:exec works like the java command above?
com.sun.speech.freetts.en.us.cmu_us_slt_arctic.ArcticVoiceDirectory is a class in cmu_us_slt_arctic.jar
In maven it is possible to include a local jar (which is outside of maven repository) using systemPath. But since the scope is system (for dependencies declared with systemPath), there are few limitations and because of that it only works with exec:java.
For exec:exec, the above solution will not work because maven does not include system scoped dependencies in its generated (runtime) classpath (%classpath) so the solution is to use your own classpath instead of maven generated classpath as shown below.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<argument>local.jar;target/project-jar-with-dependencies.jar</argument>
<argument>xpress.audio.AudioProducer</argument>
</arguments>
</configuration>
</plugin>
Replace local.jar with all the jar files that are required to be present at some fixed location (here project root is assumed, where pox.xml is located). Also note the use of 'project-jar-with-dependencies.jar', in your case it should be target\XpressAudio-1.0-SN
APSHOT-jar-with-dependencies.jar.
standard java does not allow us to specify multiple -cp arguments, but exec-maven-plugin does, so
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution><goals><goal>exec</goal></goals></execution>
</executions>
<configuration>
<executable>./java.pl</executable>
<arguments>
<argument>-ea</argument>
<argument>-cp</argument><argument>.</argument>
<argument>-cp</argument><argument>my.jar</argument>
<argument>-cp</argument><classpath/>
<argument>org.example.ConfigByXml</argument>
</arguments>
</configuration>
</plugin>
note the call to java.pl above, this is the trick
#!/usr/bin/env perl
while (#ARGV) {
$arg = shift;
if ($arg eq '-cp' or $arg eq '-classpath') {
push #cp, shift;
next;
}
push #args, $arg;
}
unshift #args, 'java', '-cp', join(':', #cp);
# print 'args: ', join(' --- ', #args); # uncomment to debug
exec #args;
understand what java.pl does and use it or do the equivalent in bash, cmd, powershell, whatever..
To set additional classpath in maven you should use in your maven configuration file as below:
<additionalClasspathElements>
<additionalClasspathElement>path/to/additional/jar</additionalClasspathElement>
</additionalClasspathElements>
For more detail:
http://maven.apache.org/surefire/maven-surefire-plugin/examples/configuring-classpath.html

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.

Issue with stopping weblogic server using wls-maven-plugin

This is part of my pom.xml of my .ear file
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>wls-maven-plugin</artifactId>
<version>12.1.1.0</version>
<configuration>
<adminurl>${adminURL}</adminurl>
<user>${username}</user>
<password>${pswrd}</password>
<upload>true</upload>
<remote>false</remote>
<verbose>true</verbose>
<source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
<name>${project.build.finalName}</name>
<targets>${serverName}</targets>
<noExit>true</noExit>
<middlewareHome>${middlewareH}</middlewareHome>
<domainHome>${domainH}</domainHome>
</configuration>
<executions>
<execution>
<id>stopserver</id>
<phase>install</phase>
<goals>
<goal>stop-server</goal>
</goals>
<configuration>
<action>stopserver</action>
<workingDir>${stopScriptDirectory}</workingDir>
<command>stopScript.sh</command>
</configuration>
</execution>
</executions>
</plugin>
I am trying to stop the server by running the stopScript.sh
This is the error I am getting when it is trying to execute the stop-server goal:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.oracle.weblogic:wls-maven-plugin:12.1.1.0:stop-server (stopserver) on project OventusEAR2: Unable to parse configuration of mojo com.oracle.weblogic:wls-maven-plugin:12.1.1.0:stop-server for parameter command: Cannot assign configuration entry 'command' with value 'stopScript.sh' of type java.lang.String to property of type java.lang.String[]
Any ideas?
Though I am not familiar with this particular plugin, however I have seen similar issues before, I guess command parameter is expecting an array instead.
Please try replacing
<command>stopScript.sh</command>
with
<command>
<value>stopScript.sh</value>
</command>
and test again.

Launching a windows batch script using Maven exec plugin blocks the build even though the script uses "start"

I am trying to perform integration tasting of the deployment of my application on the top of a custom container. Since my container is custom, I cannot use Maven Cargo plugin to setup the container.
My container:
Has to be started though a proper bat file, which is in the path of the machine where the tests are run.
Can be manually closed since I have a single maven module containing all my integration tests, even if one day I would like to know how to shut the process down after my tests are completed.
My problem is that I have to run my container in a different process, because it needs to keep running while my tests are performed. Furthermorely, I have an API in my tests that let me wait for the container to be ready (a sort of lookup with timeout).
I have added the following lines to my pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>scripts/start-agent.bat</executable>
</configuration>
</plugin>
This will call a script, which contains only
start call gs-agent.bat
However the mvn exec plugin gets stucked and my tests are not run. According to what is suggested in How do I run a batch file from my Java Application? , I have modified my pom.xml as the following:
<configuration>
<executable>cmd</executable>
<arguments>
<argument>/C</argument>
<argument>start</argument>
<argument>gs-agent.bat</argument>
</arguments>
</configuration>
But this does not seem to solve the issue:
exec plugin is not able to do this, and I found the issue for it, too: http://jira.codehaus.org/browse/MEXEC-87 (link now dead due to codehaus rampdown, can be found from web archive)
In the jira issue linked above, there is a mention and a link of a fork for exec plugin that would have the functionality.
Other than that, I think you'll need to use an antrun-plugin for the time being.
Here's an example taken from working configuration and run with mvn verify. This needs to be in the <plugins>, not <pluginManagement> (exec could reside in pluginmanagement just fine).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<configuration>
<target>
<exec executable="cmd.exe"
spawn="true">
<arg value="/c"/>
<arg value="D:\myfolder\test.bat"/>
</exec>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Note that spawn="true" is key here if you don't want the execution to block, like specified in the question. If you do want it to block and see the output immediately, set it to false.
See this question: How do I run a batch file from my Java Application?
Windows Batch Files are not executable. They are scripts that are run by the cmd executable.
More Information
Exec plugin source code reveals that Apache Commons Executor is used to actually execute the command line.
There is a lot of reading you can do here, i.e. in the Apache Commons Executor documentation and their JIRA issues, but the short version is: this isn't a problem with "Maven," it's a problem with the platform-dependent nature of executing an exec() command.
I've tackled this sort of problem before, and the solution I always devise is to deconstruct the .bat script into its actual commands and launch it directly from the exec plugin, rather than calling the script.
The Fallowing Code works for me
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<tasks>
<exec dir="${project.basedir}" executable="Script.bat" failonerror="true">
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Source https://maven.apache.org/guides/mini/guide-using-ant.html
In my case I had trouble with npm and ng.. the underlying problem was exec-maven-plugin was trying to execute the sh scripts (which had no extensions).
Renaming
C:\Users\User\AppData\Roaming\npm\ng to C:\Users\User\AppData\Roaming\npm\ng.sh
and
C:\apps\nodejs\npm to C:\apps\nodejs\npm.sh
solved the problem.
If you want to use exec-maven-plugin here is an example to run a batch script with arguments. E.g. to run something like:
.\test.bat arg1 arg2 arg3
add the following to pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>exec-test</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>cmd</executable>
<workingDirectory>./</workingDirectory>
<arguments>
<argument>/c</argument>
<argument>start</argument>
<argument>""</argument>
<argument>exec.bat</argument>
<argument>arg1</argument>
<argument>arg2</argument>
<argument>arg3</argument>
</arguments>
</configuration>
</plugin>

Resources