0

I am using Maven-Inovker-Plugin to run integration tests. I have a post-build-hook-script called verify.groovy to verify the results of the integration tests. In the groovy script, I need to access some properties from the original POM. How do I do that?

So far, I have put this in the configuration block for 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>

I have put values in scriptVariables from documentation here. I am pretty sure I have done it wrong, what is the correct way?

And then how do I access variable skip.var1 and skip.var2 in my groovy script? I am unable to find any documentation or examples on this. So far I have tried the following, but it does not work.

def var1 = skip.var1

But I get error :

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

How do I correctly access the variable?

dc95
  • 1,319
  • 1
  • 22
  • 44
  • 1
    I recommend to use `src/main/it` as folder for your integration tests...If you need to give values from your original pom to the integration test pom this could be done using `@...@` in your integration test pom which is filtered during the run of maven-invoker-plugin...And please use the most recent version of maven-invoker-plugin... – khmarbaise Feb 04 '17 at 10:56

2 Answers2

1

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

It seems that this variable was introduced in version 1.9

Luke Exton
  • 3,506
  • 2
  • 19
  • 33
0

Had to change the version to 1.9 or higher, as mentioned here : http://maven.apache.org/plugins/maven-invoker-plugin/integration-test-mojo.html#scriptVariables

Also had to have below configuration for passing the variables:

                    <scriptVariables>
                        <var1>${skp.var1}</var1>
                    </scriptVariables>

And in the groovy script, I can directly use var1.

So this is what worked:

            <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>
dc95
  • 1,319
  • 1
  • 22
  • 44
  • 1
    Added a plugin as a dependency is simply wrong! You shouldn'T use the resources folder of the project as projectsDirectory. Best practice is to use `src/main/it` as this...Furthermore `` you don't need to give explicit, cause it's default. – khmarbaise Feb 04 '17 at 10:53
  • @khmarbaise I have edited to remove the dependency. Don't know why at the time it seemed like it was necessary to add. Overall, the version was the problem. Thanks for the other tips. Question : why `src/main/it`? Any particular reason or documentation/example you can point me to? Since this is for testing, it makes sense to put this in `src/test/`, rather than `src/main`. – dc95 Feb 05 '17 at 01:45
  • I have mistyped it should be `src/it` which can be read in the [default directory layout](https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html). `src/test` are usually for unit tests and not for integration test neither for integration test of plugins...see many examples in the other maven plugins. – khmarbaise Feb 05 '17 at 09:29