Failed to execute goal org.codehaus.mojo:exec-maven-plugin. Command execution failed - maven

I have a maven project.To run cucumber test i have following configuration in my pom file.
<plugin>
<groupId>net.mynetwork</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>0.0.4</version>
<executions>
<execution>
<id>execution</id>
<phase>site</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>${project.name}</projectName>
<outputDirectory>${project.build.directory}/site/cucumber-html-reports</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
<enableFlashCharts>false</enableFlashCharts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>cucumber</id>
<phase>test</phase>
<configuration>
<executable>src/scripts/cucumber.sh</executable>
<arguments>
<argument>${host}</argument>
<argument>${port}</argument>
<argument>${profile}</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
When i am executing mvn command.
mvn clean install
its giving me following error.
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (cucumber) Misconfigured argument, value is null. Set the argument to an empty value if this is the required behaviour.
Failed to execute goal net.mynetwork:maven-cucumber-reporting:0.0.4
Please suggest any solution and let me know if anything else needs to be share.

Looks like http://jira.codehaus.org/browse/MEXEC-104.
Try this instead:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>cucumber</id>
<phase>test</phase>
<configuration>
<executable>src/scripts/cucumber.sh</executable>
<commandlineArgs>${host} ${port} ${profile}</commandlineArgs>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>

Related

Jacoco analyzed bundle '...' with 0 classes when used with Cucumber

I am currently working on Jacoco code coverage for a Maven project with Cucumber integration tests.
My pom.xml file has jacoco and failsafe plugins as shown in the pictures, with reference from https://github.com/dimazelinskyi/jacoco-coverage-cucumber-unit-tests.
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.basedir}/target/jacoco-reports/jacoco-test.exec</destFile>
<propertyName>failsafeJacocoAgent</propertyName>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.basedir}/target/jacoco-reports/jacoco-test.exec</dataFile>
<outputDirectory>${project.basedir}/target/jacoco-reports/jacoco-test</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>${failsafeJacocoAgent}</argLine>
</configuration>
</execution>
<execution>
<id>junit-integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<testNGArtifactName>none:none</testNGArtifactName>
<argLine>${failsafeJacocoAgent}</argLine>
</configuration>
</execution>
<execution>
<id>testng-integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>${failsafeJacocoAgent}</argLine>
</configuration>
</execution>
</executions>
<configuration>
<includes>
<include>**/CukeRunnerTest.java</include>
</includes>
<systemPropertyVariables>
<isMavenTest>true</isMavenTest>
<client.uri>${wipdm.app.base.url}</client.uri>
<cucumber.options>${async.option}</cucumber.options>
</systemPropertyVariables>
<properties>
<async.option>--tags ~#longRunningTest</async.option>
</properties>
</configuration>
</plugin>
And the CukeRunnerTest.java file looks like this: CukeRunnerTest.java
When I build with maven i.e. mvn clean install, all tests successfully pass, however I get a message saying
[INFO] Loading execution data file C:\Users\...\IdeaProjects\...\target\jacoco-reports\jacoco-test.exec
[INFO] Analyzed bundle 'wipdata-war' with 0 classes
The build is successful and jacoco-it.exec file is generated, but no reports are generated.
Is this expected behaviour? As I thought that jacoco would check the Cucumber feature files inside "src/test/features/v3" (which is stated inside CukeRunnerTest.java) to see which code in the java files they covered in their integration tests.
Any advice or help is much appreciated.

Generating a JaCoCo code coverage report with Maven

I don't understand, I try to generate code coverage report with JaCoCo and Maven, the simplest.
I have the following plugin in my pom.xml :
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/my-reports</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
And when I try to do a mvn test, it just doesn't do anything. Not even an error or something. It say BUILD SUCESS for my tests but Maven seems to not see JaCoCo. If I try to execute mvn jacoco:report anyway I have a message : Skipping JaCoCo execution due to missing execution data file.
The following configuration should be enough:
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The reports can then be found in target/site/jacoco/
Reasons why it does not work in your case:
The Plugin configuration is inside pluginManagement
The Plugin is inside a profile
Also check the maven log when you execute mvn test for jacoco-maven-plugin. For more information run mvn -X test
This should work. Just run from command "mvn clean test"
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
https://www.mkyong.com/maven/maven-jacoco-code-coverage-example/

maven command to execute multiple executions in plugin

I am trying to generate sources from wsdl
This is my plug-in.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/generated-sources/wsdl</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>gen1</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>pkg1</packageName>
<wsdlDirectory>${basedir}/src/main/resources/wsdl/xml1</wsdlDirectory>
<keep>true</keep>
<sourceDestDir>${basedir}/target/generated-sources/wsdl</sourceDestDir>
</configuration>
</execution>
<execution>
<id>gen2</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>pkg2</packageName>
<wsdlDirectory>${basedir}/src/main/resources/wsdl/xml2</wsdlDirectory>
<keep>true</keep>
<sourceDestDir>${basedir}/target/generated-sources/wsdl</sourceDestDir>
</configuration>
</execution>
</executions>
</plugin>
When I run mvn compile, only gen1 is generated. I want it to generate both executions. I cannot combine them as they are residing in different wsdl directories and require different packagenames.
I understand that I can split into profiles and run it like mvn compile -Pprofile1,profile2.
But is there an easier way?

Inegration test using maven

I am trying to create something like integration tests - i am using groovy to send requests and to parse answers. I'd also want starting of jboss and deploying of .ear to be automatically. Using cargo plugin i was able to start jboss. By using exec plugin i am trying to execute perl script that puts ear to deploy folder. Next phase - execute groovy tests, but this phase starts without waiting for ear to be deployed. Is it possible to make phase to wait for server to be deployed to jboss? My pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>unpack-application-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${basedir}/src/main/script/appserver/unzip.groovy</source>
<defaults>
<installDirectory>${appserver.install.directory}</installDirectory>
<zipUrl>${appserver.zip.url}</zipUrl>
</defaults>
</configuration>
</execution>
<execution>
<id>prepare-application-server-configs</id>
<phase>pre-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${basedir}/src/main/script/appserver/${suffix}/postUnzipAction.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
</executions>
<configuration>
<wait>false</wait>
<container>
<containerId>${appserver.id}</containerId>
<home>${appserver.home}</home>
<timeout>6000000</timeout> <!--in ms-->
</container>
<configuration>
<properties>
<cargo.servlet.port>${servlet.port}</cargo.servlet.port>
<cargo.rmi.port>${rmi.port}</cargo.rmi.port>
<!-- corresponds to -Djboss.bind.address=0.0.0.0 under jboss -->
<cargo.hostname>0.0.0.0</cargo.hostname>
</properties>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>deploy-with-script</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>perl</executable>
<workingDirectory>.</workingDirectory>
<commandlineArgs>${deploy.pl.cmd} -x redeploy</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
setup and tear down your server before and after integration test phase, something like that:
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
Rename your unit tests to be skipped by surefire but executed by maven-failsave-plugin to *IT.java: http://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html

how to execute multiple command prompt commands using maven in single pom.xml

I want to run multiple command prompt commands in maven using single pom.xml. How can I do that?
For ex: I have 2 commands to execute. I am executing the first command by using exec-maven-plugin.
Below is the portion of my pom.xml to execute the first command:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>load files</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>windchill</executable>
<arguments>
<argument>wt.load.LoadFileSet</argument>
<argument>-file</argument>
<argument>${basedir}/fileSet.xml</argument>
<argument>-UNATTENDED</argument>
<argument>-NOSERVERSTOP</argument>
<argument>-u</argument>
<argument>wcadmin</argument>
<argument>-p</argument>
<argument>wcadmin</argument>
</arguments>
</configuration>
</plugin>
For this the build is success.
Is it possible to execute one more command just like above in the same pom.xml? I was not able to do that. So someone please help how to add it in pom.xml
The answer can be found in the FAQ.
The full answer is here: http://article.gmane.org/gmane.comp.java.maven-plugins.mojo.user/1307
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>id1</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cmd1</executable>
</configuration>
</execution>
<execution>
<id>id2</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>cmd2</executable>
</configuration>
</execution>
</executions>
</plugin>
Then you specify execution ids as:
mvn exec:exec#id2
But this syntax is possible starting from maven 3.3.1

Resources