如何使用Maven 3配置文件在IntelliJ中切换字节码目标级别

Chr*_*ies 6 java intellij-idea maven

我正在使用maven配置文件在Intelli J中的两个"设置"之间切换.如何切换字节码目标级别?那就是:我想在compiler.xml中更改以下设置

<bytecodeTargetLevel>
  <module name="finmath-lib" target="1.6" />
</bytecodeTargetLevel>
Run Code Online (Sandbox Code Playgroud)

注意:我尝试通过相应的Maven 3配置文件中的以下部分执行此操作

<profile>
    <id>java-8</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>
Run Code Online (Sandbox Code Playgroud)

但这不起作用!

注意:pom.xml等属于finmath lib项目,如果您有兴趣,可以在www.finmath.net找到它.

Mad*_*ota 6

我正在使用IntelliJ IDEA 14.1.3,它可以使用以下配置...

<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>
Run Code Online (Sandbox Code Playgroud)

希望这是有帮助的.谢谢!


Rol*_*and 5

问题是你想把它改成1.8。

我尝试使用 Maven 配置文件成功地在 1.7 和 1.6 或 1.5 之间切换 IntelliJ 的编译器版本。

但是,当您想将其更改为 1.8 时,该配置将被忽略。

我不知道这是maven的问题还是Intellj的问题。看来现在JDK 1.8支持不太好,这是可以理解的。


mna*_*dig -1

在 IntelliJ 13 中File > Project Structure,将 设为Project language level8.0。

  • 这并不能解决问题。IntelliJ (13) GUI 显示项目语言级别为 8.0,但 compiler.xml 具有上述模块设置,并且运行单元测试失败。当然:我可以通过手动修复compiler.xml(甚至删除)来解决这个问题——这甚至比进入GUI更快。除此之外:我的问题是如何使用 maven 切换(模块的)语言级别。 (3认同)