英文:
Does IntelliJ not utilize Maven's <release> for target byte code level?
问题
我刚刚发现,当仅配置maven-compiler-plugin的<release>
时,IntelliJ的行为非常奇怪:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>14</release>
</configuration>
</plugin>
结果在重新加载Maven项目后,在“Java编译器”首选项中,它显示目标字节码级别为8
,而不是预期的14
。我猜测这是因为模块没有使用任何Java 14特性而被推断出来的。
请参见首选项截图:https://i.stack.imgur.com/gqpKV.jpg
相比之下,当添加<source>
和<target>
时,IDE会正确配置自己的配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>14</source>
<target>14</target>
</configuration>
</plugin>
请参见首选项截图:https://i.stack.imgur.com/gqpKV.jpg
就我理解,javac的--release
选项略微更可靠,因为它还将-bootclasspath
选项设置为正确的级别(与this SO post中的内容进行了双重检查)。因此,我认为仅依赖这个选项是更好的做法。
是否还需要执行其他配置步骤,以便让IntelliJ正确设置首选项,而不声明较旧的参数?
英文:
I just found out, that IntelliJ behaves very peculiarly when configuring the maven-compiler-plugin with <release>
only:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-xml -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>14</release>
</configuration>
</plugin>
<!-- end snippet -->
As a result after reloading the Maven project, in the 'Java Compiler' preferences, it displays target bytecode level 8
instead of the expected 14
. I guess it was inferred because the modules didn't use any Java 14 features, yet.
see preferences screenshot: https://i.stack.imgur.com/gqpKV.jpg
In comparison, when adding <source>
and <target>
the IDE configures its own configuration, correctly.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-xml -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>14</source>
<target>14</target>
</configuration>
</plugin>
<!-- end snippet -->
see preferences screenshot: https://i.stack.imgur.com/gqpKV.jpg
As far as I understand it, the javac --release
option is slightly more reliable than just defining -source
and -target
because it additionally sets the -bootclasspath
option to the correct level (double-checked with this SO post). So it seems to me that relying on this option exclusively is a better practice.
Is there another configuration step that I would have to execute in order to make IntelliJ set up the preferences, correctly, without declaring the older parameters?
答案1
得分: 1
我对这个问题进行了更详细的调查,并发现在某个父pom中,maven-compiler-plugin被添加到了<pluginManagement>
中,但是却从未为配置设置过一个maven属性。
尽管我在子pom中覆盖了插件的配置,但这似乎导致IntelliJ仍按语言级别推断。
我想这是可以接受的行为,因为如果父pom有问题,IntelliJ不应过于努力地自行解决问题,以免造成更多混淆。
英文:
I investigated that issue a little closer and found out that somewhere in one of the parent poms the maven-compiler-plugin was added to the <pluginManagement>
with a maven-property that got never set for the configuration.
This seemed to have caused IntelliJ to infer by language level even though I overwrote the plugin configuration in the child-pom.
I guess that's acceptable behaviour because if the parent pom is faulty, IntelliJ shouldn't try too hard to figure out stuff on its own to just cause more confusion.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论