I have a WAR Module in a multi-module Maven project (let's say foo-web), which realises a web-service. Then I have a foo-cli, which implements a web service client and tests it in a couple of unit tests.
In order to make this working, I start Jetty before the test phase this way:
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>foo-web</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>test</scope>
</dependency>
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.5.v20120716</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<useTestScope>true</useTestScope>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
</executions>
</plugin>
This works perfectly well while I run 'mvn test' from within the foo-cli module (it even stops automatically, with no need to specify anything else). However, when I attempt to go to the upper level (foo) and issue 'mvn test' from there, i.e., I try to run all the tests for all the modules in the project, it fails with '404 - not found'. From the output, I can see that the overlay (the war dependency) seems to be totally ignored.
Thanks in advance for any help.
You should try moving your integration test to the top level project. This way it will run after the WAR artifact has been built.
Have you had a look at the Maven Failsafe Plugin? It's designed for the sort of thing you're doing, which is actually an integration test and not a unit test. The page offers some good advice on why you might want to use the integration-test phase for your integration testing.
Namely, it describes why you might want to do start-jetty during pre-integration-test and so on, so that you can tear it all down appropriately.
Related
I was tasked to update a project with Maven 3.0 / Java 8 to Maven 3.6 / Java 12. To my best knowledge I did just that, changing all kinds of dependencies. Now when running the build the integration-test phase seems to be missing.
For example, the following plug-in is not called any longer during clean verify:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>do-magic</id>
<phase>pre-integration-test</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- ... -->
</configuration>
</plugin>
I can easily search the build log for do-magic, so I can confirm it's called in Java 8 but not in Java 12 (even though there might be some other changes I'm not aware of right now).
The debug output is:
[DEBUG] Goal: com.google.code.maven-replacer-plugin:maven-replacer-plugin:1.4.1:replace (do-magic)
[DEBUG] Style: Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- same as above-->
</configuration>
So there is no information on why it is not executed.
I tried calling the goal integration-test manually, still the plug-in is not called. There is no additional information either.
I have no idea where to look for the source of the problem. I wouldn't even know where to disable integration tests like this (except for maybe maven.test.skip, which removes the test module from the reactor altogether, so it's not that).
Can anybody shed some light on this issue?
The problem isn't that the integration-test phase is skipped, it's that suddenly maven-surefire-plugin decided it wants to execute the tests as well. That fails, because the pre-integration-test phase is needed for the tests.
I have no idea why that suddenly happened, so here is a pseudo fix that disables Surefire again:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- We run integration tests with failsafe! -->
<skip>true</skip>
</configuration>
</plugin>
I have embedded Jetty in my application. In order to automatically execute my integration tests on my build server I'd like Maven to start my application in the pre-integration-test phase. The integration tests are in another project than the application te be tested, because the tests are of a quite complex nature and should be seperated from production code.
I have tried to set up my application using the Maven exec plugin, but keep running into ClassNotFoundErrors. I use the maven-dependency-plugin to copy all dependencies to target/lib/. Until now, I haven't been able to figure out how to tell the exec plugin to add that lib folder to the class path.
This is my current exec plugin configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>default-cli</id>
<phase>pre-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.zertificon.managementCenter.adminUi.server.WebApp</mainClass>
<!-- this does not work: -->
<classpath>${project.build.directory}/${libFolder}/</classpath>
</configuration>
</execution>
</executions>
</plugin>
The WebApp class I am trying to run originates from another Project and is installed in the local repository. I would highly apreciate any help.
Found the error: I have been using Jetty together with a Selenium Library that itself bundles Jetty, too. This lead to a wrong Jetty Version being loaded wich gave me class not found errors. Go figure.
I want to run Flyway plugin when running integration test in Maven. For integration tests I'm using failsafe plugin.
First of all is it possible to define Flyway plugin two times? One for general usage (eg. from command line) and one for integration test? How to define a seperate configuration in Flyway plugin for integration tests?
You can achieve this through different executions of the plugin. Each execution can have its own configuration.
You can add an execution for Failsafe's pre-integration-test phase with a different configuration, see Maven Failsafe Plugin:
The Maven lifecycle has four phases for running integration tests:
pre-integration-test for setting up the integration test environment.
integration-test for running the integration tests.
post-integration-test for tearing down the integration test environment.
verify for checking the results of the integration tests.
and Guide to Configuring Plug-ins:
Using the <executions> Tag
You can also configure a mojo using the tag. This is most commonly used for mojos that are intended to participate in some phases of the build lifecycle.
For example:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0.3</version>
<configuration>
<url>jdbc:jtds:sqlserver://myCompany.com/generalDatabase</url>
<user>dbUser</user>
<password>password</password>
<locations>
<location>filesystem:src/main/resources/db/migration</location>
</locations>
</configuration>
<dependencies>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.2.7</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<executions>
<execution>
<id>integration-test-database-setup</id>
<phase>pre-integration-test</phase>
<goals>
<goal>clean</goal>
<goal>migrate</goal>
</goals>
<configuration>
<url>jdbc:jtds:sqlserver://myCompany.com/testDatabase</url>
<user>dbUser</user>
<password>password</password>
<locations>
<location>filesystem:src/test/resources/db/migration</location>
</locations>
</configuration>
</execution>
</executions>
</plugin>
Please, someone help me, I'm desperate. I've been trying all night. The problem I have is this: Weird NoClassDef-s with Eclipse Jetty's Maven plugin
Basically: I can't make recent versions of the Jetty plug-in to work properly in an integration test. Indeed, everything works fine until the Jetty's shutdown stage, when I'm told that org.eclipse.jetty.util.FutureCallback is missing.
I've included the dependencies told in the link above. Initially they were ignored, then I've added them in project/build/extensions. Now I've several other ClassNotFoundExceptions and I can't fix that.
This is what I have in my POM:
<plugins>
<!-- This is activated before tests and uses the overlay import mechanism -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<systemProperties>
<!-- Triggers test data creation in uk.ac.ebi.fg.myequivalents.webservices.server.test.WebTestDataInitializer -->
<systemProperty>
<name>uk.ac.ebi.fg.myequivalents.test_flag</name>
<value>true</value>
</systemProperty>
</systemProperties>
<scanIntervalSeconds>10</scanIntervalSeconds>
<useTestScope>true</useTestScope>
<httpConnector>
<!-- 8080 is often busy on EBI hosts -->
<port>10973</port>
</httpConnector>
<stopPort>10974</stopPort>
<stopKey>KILL</stopKey>
</configuration>
<executions>
<!--
starts jetty before tests and stops it afterwards. Note that no stop goal is needed, it magically stops
after tests
-->
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
And these are the extesions I've set up:
<extensions>
<extension>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
</extension>
<extension>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jsp</artifactId>
<version>${jetty.version}</version>
</extension>
<extension>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>${jetty.version}</version>
</extension>
<extension>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jaspi</artifactId>
<version>${jetty.version}</version>
</extension>
</extensions>
${jetty.version} is defined in the parent and = 9.1.3.v20140225, but I've tried many, down to 7.x
Moreover, Maven is 3.2.1, Java is 1.7.0_51, running on OS X 10.9.2
Thank you in advance for any help for this nasty issue.
I've found it!!! Apparently, the problem is the 'stop' goal is (rightly) attached to the 'post-integration-test' phase. So, if you issue 'mvn integration-test', such phase, as far as I understand, is not reached (http://tinyurl.com/omwulm5). By just giving 'mvn verify' or 'install', and without adding any Jetty-related dependency to the POM (everything needed should now be included in 9.1.x), Maven completed without any complaint (hooray!).
This might look silly to readers smarter than me, I'm reporting it nonetheless, just in case you're struggling as much as I've just done for hours.
You should not be using the "run" goal with an execution binding. Instead, you should be using the "start" goal. See the documentation here: http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html#jetty-start-goal
The difference is that the "run" goal will run a fresh build up until the "test-compile" phase. The "start" goal does not invoke a parallel build and simply runs at whatever phase it is bound to.
Jan
Just try to add <stopWait>10</stopWait> to plugin configuration.
Full configuration you can see in this answer.
I have a Java project in Eclipse, with JUnit tests in my src/test directory. I've also added a class to my tests with Caliper microbenchmarks, and I'd like to be able to run these tests from within Eclipse.
As the Caliper code is test code, I've added Caliper as a dependency in Maven in test scope. That makes it show up in the classpath when I run JUnit tests, but I can't see a way to run an arbitrary class with test dependencies in the classpath. What I tried doing was adding a new Run Configuration for a Java Application, thinking I could launch CaliperMain with the right class as a parameter, but the Caliper jar is not on the classpath and I can't see how to add it.
I don't want to move my benchmark code and dependency into the main scope, as it's test code! It seems seriously overkill to move it into a completely separate project.
You should be able to do this with the Maven Exec Plugin. For my project, I opted to make a benchmark profile that can be run with the maven command mvn compile -P benchmarks.
To configure something like this, you can add something along the lines of the following to your pom.xml, specifying scope of the classpath as test using the <classpathScope> tag:
<profiles>
<profile>
<id>benchmarks</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>caliper</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>com.google.caliper.runner.CaliperMain</mainClass>
<commandlineArgs>com.stackoverflow.BencharkClass,com.stackoverflow.AnotherBenchmark</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Alternatively, if you'd like to specify a lot of options for caliper, it is probably easier to use the <arguments> tags:
<executions>
<execution>
<id>caliper</id>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<classpathScope>test</classpathScope>
<mainClass>com.google.caliper.runner.CaliperMain</mainClass>
<arguments>
<argument>com.stackoverflow.BencharkClass</argument>
<argument>--instrument</argument>
<argument>runtime</argument>
<argument>-Cinstrument.allocation.options.trackAllocations=false</argument>
</arguments>
</configuration>
</execution>
</executions>
More configuration options (like -Cinstrument.allocation.options.trackAllocations above) can be found here and more runtime options (like --instrument above) can be found here.
Then, if you are using the Eclipse m2 Maven plugin, you can right-click on your project folder and select Run as... -> Maven Build... and enter something like clean install in the Goals input box and benchmarks in the Profiles input box and click Run and you should see the output in your Eclipse console.
It's important to note that I used a local snapshot build of Caliper by checking out the source using git clone https://code.google.com/p/caliper/, which is recommended at the time of this post in order to take advantage of the latest API.