I am running jUnit4 tests, built with Maven, on a Jenkins box. My goal is to restore a test database before executing the tests.
It looks like exec-maven-plugin is the way to go, but I cannot get it running. Any pointers? Although there are lots of examples, the doc on the mojo site is pretty thin.
The class I need to run currently lives at:
MyProject.src.test.java._tools.BuildTestEnvironment.java
My pom.xml includes:
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>build-test-environment</id>
<phase>generate-test-resources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>src.test.java._tools.BuildTestEnvironment</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Run this in Jenkins, nothing really happens. If I run it locally, I get
Things I have tried, without success:
Run the build in Jenkins: Nothing really happens. The project builds and starts running tests, but my class is not run.
Run the build locally: Same result as in Jenkins. No surprise there.
Run generate-test-resources locally: ClassNotFoundException. ie:
mvn exec:java generate-test-resources
java.lang.ClassNotFoundException: src.test.java._tools.BuildTestEnvironmentCompile the class into a jar, and add that to my pom.
Update:
After reading @ppuskar's comments, I tried moving my buildxxx class around a bit. After moving it to src.main.java._tools.BuildTestEnvironment, I still get a similar message. Here is my build log, in case that helps:
[DEBUG] Invoking : test.java._tools.BuildTestEnvironment.main()
[DEBUG] Plugin Dependencies will be excluded.
[DEBUG] Project Dependencies will be included.
[DEBUG] Collected project artifacts [joda-time:joda-time:jar:2.3:compile, net.sf.jt400:jt400:jar:6.7:compile, junit:junit:jar:4.11:compile, org.hamcrest:hamcrest-core:jar:1.3:compile, com.fasterxml.jackson.core:jackson-core:jar:2.3.0:compile, com.fasterxml.jackson.core:jackson-databind:jar:2.3.0:compile, com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile, org.hamcrest:hamcrest-all:jar:1.3:compile, org.apache.logging.log4j:log4j-api:jar:2.0-rc1:compile, org.apache.logging.log4j:log4j-core:jar:2.0-rc1:compile]
[DEBUG] Collected project classpath [C:\workspace\VSP_UnitTest\target\classes]
[DEBUG] Adding to classpath : file:/C:/workspace/VSP_UnitTest/target/classes/
[DEBUG] Adding project dependency artifact: joda-time to classpath
[DEBUG] Adding project dependency artifact: jt400 to classpath
[DEBUG] Adding project dependency artifact: junit to classpath
[DEBUG] Adding project dependency artifact: hamcrest-core to classpath
[DEBUG] Adding project dependency artifact: jackson-core to classpath
[DEBUG] Adding project dependency artifact: jackson-databind to classpath
[DEBUG] Adding project dependency artifact: jackson-annotations to classpath
[DEBUG] Adding project dependency artifact: hamcrest-all to classpath
[DEBUG] Adding project dependency artifact: log4j-api to classpath
[DEBUG] Adding project dependency artifact: log4j-core to classpath
[DEBUG] joining on thread Thread[test.java._tools.BuildTestEnvironment.main(),5,test.java._tools.BuildTestEnvironment]
[WARNING] java.lang.ClassNotFoundException: test.java._tools.BuildTestEnvironment
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
at java.lang.Thread.run(Thread.java:724)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.602 s
[INFO] Finished at: 2014-05-15T14:38:50-05:00
[INFO] Final Memory: 12M/152M
[INFO] ------------------------------------------------------------------------