我正在尝试创建一个pom,它将:
我已经包括了试图实现这一目标的pom.xml。
对此进行测试时,我使用的是mvn clean help:active-profiles,每种测试都显示了以下内容:
JAVA_HOME=/path/to/jdk/1.8
The following profiles are active:
- telstra-ae-sda (source: external)
- jdk-8 (source: com.example:profile-test:1.0.0-SNAPSHOT)JAVA_HOME=/path/to/jdk/14
The following profiles are active:
- telstra-ae-sda (source: external)
- jdk-14 (source: com.example:profile-test:1.0.0-SNAPSHOT)我认为概要文件会从编译的JDK中提取,而不是运行中的JDK。这是人们期望的行为吗?有人知道解决办法吗?
为此,使用了以下pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
<artifactId>profile-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<spring-boot.version>2.3.0.RELEASE</spring-boot.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>14</java.version>
<!--java.version>1.8</java.version-->
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-toolchains-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>${java.version}</version>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jdk-8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>jdk-14</id>
<activation>
<jdk>14</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${java.version}</release>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>发布于 2020-05-19 06:20:07
我想我应该将java.version属性移动到配置文件本身,默认情况下保持jdk-8配置文件是活动的。
无论如何,这种方法更适合工作流,因为测试JDK 14不是正常的模式,最好是通过-P jdk-14手动激活,而不是更新java.varsion属性。
https://stackoverflow.com/questions/61883813
复制相似问题