maven - Maven编译器使用的JDK版本在哪里指定?

标签 maven maven-3 java

当我没有在我的 pom.xml 文件中定义如下内容时,在我的系统上的哪个位置为 Maven 定义了在编译时使用哪个版本的 Java JDK(我的系统上安装了几个版本,JAVA_HOME 指向其中之一)?

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>
    </plugins>
</build>

最佳答案

Maven 文档说

The Compiler Plugin is used to compile the sources of your project. The default compiler is javac and is used to compile Java sources. Also note that 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.

引用:http://maven.apache.org/plugins/maven-compiler-plugin/index.html

Maven 的 Jira 上有这个有趣的线程 Change default source level to 1.5


编辑:
Maven 3.0 及更高版本的更新:

The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.

来源:http://maven.apache.org/plugins/maven-compiler-plugin/index.html

谢谢 nachteil感谢指出。

关于maven - Maven编译器使用的JDK版本在哪里指定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9603591/

相关文章:

android - gradle如何两次解析具有不同版本的同一个lib,并在运行时使用两者?

java - Maven 无法执行 objective-c om.jayway.maven.plugins.android. Generation2

maven - 如何强制手动执行 Maven 插件?

Maven react 器按不满足所有依赖项的顺序构建

java - 我的 GUI 每次启动时都会弹出两个窗口

java - 为什么 RuntimeException 不能从 Throwable 分配?

java - 多个Spring Boot错误: package org. springframework.boot不存在

java - 使用 maven 构建时如何在 osgi 包中导入 javax.smartcardio?

maven - 依赖收敛错误

java - 为什么没有 OptionalDouble orElseNull() 或更好的解决方案