【问题标题】:How to include dependencies targeting JDK 1.8 in jenkins plugin?如何在 jenkins 插件中包含针对 JDK 1.8 的依赖项?
【发布时间】:2017-07-09 13:49:35
【问题描述】:

我已经按照 official tutorial 创建 Jenkins 插件:我已经运行 mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create 来生成初始 POM

然后我添加了番石榴作为依赖项。

但是,当我执行mvn package 时,我得到:

[INFO] --- maven-enforcer-plugin:1.4.2.jenkins-1:enforce (display-info) @ flaky-tests ---
[INFO] Restricted to JDK 1.7 yet com.google.guava:guava:jar:22.0:compile contains com/google/common/annotations/Beta.class targeted to JDK 1.8
...
[WARNING] Rule 2: org.apache.maven.plugins.enforcer.EnforceBytecodeVersion failed with message:
Found Banned Dependency: com.google.guava:guava:jar:22.0
Use 'mvn dependency:tree' to locate the source of the banned dependencies.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

如何在我的 Jenkins 插件中包含针对 JDK 1.8 的依赖项?

这是我的完整 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>2.32</version>
        <relativePath/>
    </parent>

    <groupId>com.github.dzieciou.testing</groupId>
    <artifactId>flaky-tests</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>hpi</packaging>

    <properties>
        <jenkins.version>2.68</jenkins.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <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>

    <dependencies>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>22.0</version>
        </dependency>
    </dependencies>

</project>

【问题讨论】:

    标签: java maven jenkins jenkins-plugins


    【解决方案1】:

    在 POM 中添加以下属性就足够了:

    <java.level>8</java.level>
    

    【讨论】:

    • 太好了,工作!你应该把你的答案标记为正确的:)
    • 谢谢大佬,没想到这么简单的回答就能解决问题!
    猜你喜欢
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 2014-04-04
    • 2016-02-23
    • 1970-01-01
    • 2019-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多