1

我使用maven构建项目并对代码进行静态分析。但是,当我在 Jenkins 作业中运行这些命令时,reuslt 是不同的。

本地

$ mvn emma:emma pmd:cpd pmd:pmd javadoc:javadoc

然后我得到目标\站点在此处输入图像描述

在 Jenkins 工作中,构建部分,目标和选项

emma:emma pmd:cpd pmd:pmd javadoc:javadoc

遇到错误,因为缺少带有报告的 target\site\emma 文件夹。在此处输入图像描述

...
Emma: looking for coverage reports in the entire workspace: /home/jenkins/jenkins-home/workspace/Atlas_Master_Maven
Emma: no coverage files found in workspace. Was any report generated?
Build step 'Record Emma coverage report' changed build result to FAILURE
...

本地是 Windows 7 64x,远程 Jenkins 是 CentOS。两者都有 Maven 3.0.4。

为什么会发生这种情况,以及如何在 Jenkins 中获得相同的结果?

4

1 回答 1

1

仔细查看 Jenkins 作业输出,我发现未执行单元测试,因此 emma 没有数据可继续。谢谢@eis。是的,没有魔法。

[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ atlas ---
[INFO] Surefire report directory: /home/jenkins/jenkins-home/workspace/Atlas_Master_Maven/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: java.lang.NoClassDefFoundError: com/funshion/base/service/ServiceException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
    at java.lang.Class.getMethod0(Class.java:2670)
    at java.lang.Class.getMethod(Class.java:1603)
    at org.apache.maven.surefire.util.ReflectionUtils.tryGetMethod(ReflectionUtils.java:57)
    at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isSuiteOnly(JUnit3TestChecker.java:65)
    at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isValidJUnit3Test(JUnit3TestChecker.java:60)
    at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.accept(JUnit3TestChecker.java:55)
    at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.accept(JUnit4TestChecker.java:52)
    at org.apache.maven.surefire.util.DefaultDirectoryScanner.locateTestClasses(DefaultDirectoryScanner.java:80)
    at org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(JUnit4Provider.java:174)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:83)
    ... 9 more
Caused by: java.lang.ClassNotFoundException: com.funshion.base.service.ServiceException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 21 more

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

mojoSucceeded org.apache.maven.plugins:maven-surefire-plugin:2.10(default-test)
[JENKINS] Recording test results
forkedProjectSucceeded com.funshion.microlens:atlas:1.1.5.BUILD-SNAPSHOT
mojoStarted org.codehaus.mojo:emma-maven-plugin:1.0-alpha-3(default-cli)
[INFO] 
[INFO] --- emma-maven-plugin:1.0-alpha-3:emma (default-cli) @ atlas ---
processing input files ...
mojoSucceeded org.codehaus.mojo:emma-maven-plugin:1.0-alpha-3(default-cli)1 file(s) read and merged in 114 ms
nothing to do: no runtime coverage data found in any of the data files
于 2013-01-05T06:27:27.003 回答