Groovy Maven Structure

juno.yoon edited this page May 22, 2016 · 2 revisions

When you run the groovy maven project, it might take time to run the test at the first time. It's because maven project requires to download the related libraries from maven repo. Please be patient. :-).

If you choose to use Groovy Script when you create a script, it works similar to Jython script except the JUnit styled test cases. However if you want not only to use Groovy but also to execute JUnit runner in your IDE or easily configure dependencies, you can choose to make Groovy Maven Project first.

If you create Groovy Maven Project, you will have the following directories containing three files under the specified project folder.

Location Description
${name}/pom.xml Maven project file. You can add the library dependencies in this file.
${name}/src/main/java/Test1.groovy Default groovy script file
${name}/src/main/java/resources1.txt Default resource file
${name}/lib Not automatically generated. but this folder can be used to distribute private libraries if available.

You can import this project into you IDE using SVN checkout. You may need to check the below links.

In pom.xml, You can specify the additional library dependencies.

<project xmlns="" xmlns:xsi=""



        <!-- Following dependency is mandatory -->

        <!-- Add the dependencies -->
        <!--  <dependency>
        <!-- Put your private library like this -->



If you like to add the private libraries which do not exist in the public maven repository, you can put them in the lib folder directly and specify the systemPath option like the above sample. lib folder will be automatically detected and copied into agents as well when the controller prepares the script distribution.
When a script is selected in the performance test configuration page, the controller automatically detects whether the script is under the folder ${name}/src/main/java and there is pom.xml in the base folder. If the controller detects it, the controller will copy the files in the ${name}/src/main/resources and ${name}/src/main/java folder recursively into controller’s distribution preparation folder before distributing them to agents. The below figure illustrates how each folder in svn are copied to the distribution preparation folder.

folder path
from svn foler pom.xml
lib (private libraries)
folder path
to dist folder Test1.groovy
lib (copied from maven dependencies and files in lib folder existing subversion)

In generic Jython script and Groovy script, the resources are loaded using command "open(“./resources/resource1.txt”)" or "new File("./resources/resource1.txt"). However this won’t work in Groovy Maven project. We had to replace this path based resource discovery into the classpath based resource discovery to make Groovy JUnit test workable in IDE as well,
All resources in ${project_name}/src/main/resources/.. are copied into the same folder where the test script is copied but keeping the sub directory hierachy. You can load the resources using code below.

import org.codehaus.groovy.reflection.ReflectionUtils;

class YourTest {
    String text;

    public void beforeThread() {
       // In groovy, InputStream contains text field.
       text = loadResourceFromClassPath("/resource1.txt").text;

    public void doTest() {

    // This is groovy way to load resource from classpath
    public loadResourceFromClassPath(String resourcePath) {
        return ReflectionUtils.getCallingClass(0).getResourceAsStream(resourcePath);
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.