Que*_*tin 131 java intellij-idea pom.xml maven
使用IntelliJ 12,我有一个java项目,我使用maven和pom.xml.我的项目使用的是java8,但在导入项目时,似乎默认的项目语言级别已设置为6.
我可以将语言级别更改为8.0(F4 - >模块 - >语言级别)但是每次编辑我的pom.xml时,项目级别都会切换回"使用项目语言级别",我必须再次编辑此设置,再次.
是否需要添加到pom.xml以将默认语言级别设置为8.0?
vik*_*eve 162
根据马克的评论,以下是如何做到这一点:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
Die*_*rDP 91
更短版本的vikingsteve的答案是:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
Pet*_*etz 23
我认为这与Maven编译器插件和IntelliJ想法之间的概念冲突有关.显然,较新版本的编译器插件的默认级别为1.5(请参阅http://maven.apache.org/plugins/maven-compiler-plugin/).因此,如果在项目中根本使用了编译器插件,并且未在pom.xml中显式设置编译器级别,则每当重新处理POM时,级别将恢复为默认值.
因此,Intellij IDEA会忽略概念冲突.IDE仍允许设置项目和模块设置,但不提供此设置由pom.xml控制的警告或反馈.解决方案可能是明确允许覆盖POM编译器插件设置(可能不明智,因为当您在命令行上使用maven时会发生这种情况),或者当POM中的此设置生效时停用IDE中的控件.
目前的解决方案是在pom中的编译器插件中设置所需的编译器级别,重新导入,而不是尝试在模块设置中设置它.
有两种方法可以执行此操作,在pom.xml文件中添加其中一个:
首先添加属性
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
second-添加插件
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如果有帮助,请告诉我.
我正在将项目从JDK 8升级到JDK 10+。我正确指定了编译器属性,如下所示:
<properties>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
</properties>
Run Code Online (Sandbox Code Playgroud)
但是,Idea项目将继续将语言级别重置为8。
最终,我发现Idea的Maven导入过程是使用JDK 8导入项目,从而将语言级别限制为<= 8。
为了解决这个问题,我更新了“设置”->“构建,执行,部署”->“构建工具”->“ Maven”->“导入以使用JDK 11”下的“ JDK for importer”属性。
这些解决方案对我的情况都没有帮助。我不需要在我的 .xe2x80x99 中指定任何 Java 版本pom.xml
。
我需要打开该<project-name>.iml
文件并更改其中的 JDK 版本。
原来的:
\n\n<?xml version="1.0" encoding="UTF-8"?>\n<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">\n <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">\n <!-- ... ^ -->\n <!-- ... | -->\n
Run Code Online (Sandbox Code Playgroud)\n\n更新:
\n\n<?xml version="1.0" encoding="UTF-8"?>\n<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">\n <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">\n <!-- ... ^ -->\n <!-- ... | -->\n
Run Code Online (Sandbox Code Playgroud)\n\n这完全没有意义。我从未指定过 Java 1.5 的 JDK 版本。
\n 归档时间: |
|
查看次数: |
48171 次 |
最近记录: |