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

时间:2017-07-09 13:49:35

标签: java maven jenkins jenkins-plugins

我已按照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>

1 个答案:

答案 0 :(得分:8)

将以下属性添加到POM就足够了:

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