Maven exec plugin multiple executions not working - maven

I am trying to make the Maven exec plugin run multiple executions when I invoke the exec:java goal in the following way:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>first</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.example.First</mainClass>
</configuration>
</execution>
<execution>
<id>second</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.example.Second</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
However upon running mvn exec:java with maven 3.1.1 I get the error message:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project test: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java are missing or invalid -> [Help 1]
Running the exec:java goal for a single execution (without using the nested executions element) works as expected.

It seems to me that the problem is that neither of the <execution/> is tied to a particular <phase/>. Try setting one.

Related

Skip maven-cucumber-reporting plugin when integration test is skipped

This is a basic level question about maven plugin lifecycle.
When I run the command mvn clean install -Dskip.integration.tests=false then cucumber report is generated by the following plugin:
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>${project.name}</projectName>
<inputDirectory>${project.build.directory}/cucumber</inputDirectory>
<outputDirectory>${project.build.directory}</outputDirectory>
<jsonFiles>
<jsonFile>cucumber.json</jsonFile>
</jsonFiles>
</configuration>
</execution>
</executions>
</plugin>
If I skip the integration tests using the maven command mvn clean install -Dskip.integration.tests=true then the maven build fails with the following error:
Execution execution of goal net.masterthought:maven-cucumber-reporting:5.5.0:generate failed: basedir app/target/cucumber does not exist
To what phase should the plugin be configured so that the maven build does not fail when integration test is skipped?
Add the skip variable to the plugin config whose value is based on whether the integration tests are skipped or not.
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<skip>${skip.integration.tests}</skip>
<projectName>${project.name}</projectName>
<inputDirectory>${project.build.directory}/cucumber</inputDirectory>
<outputDirectory>${project.build.directory}</outputDirectory>
<jsonFiles>
<jsonFile>cucumber.json</jsonFile>
</jsonFiles>
</configuration>
</execution>
</executions>
</plugin>
in root pom.xml in the properties section add:
<skip.integration.tests>true</skip.integration.tests>
Now the plugin generates cucumber-html-reports folder when you run the maven command mvn clean install -Dskip.integration.tests=false. If you skip integration tests using the maven command mvn clean install -Dskip.integration.tests=true then the cucumber-html-reports folder will not be generated but maven build would still succeed.

Build not finishing due to maven exec plugin

I have this multi module maven project, with one parent pom and many child poms.
when running maven install, my last module uses a maven exec plugin and runs a main method of some class. The thing is, it seems like the build is stopped once the main method finishes running.
This is my setup:
from my parent pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<skip>true</skip>
<executable>java</executable>
</configuration>
</plugin>
from my child pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.example.MainClass</mainClass>
<async>true</async>
<keepAlive>true</keepAlive>
</configuration>
</execution>
</executions>
</plugin>
I tried incorporating
<async>true</async>
<keepAlive>true</keepAlive>
but it still stops after the main method is executed. I do not see BUILD SUCCESS in the end...
The solution was to use exec:exec and not exec:java, because exec:java and maven build run on the same process while exec:exec runs on a different process.

exec-maven plugin error when executing with mvn clean verify

I get the below error when executing postman tests using exec Maven plugin. What am I doing wrong?
I am fairly new to this, so, any help would be welcomed.
I run it with 'mvn clean verify'
Error:-
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (merge) on project ihtests: Command execution failed.
Plugin:-
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<workingDirectory>.</workingDirectory>
</configuration>
<executions>
<execution>
<id>merge</id>
<phase>integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>
/node_modules/newman/bin/newman.js
</executable>
<arguments>
npm shipment-tests
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Creating an Archetype From POM: Property is Missing

I created a Maven archetype and want to create an example project of it in my repository, which seems to be an unusual use-case.
Since I don't want to create the archetype manually, I added the following execution:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<configuration>
<archetypeGroupId>my.company.archetypes</archetypeGroupId>
<archetypeVersion>${project.version}</archetypeVersion>
<groupId>org.acme</groupId>
<version>0.1.2-SNAPSHOT</version>
<interactiveMode>false</interactiveMode>
</configuration>
<executions>
<execution>
<id>archetype-one</id>
<goals>
<goal>generate</goal>
</goals>
<phase>package</phase>
<configuration>
<archetypeArtifactId>archetype-one</archetypeArtifactId>
<artifactId>one</artifactId>
<package>org.acme.one</package>
</configuration>
</execution>
</executions>
</plugin>
This leads to the following exception:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (archetype-one) on project examples: Archetype my.company.archetypes:archetype-one:0.9.0-SNAPSHOT is not configured
[ERROR] Property groupId is missing.
[ERROR] Property artifactId is missing.
[ERROR] Property package is missing.
Which is just not true, since I've defined all of these. At least the IDE proposes these tags on that position. Moving the configuration tags around doesn't help either.
So I checked the source code of generate, and lo and behold, the target GAVs aren't present.
How do I define them when generating an archetype directly from another pom.xml?
So I ended up using an entirely different Maven plug-in:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>archetype-one</id>
<goals>
<goal>exec</goal>
</goals>
<phase>package</phase>
<configuration>
<executable>mvn</executable>>
<arguments>
<argument>archetype:generate</argument>
<argument>-DarchetypeGroupId=my.company.archetypes</argument>
<argument>-DarchetypeVersion=${project.version}</argument>
<argument>-DgroupId=org.acme</argument>
<argument>-Dversion=0.1.2-SNAPSHOT</argument>
<argument>-DinteractiveMode=false</argument>
<argument>-DarchetypeArtifactId=archetype-one</argument>
<argument>-DartifactId=one</argument>
<argument>-Dpackage=org.acme.one</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
And since I wanted to generate multiple archetypes, I put the first six arguments into a general <configuration> block, and appended the remaining three with <arguments combine.children="append">.

Error using exec-maven-plugin inside of iterator-maven-plugin

We are currently using the exec-maven-plugin to import oracle .dmp files into a database. Our list of .dmp files keeps growing so I wanted to try using the iterator-maven-plugin to loop through a list of .dmp file names. when I wrap the iterator plugin around the exec plugin, I receive a java error about being unable to find 'executable' in class java.lang.Object. I'm not strong in Java but it looks like the iterator plugin is blocking the exec plugin from working correctly.
<build>
<plugins>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<version>0.5.1</version>
<executions>
<execution>
<id>import-dmp</id>
<phase>install</phase>
<goals>
<goal>iterator</goal>
</goals>
<configuration>
<items>
<item>file1.dmp</item>
<item>file2.dmp</item>
</items>
<pluginExecutors>
<pluginExecutor>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>exec-one</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>imp.exe</executable>
<commandlineArgs>${jdbc.user}/${jdbc.password}#${jdbc.db.name} FILE=${project.basedir}/export/target/database/#item# FULL=Y GRANTS=N INDEXES=N CONSTRAINTS=N IGNORE=Y</commandlineArgs>
</configuration>
</plugin>
</pluginExecutor>
</pluginExecutors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The error message I receive is
[ERROR] Failed to execute goal com.soebes.maven.plugins:iterator-maven-plugin:0.5.1:iterator (import-file) on project test-import: Unable to parse > configuration of mojo com.soebes.maven.plugins:iterator-maven-plugin:0.5.1:iterator for parameter executable: Cannot find 'executable' in class > java.lang.Object -> [Help 1]
[ERROR]
I've looked at the optional parameters for both the iterator plugin and the exec plugin to see if there is something I can add which would allow the exec plugin to work but nothing seems related to a java error.
Has anyone run into this error before?

Resources