这是一个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>
我怎样才能找到&#39; DIR_TARGET&#39;初始定义并更改值
答案 0 :(得分:0)
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
的值是path(location: project.build.directory)
的路径分隔符规范化为unix的。
(我不是蚂蚁专家,但我在我的电脑上测试,这两个有相同的价值。 只需添加日志行即可查看
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>