这个问题是否与我有
${ced2ar.version} 在父 pom 中,即使
${ced2ar.version} 出现在进一步的正确定义
在文件中?
不,问题来自您声明子模块的方式。
这是 rdb 模块pom 的摘录。
<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">
<parent>
<artifactId>ced2ar3-rdb-parent</artifactId>
<groupId>edu.cornell.ncrn.ced2ar</groupId>
<version>${ced2ar.version}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ced2ar3-rdb</artifactId>
</project>
如果不构建首先构建定义此属性的父 pom 的反应器项目,则无法解析子项目的父版本中定义的 ${ced2ar.version} 属性。这就是为什么您的构建在开发中工作(使用反应器)但没有它就无法工作的原因。
使用flatten-maven-plugin 解决您的问题you could use the revision standard property,这将帮助您在父母和孩子之间设置唯一的版本。
你的反应堆 pom 可能看起来像:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>my-group</groupId>
<artifactId>my-parent</artifactId>
<version>${revision}</version>
...
<properties>
<revision>1.0.0</revision>
</properties>
<modules>
<module>rdb</module>
<module>rdb-tests</module>
..
</modules>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
例如像这样的rdb pom.xml:
<project>
<parent>
<groupId>my-group</groupId>
<artifactId>my-parent</artifactId>
<version>${revision}</version>
</parent>
<artifactId>rdb</artifactId>
...
</project>
关于你的评论:
我收到一个无效的 POM 错误:“缺少项目名称,项目
缺少描述、缺少项目 URL、缺少 SCM URL、开发人员
信息丢失”。确实,在检查了生成的
.flattened-pom.xml,我没有看到这些字段
预计为flattened plugin strips some metadata of the original POM:
扁平化 POM 是原始 POM 的简化版本,带有
专注于仅包含使用它的重要信息。
因此,仅在维护时需要的信息
开发人员和构建项目工件被剥离。开始
从这里我们指定如何从
原POM及其项目
但您可以通过在插件的pomElements 参数中添加您不想去除的元素来覆盖此默认设置。
例如:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<pomElements>
<name/>
<description/>
<developers/>
<contributors/>
<url/>
<scm/>
</pomElements>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>