我的 pom.xml 看起来像这样:
<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>mygroup</groupId>
<artifactId>myartefact</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<my.property>defaultValue</my.property>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script>file:///${basedir}/script.groovy</script>
</scripts>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.7</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
script.groovy 看起来像这样:
def value = project.properties['my.property']
log.info "my.property value = $value"
当我运行mvn validate -Dmy.property=cmdValue
脚本时会写
[INFO] my.property value = defaultValue
它将写入“defaultValue”,但我绝对需要覆盖值“cmdValue”。