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

使用Maven为不同JVM版本构建多Jar包时出现编译错误如何解决?

问题原因

  • 你自定义的jdk-17-compile、jdk-11-compile属于额外追加的编译执行节点,没有覆盖maven-compiler-plugin自带的default-compile默认执行逻辑
  • 默认执行逻辑没有配置source/target/release参数,maven-compiler-plugin:3.8.1的默认编译源版本和目标版本为1.6,而JDK17已经不再支持1.6版本的编译目标,所以默认执行环节就触发了报错,你自定义的两个编译任务还未执行就已终止。

修复方案

在maven-compiler-plugin的executions节点中新增配置,禁用默认的编译执行即可,修正后的插件配置如下:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <executions>
        <!-- 新增:禁用默认编译执行 -->
        <execution>
            <id>default-compile</id>
            <phase>none</phase>
        </execution>
        <!-- 以下是原有自定义编译配置 -->
        <execution>
            <id>jdk-17-compile</id>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <release>17</release>
                <outputDirectory>${project.build.outputDirectory}-jdk17</outputDirectory>
            </configuration>
        </execution>
        <execution>
            <id>jdk-11-compile</id>
            <goals>
                <goal>compile</goal>
            </goals>
            <configuration>
                <release>11</release>
                <outputDirectory>${project.build.outputDirectory}-jdk11</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

如果后续需要执行test相关的编译目标,同样需要按照相同逻辑禁用默认的default-testCompile执行,再自定义对应JDK版本的测试编译配置即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 16:36:01