这是一个groovy脚本文件MavenInit.groovy,在pom.xml中执行如下,var'SCRIPTS_GROOVY'在另一个pom.xml中定义,让我迷惑的是我找不到“DIR_TARGET”定义在哪里,怎么能没有ant = new AntBuilder()
直接使用蚂蚁
SCRIPTS_GROOVY=project.properties['SCRIPTS_GROOVY']
ant.pathconvert(targetos:"unix", property:"DIR_TARGET") {
path(location:project.build.directory)
}
DIR_TARGET=ant.project.properties['DIR_TARGET']
project.properties.setProperty('DIR_TARGET', "${DIR_TARGET}")
project.properties.setProperty('DIR_LOGS', "${DIR_TARGET}/logs")
ant.mkdir(dir:"${DIR_TARGET}/logs")
pom.xml执行Maven Init.groovy如下
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<executions>
<execution>
<id>set-maven-property</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script>file:///${SCRIPTS_GROOVY}/MavenInit.groovy</script>
</scripts>
</configuration>
</execution>
<execution>
<id>Windows-package</id>
<phase>compile</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script>file:///${SCRIPTS_GROOVY}/PackageWindows.groovy</script>
</scripts>
</configuration>
</execution>
</executions>
</plugin>
如何找到'DIR_TARGET'初始定义并更改值
GMavenplus插件set an ant property进入其脚本
if (!properties.containsKey("ant")) {
try {
Object antBuilder = invokeConstructor(findConstructor(classWrangler.getClass("groovy.util.AntBuilder")));
properties.put("ant", antBuilder);
}
还有其他属性,如project
,log
等。
关于DIR_TARGET
,我认为这是project.build.directory
的路径分隔符规范化为unix的path(location: project.build.directory)
的值。
(我不是蚂蚁专家,但我在我的电脑上测试,这两个有相同的价值。只需添加日志行即可查看
log.info( project.build.directory)
DIR_TARGET = ant.project.properties['DIR_TARGET']
log.info(DIR_TARGET)
我搜索了蚂蚁文档并找到了https://ant.apache.org/manual/Tasks/pathconvert.html的一个例子,它验证了我的猜测。
<pathconvert property="prop" dirsep="|">
<map from="${basedir}/abc/" to=''/>
<path location="abc/def/ghi"/>
</pathconvert>