bob*_*alf 3 java maven exec-maven-plugin jenkins
我在Jenkins盒子上运行使用Maven构建的jUnit4测试.我的目标是在执行测试之前恢复测试数据库.
看起来像exec-maven-plugin是要走的路,但是我无法让它运行起来.有什么指针吗?虽然有很多例子,但mojo网站上的文档非常简洁.
我现在需要运行的课程住在:
MyProject.src.test.java._tools.BuildTestEnvironment.java
我的pom.xml包括:
<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 Code Online (Sandbox Code Playgroud)
在Jenkins运行,没有任何事情发生.如果我在本地运行它,我会
我尝试过的事情没有成功:
在Jenkins中运行构建:没有任何事情发生.该项目构建并开始运行测试,但我的课程没有运行.
在本地运行构建:与Jenkins中的结果相同.这并不奇怪.
在本地运行generate-test-resources:ClassNotFoundException.即:
mvn exec:java generate-test-resources
java.lang.ClassNotFoundException:src.test.java._tools.BuildTestEnvironment
将类编译成jar,然后将其添加到我的pom中.
更新:
在阅读@ ppuskar的评论之后,我尝试了一下我的buildxxx类.将它移动到src.main.java._tools.BuildTestEnvironment后,我仍然收到类似的消息.这是我的构建日志,如果有帮助:
[DEBUG]调用:test.java._tools.BuildTestEnvironment.main()
[DEBUG]插件依赖项将被排除.
[DEBUG]将包括项目依赖项.
[DEBUG]收集的项目工件[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]收集项目类路径[C:\ workspace\VSP_UnitTest\target\classes]
[DEBUG]添加到classpath:file:/C:/ workspace/VSP_UnitTest/target/classes/
[DEBUG]添加项目依赖项工件:joda-time到classpath
[DEBUG]添加项目依赖项工件:jt400到classpath
[DEBUG]添加项目依赖项工件:junit到classpath
[DEBUG]添加项目依赖项工件:hamcrest-core到classpath
[DEBUG]添加项目依赖项工件:jackson -core to classpath
[DEBUG]添加项目依赖项工件:jackson-databind到classpath
[DEBUG]添加项目依赖项工件:jackson-annotations到classpath
[DEBUG]添加项目依赖项工件:hamcrest-all到classpath
[DEBUG]添加项目依赖项工件:log4j-api到classpath
[DEBUG]添加项目依赖项工件:log4j-core到类路径
[DEBUG]加入线程Thread [test.java._tools.BuildTestEnvironment.main(),5,test.java._tools.BuildTestEnvironment]
[警告] java.lang.ClassNotFoundException:
java.net.URLClassLoader $ 1.run中的test.java._tools.BuildTestEnvironment(URLClassLoader.java:366)
java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)
. 在java.lang.ClassLoader.loadClass(ClassLoader.java:424)的
java.net.URLClassLoader.findClass(URLClassLoader.java:354)
上的security.AccessController.doPrivileged(Native Method),
位于java.lang.ClassLoader.loadClass(ClassLoader. java:357)
at org.codehaus.mojo.exec.ExecJavaMojo $ 1.run(ExecJavaMojo.java:281)
at at java.lang.Thread.run(Thread.java:724)
[INFO] --------------------------------- ---------------------------------------
[INFO] BUILD FAILURE
[INFO] --- -------------------------------------------------- -------------------
[INFO]总时间:2.602秒
[INFO]完成时间:2014-05-15T14:38:50-05:00
[INFO]决赛记忆:12M/152M
[INFO] ------------------------------------------ ------------------------------
我想留下这个评论来解决Rebzie的评论,但我没有声誉.
但是,您在主配置中有测试配置
Exec Maven插件支持更改类路径范围,以便您可以使用测试范围的资源,而无需将它们移出测试包,如下所示:
<configuration>
<mainClass>src.test.java._tools.BuildTestEnvironment</mainClass>
<classpathScope>test</classpathScope>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这提供了一个干净的解决方案,您的测试设置代码将保留在测试资源中.
小智 5
我正在尝试一些非常相似的东西,如果有人偶然发现的话,我只是将我的发现留在这里。我计划在测试中开设一个课程,创建一些测试资源,然后运行实际测试。
核心问题是maven阶段test-compile运行在 generate-test-resources. 执行时测试分支中的代码尚未编译,因此 exec-plugin 找不到已编译的类。
我的临时解决方案是将 exec-plugin 附加到 Phase process-test-classes。
小智 4
尝试BuildTestEnvironment.java从src.test.java._tools到src.main.java._tools
ie 你的班级将是 src.main.java._tools.BuildTestEnvironment
我尝试运行您提供的场景。正如你所说,它失败了,但是我将 java 文件从 test 移动到 main .... 它 RAN :)
干杯:)
| 归档时间: |
|
| 查看次数: |
5509 次 |
| 最近记录: |