JavaMaven读取属性插件不能用值替换依赖项
以下是我的项目结构
test-proj
|_ src
|_main
| |_java
|_test
|_java
|_prop.properties
|_pom.xml
还有我的pom。xml
<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.sample</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<!-- The resources tag will be used if prop file is under src location. -->
<!-- <resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources> -->
<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>${basedir}/prop.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring-version}</version>
</dependency>
</dependencies>
</project>
道具。属性文件具有
spring-version=3.1.0.RELEASE
我曾尝试使用maven read properties插件来读取属性,并将其替换为spring版本。但它抛出了一个错误,即“依赖性”。附属国。组织的“版本”。springframework:SpringBeans:jar必须是有效版本,但为“${SpringVersion}”
我尝试在maven执行阶段使用验证阶段而不是初始化。但问题依然存在。我尝试将属性文件位置替换为绝对路径D:\test proj\prop,而不是上下文路径。配置中的属性对我也没有帮助。我使用的是maven编译器插件版本2.3.2。我错过什么了吗?请让我知道用其他插件替代依赖版本是否可行
注意:我将不能使用父子pom关系,因为我的所有项目都是模块化的,它们不依赖于同一个父项目
# 1 楼答案
如果需要多个不相关的项目共享依赖项版本,可以使用物料清单概念http://howtodoinjava.com/maven/maven-bom-bill-of-materials-dependency/
下面是示例页面的片段
# 2 楼答案
我无法想象这会起作用。AFAIU Maven必须在任何构建执行之前解决依赖关系,否则它应该如何为执行创建正确的类路径
回复:
我认为你有能力。建立一个
super-parent
POM,其中包含所有人都要继承的适当设置,并使所有项目的父项都是以下内容的子项: