[英]What's the difference between maven-compiler-plugin and scala-maven-plugin?
[英]What's the difference between `spring-boot-maven-plugin` and `maven-compiler-plugin`?
我不知道spring-boot-maven-plugin
和maven-compiler-plugin
之间的区别。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
这是否意味着Spring Boot Maven Plugin
的功能包括maven-compiler-plugin
?
我只是使用Spring Boot Maven Plugin
就可以了,不需要添加 2 个插件吗??
“ Spring Boot Maven 插件在 Maven 中提供 Spring Boot 支持,让您可以打包可执行的 jar 或 war 档案并“就地”运行应用程序。”
“ Maven Compiler Plugin用于编译您项目的源代码。”
maven-compiler-plugin 有两个目标。 两者都已经绑定到 Maven 生命周期中的适当阶段,因此在各自的阶段自动执行。
compiler:compile 绑定到 compile 阶段,用于编译主要的源文件。 compiler:testCompile 绑定到 test-compile 阶段,用于编译测试源文件。
要了解有关 maven 构建生命周期的更多信息 - http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
maven-compiler-plugin 用法 -
最常用于定义源和目标版本。 有时,您可能希望将某个项目编译为与当前使用的版本不同的版本。 javac 可以使用 -source 和 -target 来接受这样的命令。 maven-compiler-plugin 也可以配置为在编译期间提供这些选项。
例如,如果您想使用Java 8 语言特性(-source 1.8)并且还希望编译后的类与JVM 1.8(-target 1.8)兼容,您可以添加以下两个属性,它们是默认属性插件参数的名称:
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>
或者直接配置插件:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
从技术上讲,如果需要创建可执行 jar 并确保源代码和目标代码具有特定版本(通过包含 maven-编译器插件)。
就我而言,我没有组合使用,但是当我的 Java 项目是一个需要作为微服务等运行的 Spring Boot 应用程序时,我们需要一个可执行的 jar 作为构建输出,因此使用了 Spring Boot maven 插件(仅)但是我的另一个 java 项目由 spring bean 或组件组成,将在其他外部应用程序中用作启用 spring 的库,但不需要单独运行,但必须确保指定源和目标版本然后正常的“mvn 包" 生成的 jar 应该可以工作。 对于那个 Maven 编译器插件(仅)应该完成这项工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.