一、介绍
如果你想在项maven生命周期内,运行一段java代码,或者一段独立的程序,或者说我们所指的预执行,初始化某些值,生成某些不能预先生成的文件。 那么这样我们就可以使用exec-maven-plugin进行程序的预执行,生成相关文件。
二、配置案例
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>git-info</id>
<phase>exec</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${project.basedir}/build_info.sh</executable>
<outputFile>${project.basedir}/src/main/webapp/build.info</outputFile>
</configuration>
</execution>
<execution>
<id>gen-version</id>
<phase>exec</phase>
<goals>
<goal>exec</goal> <!-- java还是exec-->
</goals>
<configuration>
<executable>${project.basedir}/gen_version.sh</executable>
<outputFile>${project.basedir}/VERSION</outputFile>
</configuration>
</execution>
<execution>
<id>gen-cron-props</id>
<phase>exec</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>sed</executable>
<arguments>
<argument>s/environment=product/environment=product_cron/g</argument>
<argument>${project.basedir}/profile/env.product.properties</argument>
</arguments>
<outputFile>${project.basedir}/profile/env.product_cron.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
三、使用
mvn exec:exec@gen-version exec:exec@git-info clean package -DAPP_ENV=test -Dmaven.test.skip=true