现在如果我们不使用Sonar,一切都还可以。但是如果我们打开它,Sonar的Maven Cobertura插件会抛出错误。其他一切(就输出而言)都没问题。
现在,根据我的理解,会发生以下情况:
Jenkins的一些输出摘录:
[INFO] ------------------------------------------------------------------------
[INFO] Building Project
[INFO] ------------------------------------------------------------------------
[WARNING] The following dependencies could not be resolved at this point of the build but seem to be part of the reactor:
[WARNING] o de.tool.core:de.tool.core:eclipse-plugin:1.2.0-SNAPSHOT (provided)
[WARNING] Try running the build up to the lifecycle phase "package"
后来......构建顺序是核心在进化之前构建,但进化似乎是Cobertura想要构建的第一件事......
[INFO] Execute maven plugin cobertura-maven-plugin...
[INFO] Execute org.codehaus.mojo:cobertura-maven-plugin:2.5:cobertura...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building de.tool.evolution 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> cobertura-maven-plugin:2.5:cobertura (default-cli) @ de.tool.evolution >>>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.240s
[INFO] Finished at: Tue Oct 25 11:28:29 CEST 2011
[INFO] Final Memory: 57M/231M
之后构建总是这样:
[INFO] ------------------------------------------------------------------------
[INFO] Building de.tool.core 1.2.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> cobertura-maven-plugin:2.5:cobertura (default-cli) @ de.tool.core >>>
[INFO]
[INFO] --- tycho-packaging-plugin:0.13.0:build-qualifier (default-build-qualifier) @ de.tool.core ---
[INFO]
[INFO] --- tycho-packaging-plugin:0.13.0:validate-id (default-validate-id) @ de.tool.core ---
[INFO]
[INFO] --- tycho-packaging-plugin:0.13.0:validate-version (default-validate-version) @ de.tool.core ---
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ de.tool.core ---
[INFO] Using 'Cp1252' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/jobs/testBuild/workspace/de.tool.core/src/main/resources
[INFO]
[INFO] --- tycho-compiler-plugin:0.13.0:compile (default-compile) @ de.tool.core ---
[INFO] Using compile source roots from build.properties
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- cobertura-maven-plugin:2.5:instrument (default-cli) @ de.tool.core ---
[INFO] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Instrumenting 88 files to /var/lib/jenkins/jobs/testBuild/workspace/de.tool.core/target/generated-classes/cobertura
Cobertura: Saved information on 88 classes.
Instrument time: 256ms
[INFO] Instrumentation was successful.
[INFO] NOT adding cobertura ser file to attached artifacts list.
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ de.tool.core ---
[INFO] Using 'Cp1252' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/jobs/testBuild/workspace/de.tool.core/src/test/resources
[INFO]
[INFO] <<< cobertura-maven-plugin:2.5:cobertura (default-cli) @ de.tool.core <<<
[INFO]
[INFO] --- cobertura-maven-plugin:2.5:cobertura (default-cli) @ de.tool.core ---
[INFO] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Cobertura: Loaded information on 88 classes.
Report time: 800ms
[INFO] Cobertura Report generation was successful.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 50.133s
[INFO] Finished at: Tue Oct 25 11:28:44 CEST 2011
[INFO] Final Memory: 33M/263M
接着是警告:
[INFO] Java bytecode scan...
[WARN] Class 'de/tool/core/util/EObjectUtil' is not accessible through the ClassLoader.
[INFO] Java bytecode scan done: 105 ms
...
The following classes needed for analysis were missing:
de.tool.core.util.EObjectUtil
......并且在肠道中最后一击:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] de.tool.core ............................... SUCCESS [2.364s]
[INFO] de.tool.evolution .......................... FAILURE [0.023s]
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:52.418s
[INFO] Finished at: Tue Oct 25 11:29:46 CEST 2011
[INFO] Final Memory: 51M/411M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project de.tool.evolution: Could not resolve dependencies for project de.tool.evolution:de.tool.evolution:eclipse-plugin:1.0.0-SNAPSHOT: Could not find artifact de.tool.core:de.tool.core:eclipse-plugin:1.2.0-SNAPSHOT -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project de.tool.evolution: Could not resolve dependencies for project de.tool.evolution:de.tool.evolution:eclipse-plugin:1.0.0-SNAPSHOT: Could not find artifact de.tool.core:de.tool.core:eclipse-plugin:1.2.0-SNAPSHOT
我的猜测是Sonar中的构建顺序不正确。但是它会如何变得混乱(因为Jenkins以正确的顺序构建项目)?
为什么地球上的Cobertura会再次建造这个项目? Jenkins已经构建了它,Cobertura可以使用那里编译的类......或者我误解了什么?
答案 0 :(得分:12)
我刚刚完成了使用Sonar配置我公司的Jenkins服务器,以便与Maven构建的项目一起使用。所以这是我必须经历的步骤。
在我的pom.xml(Maven2版本)中,我不得不添加以下代码:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>1.0-beta-2</version>
</plugin>
在我们的Linux构建服务器上,我们已经安装了MySQL,因此我们按照Wakaleo Consulting的说明,了解如何让Sonar与MySQL通信。请注意Jenkins配置部分中MySQL URL中的转义&符号;这让我们为一些构建做了一个循环。
另外,请注意您不需要在Maven目标行中包含sonar:sonar
目标...在项目级别启用Sonar足以让我们的Jenkins工作收集所有的统计数据。
我认为这涵盖了它。