最近在做一些代码生成器,需要在maven生存期执行groovy,使用简单示例,记录一下。
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mtest</groupId>
<artifactId>tool-generator</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${project.basedir}/src/main/groovy/test.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
test.groovy
println "test"
执行maven的Lifecycle中的package,结果: