jav*_*dev 5 groovy maven gmaven-plugin
我正在通过pom.xml中的gmaven插件运行外部groovy脚本.外部脚本是'myscript.groovy'.
我想通过maven pom.xml [即插件'gmaven-plugin'执行内部]为myscript.groovy提供一些参数/参数; 但无法这样做..
我尝试过使用; 但不确定如何在groovy脚本中检索其值.简单地调用properties.get不会给出属性值.
pom文件的快照:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>generate-resources-execute-groovyscript</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<property>
<name>installation.dir</name>
<value>${installation.dir}</value>
</property>
</properties>
<source>${pom.basedir}/src/main/groovy/configure.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
不确定如何在'configure.groovy'脚本中检索'installation.dir'属性的值.
在这方面的任何暗示将是有用的..谢谢
有两种方法可以绑定和检索属性.一种是通过插件特定的属性.
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>generate-resources-execute-groovyscript</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<properties>
<installation.dir>${installation.dir}</installation.dir>
</properties>
<source>${pom.basedir}/src/main/groovy/configure.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这些将在脚本中检索project.properties['installation.dir'].
GMaven不再维护(我是最后一个维护者).如果您想使用比2.0.0更新的Groovy版本,请查看GMavenPlus.这是等效的POM:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>execute</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<bindPropertiesToSeparateVariables>false</bindPropertiesToSeparateVariables>
<properties>
<property>
<name>installation.dir</name>
<value>${installation.dir}</value>
</property>
</properties>
<scripts>
<script>file:///${pom.basedir}/src/main/groovy/configure.groovy</script>
</scripts>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.3</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
在这种情况下检索就像properties['installation.dir'].我知道这file:///很烦人.我在下一个版本中删除了对此的要求.
对于GMaven或GMavenPlus,如果选择插件属性方法,则需要在项目POM中将值设置为其他位置
<properties>
<installation.dir>C:\someDir</installation.dir>
</properties>
Run Code Online (Sandbox Code Playgroud)
或者将其包含在您的通话中 mvn -Dinstallation.dir=C:\someDir
另一种选择是直接绑定到项目级属性.您可以将它放在项目级属性或您的调用中,如上所述,并且不包含<properties>在插件中<configuration>.如果你走这条路线,你可以在你的脚本中访问project.properties['installation.dir']GMaven或GMavenPlus(<bindPropertiesToSeparateVariables>在这种情况下也可以取出GMavenPlus).
如果这对您不起作用,请尝试重命名installation.dir为installationDir.如果时间有问题我不记得了.
| 归档时间: |
|
| 查看次数: |
3679 次 |
| 最近记录: |