【问题标题】:Why is maven not able to find added dependency (Some Enforcer rules have failed)为什么 maven 无法找到添加的依赖项(某些 Enforcer 规则已失败)
【发布时间】:2021-07-01 15:35:06
【问题描述】:

我正在使用此处的教程作为起点构建 Jenkins 插件:https://www.jenkins.io/doc/developer/tutorial/create/

我已经完成了教程,一切正常。现在我想添加真正的功能,所以我需要添加几个依赖项。我是 maven 新手,但我一般都知道我需要添加依赖 XML 部分。

这是我的 POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.jenkins-ci.plugins</groupId>
        <artifactId>plugin</artifactId>
        <version>4.16</version>
        <relativePath />
    </parent>
    <groupId>io.jenkins.plugins</groupId>
    <artifactId>bdptest</artifactId>
    <version>${revision}${changelist}</version>
    <packaging>hpi</packaging>
    <properties>
        <revision>1.0</revision>
        <changelist>-SNAPSHOT</changelist>

        <!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
        <jenkins.version>2.277.1</jenkins.version>
        <java.level>8</java.level>
        <gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>    </properties>
    <name>BDPTest Plugin</name>
    <url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Pick up common dependencies for the selected LTS line: https://github.com/jenkinsci/bom#usage -->
                <groupId>io.jenkins.tools.bom</groupId>
                <artifactId>bom-2.277.x</artifactId>
                <version>25</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jenkins-ci.plugins</groupId>
            <artifactId>structs</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jenkins-ci.plugins.workflow</groupId>
            <artifactId>workflow-cps</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jenkins-ci.plugins.workflow</groupId>
            <artifactId>workflow-job</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jenkins-ci.plugins.workflow</groupId>
            <artifactId>workflow-basic-steps</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jenkins-ci.plugins.workflow</groupId>
            <artifactId>workflow-durable-task-step</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.9.1</version>
        </dependency>
    </dependencies>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>https://opensource.org/licenses/MIT</url>
        </license>
    </licenses>
    <scm>
        <connection>scm:git:git://github.com/${gitHubRepo}.git</connection>
        <developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
        <url>https://github.com/${gitHubRepo}</url>
        <tag>${scmTag}</tag>
    </scm>

    <repositories>
        <repository>
            <id>repo.jenkins-ci.org</id>
            <url>https://repo.jenkins-ci.org/public/</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>repo.jenkins-ci.org</id>
            <url>https://repo.jenkins-ci.org/public/</url>
        </pluginRepository>
    </pluginRepositories>
</project>

除了这一点之外的一切:

        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.9.1</version>
        </dependency>

来自教程并且正在工作。但是,当我添加那个单一的依赖项时,没有运气。尝试做一个 mvn hpi:run 帖子添加我得到的依赖项:

[WARNING] Rule 5: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for org.jetbrains.kotlin:kotlin-stdlib-common:1.4.0 paths to dependency are:
+-io.jenkins.plugins:bdptest:1.0-SNAPSHOT
  +-com.squareup.okhttp3:okhttp:4.9.1
    +-com.squareup.okio:okio:2.8.0
      +-org.jetbrains.kotlin:kotlin-stdlib-common:1.4.0
and
+-io.jenkins.plugins:bdptest:1.0-SNAPSHOT
  +-com.squareup.okhttp3:okhttp:4.9.1
    +-org.jetbrains.kotlin:kotlin-stdlib:1.4.10
      +-org.jetbrains.kotlin:kotlin-stdlib-common:1.4.10
]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.515 s
[INFO] Finished at: 2021-04-05T13:25:50-06:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M3:enforce (display-info) on project bdptest: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

谁能帮我弄清楚怎么回事?

【问题讨论】:

  • 我发现 4.9.1 是问题....尝试了 4.2.2 并且它有效...生活和学习。

标签: java maven jenkins-plugins


【解决方案1】:

尝试将 Kotlin 标准库显式添加到您的依赖项中

        <!-- required by OkHTTP -->
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-common</artifactId>
            <version>1.4.10</version>
        </dependency>

【讨论】:

    猜你喜欢
    • 2021-10-23
    • 2016-03-31
    • 2015-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 2016-09-15
    相关资源
    最近更新 更多