You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Eclipse创建Jenkins插件时maven-enforcer-plugin JDK版本错误求助

Fixing "Unknown JDK version given" Error When Building Jenkins Plugin in Eclipse

Let's break down why you're hitting this error and how to fix it step by step:

Root Cause

The maven-enforcer-plugin:3.0.0-M1 you're using has strict version parsing logic—it expects a simplified JDK version string like "1.7" or "1.8", but your system is reporting versions with patch numbers (e.g., "1.8.0-162"). This mismatch causes the plugin to fail validation even though your JDK meets the minimum requirement.

Step 1: Ensure Eclipse Uses a JDK (Not JRE) for the Project

Your current JAVA_HOME points to a JRE, which is likely part of the problem. Maven needs a full JDK to build properly:

  • Right-click your project → Properties → Java Build Path → Libraries
    • Remove the existing JRE System Library
    • Click Add Library → JRE System Library → Alternate JRE → Installed JREs
    • Add your JDK 1.8 installation (e.g., C:\Program Files\Java\jdk1.8.0_162, not the JRE folder) and select it
  • Go to Java Compiler → Check Enable project specific settings
    • Set Compiler compliance level, Generated .class files compatibility, and Source compatibility all to 1.8
  • Go to Maven → Java Runtime → Select the JDK 1.8 entry you just added

Step 2: Explicitly Set Java Version in Maven

Force Maven to use the simplified version string the enforcer plugin expects:

Option A: Add Run Parameters in Eclipse

When running Maven Install:

  1. Right-click project → Run As → Maven Build...
  2. In the Goals field, keep install
  3. Go to the Arguments tab → In Program arguments, add:
    -Dmaven.compiler.source=1.8 -Dmaven.compiler.target=1.8 -Djava.version=1.8
    
  4. Click Run

Option B: Hardcode Versions in pom.xml

Add these properties to your project's pom.xml to enforce the version globally:

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <java.version>1.8</java.version>
</properties>

Step 3: Relax Enforcer Plugin Version Parsing (Optional)

If the above steps don't work, tweak the enforcer plugin configuration to accept patch-level versions:
Add this to your pom.xml's <build><plugins> section:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>3.0.0-M1</version>
    <executions>
        <execution>
            <id>enforce-java</id>
            <goals>
                <goal>enforce</goal>
            </goals>
            <configuration>
                <rules>
                    <requireJavaVersion>
                        <version>[1.8,)</version>
                        <message>Jenkins plugin requires JDK 8 or higher</message>
                        <allowMinorUpdates>true</allowMinorUpdates>
                    </requireJavaVersion>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>

Why Your Previous Changes Didn't Work

Modifying Project Facets or JRE dependencies only affects Eclipse's internal validation, but Maven uses its own runtime settings (often tied to JAVA_HOME or Eclipse's configured Maven JDK). The enforcer plugin was still picking up the full patch-version string from your system, which it couldn't parse correctly.

内容的提问来源于stack exchange,提问作者Johannes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:43:23