我正在使用Maven-Inovker-Plugin
来运行集成测试。我有一个名为verify.groovy
的post-build-hook-script来验证集成测试的结果。在groovy
脚本中,我需要从原始POM访问一些属性。我该怎么做?
到目前为止,我已将其放在maven-invoker-plugin
的配置块中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>1.7</version>
<configuration>
<debug>true</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<projectsDirectory>src/test/resources/invoker-tests</projectsDirectory>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<postBuildHookScript>verify</postBuildHookScript>
<scriptVariables>
<param>${skip.var1}</param>
<param>${skip.var2}</param>
</scriptVariables>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<goals>
<goal>clean</goal>
<goal>package</goal>
</goals>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
我已在文档here的scriptVariables
中添加了值。我很确定我做错了,正确的方法是什么?
然后如何在我的groovy脚本中访问变量skip.var1
和skip.var2
?我无法找到任何关于此的文档或示例。到目前为止,我已尝试过以下内容,但它不起作用。
def var1 = skip.var1
但我得到错误:
groovy.lang.MissingPropertyException: No such property: skip for class: Script1
如何正确访问变量?
答案 0 :(得分:1)
检查http://maven.apache.org/plugins/maven-invoker-plugin/run-mojo.html#scriptVariables
似乎这个变量是在1.9版本中引入的
答案 1 :(得分:0)
必须将版本更改为1.9或更高版本,如此处所述:http://maven.apache.org/plugins/maven-invoker-plugin/integration-test-mojo.html#scriptVariables
还必须具有以下配置才能传递变量:
<scriptVariables>
<var1>${skp.var1}</var1>
</scriptVariables>
在groovy脚本中,我可以直接使用var1
。
所以这才有效:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<version>2.0.0</version>
<configuration>
<debug>true</debug>
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
<projectsDirectory>src/test/resources/invoker-tests</projectsDirectory>
<pomIncludes>
<pomInclude>*/pom.xml</pomInclude>
</pomIncludes>
<postBuildHookScript>verify</postBuildHookScript>
<scriptVariables>
<var1>${skip.var1}</var1>
</scriptVariables>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<goals>
<goal>clean</goal>
<goal>package</goal>
</goals>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>