如何使用java11创建jenkins插件

时间:2019-04-29 06:33:09

标签: maven jenkins-plugins java-11

我正在用java11和maven项目创建jenkins插件,但收到错误:-

[错误]无法在项目abcdef上执行目标org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M2:enforce(显示信息):目标org.apache的执行显示信息。 maven.plugins:maven-enforcer-plugin:3.0.0-M2:enforce失败:给出了未知的JDK版本。应该是“ 1.7”,“ 8”,“ 11”,“ 12”之类的

URL中提到的以下步骤:-https://wiki.jenkins.io/display/JENKINS/Java+11+Developer+Guidelines

<parent>
 <groupId>org.jenkins-ci.plugins</groupId>
 <artifactId>plugin</artifactId>
 <version>3.42</version>
</parent>

<properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <java.level>11</java.level>
</properties>

<dependencies>
 <dependency>
  <groupId>org.jenkins-ci.main</groupId>
  <artifactId>jenkins-core</artifactId>
  <version>2.173</version>
 </dependency>
</dependencies>

在jenkins hello world插件中也遵循上述步骤,并收到相同的错误。根据URL中提到的详细信息,jenkins支持java11,因此希望.hpi文件应使用java11创建。

1 个答案:

答案 0 :(得分:0)

我通过更改pom.xml来解决上述错误:

<build>
 <plugins>
  <plugin>
   <artifactId>maven-enforcer-plugin</artifactId>
   <executions>
    <execution>
     <id>display-info</id>
     <phase>validate</phase>
     <goals>
      <goal>display-info</goal>
     <goal>enforce</goal>
    </goals>
    <configuration>
     <rules>
      <requireJavaVersion>
       <version>11</version>
      </requireJavaVersion>
      <enforceBytecodeVersion>
       <maxJdkVersion>11</maxJdkVersion>
      </enforceBytecodeVersion>
     </rules>
    </configuration>
   </execution>
  </executions>
 </plugin>
 <plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
   <source>11</source>
   <target>11</target>
   <testSource>11</testSource>
   <testTarget>11</testTarget>
  </configuration>
 </plugin>
</plugins>
</build>

现在收到新错误: [错误]无法在项目测试中执行目标org.kohsuke:access-modifier-checker:1.16:enforce(default-enforce)。执行目标org.kohsuke:access-modifier-checker:1.16:enforce的默认实施失败。 IllegalArgumentException