Handle different language and target levels for sources and tests with IntelliJ IDEA

前端 未结 2 1569
广开言路
广开言路 2021-01-02 00:47

I\'m interested if someone has clue how to handle this pom in projects properties of IDEA:


   org.apache.maven.plugins

        
相关标签:
2条回答
  • 2021-01-02 01:30

    As already mentioned different language levels for main and test sources are not yet supported by Idea.

    There's a workaround to force Idea to use the language level defined in testSource when importing Maven project. You can create a separate Maven profile only for Idea with different compiler plugin settings:

    <profiles>
    
        <profile>
            <id>default</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.2</version>
                        <configuration>
                            <source>1.6</source>
                            <target>1.6</target>
                            <testSource>1.8</testSource>
                            <testTarget>1.8</testTarget>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    
        <profile>
            <id>ide</id>
            <activation>
                <activeByDefault>false</activeByDefault>
                <property>
                    <name>idea.maven.embedder.version</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.2</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                            <testSource>1.8</testSource>
                            <testTarget>1.8</testTarget>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    
    </profile>
    
    0 讨论(0)
  • 2021-01-02 01:34

    Supporting test source/target levels is tracked by this request. Language level changed message is also a known issue.

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