简体   繁体   English

IntelliJ 目标字节码恢复

[英]IntelliJ target bytecode reverting

For a project that I'm currently working on, IntelliJ gave me the compile error Error:java: javacTask: source release 8 requires target release 1.8 .对于我目前正在处理的项目,IntelliJ 给了我编译错误Error:java: javacTask: source release 8 requires target release 1.8 I went into Settings>Build, Execution, Deployment>Compiler>Java and saw that the target bytecode version for one of my modules was set to 1.5, so I changed it to 1.8, compiled, and it worked.我进入设置>构建,执行,部署>编译器>Java,看到我的一个模块的目标字节码版本被设置为1.5,所以我将它更改为1.8,编译,它工作了。 But then the next day, I got the same error.但是第二天,我得到了同样的错误。 I went into settings and the target bytecode for that one module was back at 1.5.我进入了设置,那个模块的目标字节码又回到了 1.5。 I changed it to 1.8 and it compiled/ran just fine.我将其更改为 1.8,并且编译/运行得很好。 This has now happened multiple times and I am frustrated by the number of times I have to go into settings to manually change the target bytecode version.这已经发生了多次,我对必须进入设置以手动更改目标字节码版本的次数感到沮丧。

Why does the target bytecode version keep reverting?为什么目标字节码版本不断恢复? I don't have 1.5 specified in the pom or anywhere else, so I am baffled as to why the bytecode version keeps getting set to 1.5.我没有在 pom 或其他任何地方指定 1.5,所以我很困惑为什么字节码版本一直设置为 1.5。

You need to specify the source and target versions in your pom.xml file, but since the maven-compiler-plugin is added by default, an easier way to do that would be to set the following properties:您需要在 pom.xml 文件中指定源版本和目标版本,但由于默认情况下添加了maven-compiler-plugin ,因此更简单的方法是设置以下属性:

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

You need to dd this to your POM:您需要将此添加到您的 POM 中:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

FYI.供参考。

I still had this problem despite setting the pom.xml with both the settings above from the answers as mentioned by @isapir and @carlos-a-ibarra respectively.尽管从@isapir 和@carlos-a-ibarra 分别提到的答案中使用上述两个设置设置了pom.xml ,但我仍然遇到了这个问题。

I discovered this was due to an Intellij setting:我发现这是由于 Intellij 设置造成的:

Intellij Maven 设置的屏幕截图

This config can be found in Build,Execution,Deployment > Build Tools > Maven > Importing这个配置可以在 Build,Execution,Deployment > Build Tools > Maven > Importing 中找到

By default, it is set to the 'Internal JRE' setting, which in the latest version of Idea is 11. I had to select it to use the 1.8 JDK the project was configured to use.默认情况下,它被设置为“内部 JRE”设置,在最新版本的 Idea 中是 11。我不得不选择它来使用项目配置使用的 1.8 JDK。

This is annoying, because if you have a mix of 11 and 8 projects, you'll have to manually toggle this setting back and forth.这很烦人,因为如果您混合使用 11 个和 8 个项目,则必须手动来回切换此设置。

It caused the module output to always fall back to 11 every time the pom.xml was reimported.它导致每次重新导入pom.xml时,模块输出总是回退到 11。

intellij idea 项目模块设置

It's a really annoying bug in IntelliJ.这是 IntelliJ 中一个非常烦人的错误。

Please try below option, it worked for me.请尝试以下选项,它对我有用。

step 01: Change the version under Module and project.步骤01:更改模块和项目下的版本。 step 02: build the module.步骤02:构建模块。

Hope it should resolve the issue.希望它应该解决问题。

在此处输入图片说明

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM