gpt4 book ai didi

maven - 如何正确集成 Maven、Jenkins、Sonar 和 Cobertura?

转载 作者:行者123 更新时间:2023-12-03 23:48:19 25 4
gpt4 key购买 nike

希望有人可以提供帮助。

  • 我们的项目是一个Eclipse插件项目
  • 我们有一个 Jenkins 服务器
  • 我们的项目使用 Maven 和 Tycho(用于插件项目)进行构建管理
  • 我们安装了 Sonar 服务器
  • 我们使用 Jenkins Web-Config 将 Sonar 集成到 Jenkins 中

  • 现在如果我们不使用 Sonar ,一切都好。但是如果我们打开它,Sonar 的 Maven Cobertura 插件会抛出错误。其他一切(就输出而言)都可以。

    现在,据我所知,会发生以下情况:
  • Jenkins 构建项目
  • Sonar 使用其静态代码分析插件和指标(Findbugs、PMD、RFC 等)
  • Sonar 启动 Cobertura 插件
  • Cobertura 尝试再次构建该项目
  • Cobertura 没有成功构建它,因为它以不同的顺序构建它
  • 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 又要 build 这个项目? Jenkins 已经构建了它,Cobertura 可以使用从那里编译的类......或者我误解了什么?

    最佳答案

    我刚刚使用 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 中的转义符;这让我们陷入了几次构建的循环。

    另外,请注意,您不需要包含 sonar:sonar target 在您的 Maven 目标行上...在项目级别启用 Sonar 足以让我们的 Jenkins 工作收集其所有统计信息。

    我认为大约涵盖了它。

    关于maven - 如何正确集成 Maven、Jenkins、Sonar 和 Cobertura?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7890320/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com