好好爱自己!

maven 的编译插件的配置

原文: https://stackoverflow.com/questions/29258141/maven-compilation-error-use-source-7-or-higher-to-enable-diamond-operator/31734791#31734791

--------------------------------------------------------------------------------------------------------

WHY IT HAPPENS

The problem arises because

[...] at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler.

Maven Compiler Plugin Introduction

That's why changing the JDK has no effect on the source level. So you have a couple of way to tell Maven what source level to use.

SOLUTIONS

  • Configure the Maven compiler plugin in the pom.xml
<build>

<plugins>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>
</plugins>
...
  • OR Set these properties (always in the pom)
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

JDK VERSION TO USE?

If you set a target 1.7 like in this example be sure that the mvn command is actually launched with a jdk7 (or higher)

LANGUAGE LEVEL ON THE IDE

Usually IDEs use maven pom.xml file as a source of project configuration. Changing the compiler settings in the IDE not always has effect on the maven build. That's why, the best way to keep a project always manageable with maven (and interoperable with other IDEs) is edit the pom.xml files and instruct the IDE to sync with maven.

posted @   立志做一个好的程序员  阅读(562)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
历史上的今天:
2017-02-27 linux 状态与系统调优

不断学习创作,与自己快乐相处

点击右上角即可分享
微信分享提示