【发布时间】:2021-05-04 01:09:45
【问题描述】:
A)总结问题
在 pom maven 中有三种定义编译器版本的方法。 我没有提到 maven.compiler 版本、插件和它工作的版本(意味着 maven 构建成功)然后它是如何选择编译器版本的,我没有提到版本
对于我尝试过的事情,请参阅第 b 部分
1)
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<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>
<verbose>true</verbose>
</configuration>
</plugin>
<maven.compiler.release> 8</maven.compiler.release>
B) 我试过的方法
我删除了 maven.compiler 版本和插件,然后它是如何选择编译器版本的
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.flowing.retail</groupId>
<artifactId>flowing-retail-kafka-shipping</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.boot.version>2.2.5.RELEASE</spring.boot.version>
<spring-cloud-stream.version>Horsham.RELEASE</spring-cloud-stream.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-dependencies</artifactId>
<version>${spring-cloud-stream.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-kafka</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- required to add JSR310 time formats for Jackson to ObjectMapper -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>io.flowing.retail.shipping.ShippingApplication</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
-
我定义了无效的 maven.compiler.release。然后它也可以工作
4.0.0 io.flowing.retail 流动零售卡夫卡航运 0.0.1-快照
108 UTF-8 1.8 1.8 <spring.boot.version>2.2.5.RELEASE</spring.boot.version> <spring-cloud-stream.version>Horsham.RELEASE</spring-cloud-stream.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring.boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream-dependencies</artifactId> <version>${spring-cloud-stream.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-stream-kafka</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </exclusion> </exclusions> </dependency> <dependency> <!-- required to add JSR310 time formats for Jackson to ObjectMapper --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-json</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <configuration> <mainClass>io.flowing.retail.shipping.ShippingApplication</mainClass> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
【问题讨论】:
-
如果你使用spring boot,设置
<java.version>,别无其他。 -
编译器参数
-release是在Java 9 中引入的。您能edit 您的问题并解释问题所在吗?您想知道哪个参数会覆盖其他参数吗? -
@dan1st ,在pom maven中定义编译器版本的方法有3种。我没有提到 maven.compiler 版本、插件和它工作的版本(意味着 maven 构建成功)然后它是如何选择编译器版本的,我没有提到版本
-
@PiotrP.Karwasz 你可以参考这个问题的 B 部分吗?我已经做了一些编辑,如果你知道请回答这将是有帮助的
-
只需设置一个属性
java.version,spring boot 就会管理源/目标/发布。