gpt4 book ai didi

java - Maven依赖版本依赖于JVM版本

转载 作者:行者123 更新时间:2023-11-30 07:22:15 29 4
gpt4 key购买 nike

我正在尝试创建一个 Maven POM,它将引入 the correct version of alpn-boot构建项目并运行测试时。

如果我在运行构建时从“外部”注入(inject)属性(例如通过 mvn -Dalpn-boot.version=8.1.8.v20160420 test 或作为环境),整个事情就会起作用变量),但在尝试使用 ${java.version} 将其插入 POM 内时则不然。

我尝试过使用 properties-maven-plugin通过在 pom.xml 文件(片段)中进行以下设置来完成此操作:

<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${project.basedir}/alpn-boot/jdk-${java.version}.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mortbay.jetty.alpn</groupId>
<artifactId>alpn-boot</artifactId>
<version>${alpn-boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

属性文件之一的内容:

$ cat alpn-boot/jdk-1.8.0_92.properties
alpn-boot.version=8.1.8.v20160420

gmaven-plugin基本上有同样的问题:

<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
alpnVersions = [ '1.8.0_92': '8.1.8.v20160420' ]
project.properties['alpn-boot.version'] = alpnVersions[System.getProperty('java.version')]
</source>
</configuration>
</execution>
</executions>
</plugin>

使用这两种方法我都会收到以下错误消息:

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for org.mortbay.jetty.alpn:alpn-boot:jar must be a valid version but is '${alpn-boot.version}'. @ org.example:my-project:[unknown-version], /path/to/pom.xml, line 132, column 22
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project org.example:my-project:1.0.0-rc3-SNAPSHOT (/path/to/pom.xml) has 1 error
[ERROR] 'dependencies.dependency.version' for org.mortbay.jetty.alpn:alpn-boot:jar must be a valid version but is '${alpn-boot.version}'. @ org.example:my-project:[unknown-version], /path/to/pom.xml, line 132, column 22
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException

最佳答案

我最终关注了 the advice of @khmarbaise并添加 Maven profile对于需要支持的每个 JDK 版本:

<properties>
<!-- Default alpn-boot version. See <profiles> for specific profiles. -->
<alpn-boot.version>8.1.3.v20150130</alpn-boot.version>
</properties>

<dependencies>
<dependency>
<groupId>org.mortbay.jetty.alpn</groupId>
<artifactId>alpn-boot</artifactId>
<version>${alpn-boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<!-- Profiles for selecting the correct version of alpn-boot for each JDK.
see http://www.eclipse.org/jetty/documentation/current/alpn-chapter.html for reference. -->
<profiles>
<profile>
<id>jdk-1.8.0</id>
<activation>
<jdk>1.8.0</jdk>
</activation>
<properties>
<alpn-boot.version>8.1.0.v20141016</alpn-boot.version>
</properties>
</profile>
<!-- Lots of profiles [...] -->
<profile>
<id>jdk-1.8.0_92</id>
<activation>
<jdk>1.8.0_92</jdk>
</activation>
<properties>
<alpn-boot.version>8.1.8.v20160420</alpn-boot.version>
</properties>
</profile>
</profiles>

关于java - Maven依赖版本依赖于JVM版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37363352/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com