groovy蚂蚁怎么用
how does the ant use in groovy
这是一个 groovy 脚本文件 MavenInit.groovy,在 pom.xml 中执行如下,var 'SCRIPTS_GROOVY' 在另一个 pom.xml 中定义,什么令我困惑的是我找不到 "DIR_TARGET" 的定义,以及如何在没有 ant = new AntBuilder()
的情况下直接使用 ant
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 执行 MavenInit.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 like,来自path(location: project.build.directory)
。
(我不是蚂蚁专家,但我在我的电脑上测试,这两个值相同。
只需添加日志行即可查看
log.info( project.build.directory)
DIR_TARGET = ant.project.properties['DIR_TARGET']
log.info(DIR_TARGET)
我搜索了ant doc,从https://ant.apache.org/manual/Tasks/pathconvert.html中找到了一个例子,验证了我的猜测。
<pathconvert property="prop" dirsep="|">
<map from="${basedir}/abc/" to=''/>
<path location="abc/def/ghi"/>
</pathconvert>
这是一个 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 执行 MavenInit.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 like,来自path(location: project.build.directory)
。
(我不是蚂蚁专家,但我在我的电脑上测试,这两个值相同。 只需添加日志行即可查看
log.info( project.build.directory)
DIR_TARGET = ant.project.properties['DIR_TARGET']
log.info(DIR_TARGET)
我搜索了ant doc,从https://ant.apache.org/manual/Tasks/pathconvert.html中找到了一个例子,验证了我的猜测。
<pathconvert property="prop" dirsep="|">
<map from="${basedir}/abc/" to=''/>
<path location="abc/def/ghi"/>
</pathconvert>