如何在 Maven-Invoker-Plugin 中使用 ScriptVariables 和 Groovy 中的 PostBuildHookScript

How to use ScriptVariables in Maven-Invoker-Plugin with PostBuildHookScript in Groovy

我正在使用 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.var1skip.var2?我找不到任何关于此的文档或示例。到目前为止,我已经尝试了以下方法,但它不起作用。

def var1 = skip.var1

但我收到错误消息:

groovy.lang.MissingPropertyException: No such property: skip for class: Script1

如何正确访问变量?

勾选http://maven.apache.org/plugins/maven-invoker-plugin/run-mojo.html#scriptVariables

这个变量好像是1.9版本引入的

必须将版本更改为 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>