1

I'm trying to use the plugin: http://gatling.io/docs/2.0.1/extensions/maven_plugin.html

I'm trying to run this command at the root pom:

mvn package gatling:execute

This multi module project only has this plugin defined in one child pom like so:

    <plugins>
        <plugin>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-maven-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.2.1</version>
            <configuration>
                <args>
                    <arg>-deprecation</arg>
                    <arg>-feature</arg>
                    <arg>-language:postfixOps</arg>
                </args>
            </configuration>
            <executions>
                <execution>
                    <id>scala-compile-first</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>add-source</goal>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>scala-test-compile</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

But when I run this command at the root, it gives this error:

[INFO] ------------------------------------------------------------------------
[INFO] Building root-pom 2.5.210-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- gatling-maven-plugin:2.1.7:execute (default-cli) @ root-pom ---
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
    at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
Caused by: java.lang.RuntimeException: Can't find the jar matching (.*scala-library.*\.jar)$
    at io.gatling.compiler.ZincCompiler$$anonfun$jarMatching$1$2.apply(ZincCompiler.scala:88)
    at io.gatling.compiler.ZincCompiler$$anonfun$jarMatching$1$2.apply(ZincCompiler.scala:88)
    at scala.Option.getOrElse(Option.scala:120)
    at io.gatling.compiler.ZincCompiler$.jarMatching$1(ZincCompiler.scala:88)
    at io.gatling.compiler.ZincCompiler$.setupZincCompiler(ZincCompiler.scala:91)
    at io.gatling.compiler.ZincCompiler$delayedInit$body.apply(ZincCompiler.scala:106)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.App$class.main(App.scala:71)
    at io.gatling.compiler.ZincCompiler$.main(ZincCompiler.scala:35)
    at io.gatling.compiler.ZincCompiler.main(ZincCompiler.scala)
    ... 6 more

This is not a scala project, so this is definitely related to the plugin. Running mvn package without gatling:execute works fine.

I do not know enough about maven to be able to troubleshoot this problem because I can't really tell what maven is trying to do here. If it is trying to run gatling at the root, why? That plugin is not defined in the root pom anywhere. My question is:

  1. When you run a plugin at the root of a multi-module project, how does it traverse my project, look for plugins and run them? I'm asking this question abstractly. You don't have to answer in terms of gatling. I just want to understand maven plugins better.

  2. How do I troubleshoot this issue? I think I could add scala to the root pom, but since it would be the first dependency at that level, it seems like it's the wrong approach.

    I could also cd into the one child pom that has this plugin and run the command there, but that means I'll only be running package on a piece of the project. Ideally I'd like to run package on the whole project before I run the plugin.

Community
  • 1
  • 1
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356

1 Answers1

2

Running maven with a plugin goal like that will run that goal for all project modules, the same as mvn install will install each module. You don't have to define the plugin anywhere - if you specify it on the commandline, it is run.

You correctly bound the execution of that plugin to one or more lifecycle phases, in this case process-resources and process-test-resources. If you run mvn compile, the the process-resources phase will be executed and the add-sources and compile goals will be run for the gatling plugin. Similarly, running mvn test (which is also run when you mvn install) will run the testCompile goal of the gatling plugin.

What you'll want to do is to also bind the execute goal as is exemplified on the page you linked. If you want everyting packaged first, bind it to the integration test phase:

<execution>
  <phase>integration-test</phase>
  <goals>
    <goal>execute</goal>
  </goals>
  <configuration>
     ....
  </configuration>
</execution>

Note that integration-test comes after package (and somewhere before install), so to run it, execute mvn integration-test or mvn install.

Kenney
  • 9,003
  • 15
  • 21
  • It depends on the plugin. If it is a core plugin, it'll be located using some [default groupId's](https://maven.apache.org/guides/introduction/introduction-to-plugin-prefix-mapping.html). You can also specify any random maven plugin to run on the commandline using `mvn groupId:artifactId:version:goal` (or something very close to that syntax). – Kenney Dec 17 '15 at 18:18
  • That `execute` tip is very helpful. But I want this plugin to be run *after* package, not during. I also want to run package everywhere else first. What technique can I use for that? – Daniel Kaplan Dec 17 '15 at 18:22
  • Updated the answer: there's an integration-test phase just for that purpose. – Kenney Dec 17 '15 at 18:31
  • Sorry I communicated poorly. I meant I only want to run this plugin after package *sometimes*, not every time. I don't want this to be triggered after every `package`, I want to explicitly tell it to run. – Daniel Kaplan Dec 17 '15 at 18:38
  • Ah. In that case you can use [profiles](http://maven.apache.org/guides/introduction/introduction-to-profiles.html). See [this answer](http://stackoverflow.com/questions/5443097/conditionally-execute-maven-plugins#5443207) for an example. – Kenney Dec 17 '15 at 18:44
  • 1
    You're welcome. Btw, there's also [`-Dgatling.skip=true`](https://github.com/gatling/gatling/issues/1063); using profiles you can set that to true by default using a `` and override the value with a profile. But defining the plugin within a profile is more portable. Good luck! – Kenney Dec 17 '15 at 18:49