Running the Maven3 exec plugin without inheritance

I have a java project project with several maven modules where I want to execute the exec plugin to execute a custom command after creating the Jars.

I call the maven: assembly exec: exec assembly on the parent POM to create the project output file.

In the parent POM, I used the following:

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <configuration> <executable>myExecutable.exe</executable> <workingDirectory>${basedir}</workingDirectory> <arguments>....</arguments> </configuration> </plugin> 

At the same time, my executable file was executed correctly, but it was executed for each child module.

To try to fix this, I found that the plugin does not receive child module inheritance:

 <inherited>false</inherited> 

But now, using the exec plugin , the parameters are executed 'for the target org.codehaus.mojo: exec-maven-plugin: 1.2.1: exec are absent or invalid .. p>

I tried to configure the plugin to run under the "executions" element and assign it to the maven life cycle phase. This made the executable work successfully, but I canโ€™t do it because I need to execute other plugins (build plugin) before I run this exec plugin.

How can I run this (exec) plugin only once after the completion of the package phase, and the other plugin (build) was finished?

In other words, I want to execute a โ€œpackageโ€ for all of my child modules, and then execute the exec plugin only once from the parent.

I would appreciate any help.

+4
source share
2 answers

When you run the command at the parent POM level, you tell Maven to invoke this part of the life cycle for each module.

If you only want to call exec: exec for the child module, you should only declare this plugin for the child module (since it does not make sense for other modules inheriting from the parent) and call Maven with the --projects or -pl argument:

mvn -pl child assembly package: assembly exec: exec

This command, when executed from the parent project, executes package assembly:assembly exec:exec only for the child project.

However, if you are really trying to accomplish that you can package all the modules in one command, and you want the assembly:assembly and exec:exec targets to be executed for this child module during package , then you want to bind these plugins to this phase . For instance:

 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <configuration> <executable>myExecutable.exe</executable> <workingDirectory>${basedir}</workingDirectory> <arguments>....</arguments> </configuration> <executions> <!-- run the exec goal of this plugin every time this module is packaged --> <execution> <phase>package</phase> <goals><goal>exec</goal></goals> </execution> </executions> </plugin> 
+1
source

This will skip inheritance with the exec-maven-plugin settings previously made:

 <build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <executions> <execution> <phase>none</phase> </execution> </executions> </plugin> </plugins> </pluginManagement> ... </build> 
0
source

Source: https://habr.com/ru/post/1484422/


All Articles