IDEA: javac: source release 1.7 requires target release 1.7

后端 未结 18 1109
青春惊慌失措
青春惊慌失措 2020-11-22 06:26

When running a JUnit test, using IntelliJ IDEA, I get

\"enter

How can I correc

相关标签:
18条回答
  • 2020-11-22 06:52

    I resolved bellow method

    File >> Project Structure >> Project >> Project Language Level --> do set proper version (ex: 1.5)

    0 讨论(0)
  • 2020-11-22 06:54

    If it is a Gradle project, in your build.gradle file, search for following settings:

    sourceCompatibility = "xx"
    targetCompatibility = "xx"
    

    For all subrpojects, in your root build.gradle file, you may put:

    subprojects { project ->
        sourceCompatibility = "1.7"
        targetCompatibility = "1.7"
    }
    

    Although you can manually set language levels in Idea > Settings, if it is a Gradle project, Idea automatically synchronizes module .iml files from Gradle settings ( tested with Idea 15+). So all your manual changes are overriden when gradle is refreshed.

    Based on Gradle documentation, if these are not set, then current JVM configuration is used.

    0 讨论(0)
  • 2020-11-22 06:56

    IntelliJ 15, 2016 & 2017

    Similar to that discussed below for IntelliJ 13 & 14, but with an extra level in the Settings/Preferences panel: Settings > Build, Execution, Deployment > Compiler > Java Compiler.

    IntelliJ 13 & 14

    In IntelliJ 13 and 14, check the Settings > Compiler > Java Compiler UI to ensure you're not targeting a different bytecode version in your module.

    enter image description here

    0 讨论(0)
  • 2020-11-22 06:56

    I've found required options ('target bytecode version') in settings > compiler > java compiler in my case (intelij idea 12.1.3)

    0 讨论(0)
  • 2020-11-22 06:56

    Modify the compiler setting file of the project in the following path and change the 'target' to 1.7:

    /project/.idea/compiler.xml

    <bytecodeTargetLevel>
      <module name="project-name" target="1.7" />
    </bytecodeTargetLevel>
    
    0 讨论(0)
  • 2020-11-22 06:59

    Most likely you have incorrect compiler options imported from Maven here:

    compiler options

    Also check project and module bytecode (target) version settings outlined on the screenshot.

    Other places where the source language level is configured:

    • Project Structure | Project

    • Project Structure | Modules (check every module) | Sources

    Maven default language level is 1.5 (5.0), you will see this version as the Module language level on the screenshot above.

    This can be changed using maven-compiler-plugin configuration inside pom.xml:

    <project>
      [...]
      <build>
        [...]
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
        </plugins>
        [...]
      </build>
      [...]
    </project>
    

    or

    <project>
      [...]
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
      </properties>
      [...]
    </project>
    

    IntelliJ IDEA will respect this setting after you Reimport the Maven project in the Maven Projects tool window:

    0 讨论(0)
提交回复
热议问题