问题与父级pom中有${ced2ar.version}有关吗?即使在文件的较低位置正确定义了${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>
子项目中定义的${ced2ar.version}
属性必须通过先构建定义此属性的父POM的反应堆项目来解析。这就是为什么在开发中(使用反应堆)可以正常构建,但没有反应堆时不能构建的原因。
要解决此问题,您可以使用revision
标准属性和flatten-maven-plugin
,帮助您在父级和子级之间设置唯一版本。
您的反应堆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 后,我没有看到这些字段
这是预期的,因为扁平化插件会剥离原始 POM 中的一些元数据:
扁平化 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>
.flattened-pom.xml
后,我没有看到这些字段,如果这相关的话。当前状态:https://github.com/ncrncornell/ced2ar-rdb/tree/e6ce9c951904d6b1f1aad637a9bce7abe2448778 - bbarker<flattenMode>ossrh</flattenMode>
也可以作为列出单个pomElements
的替代方法。但我发现一个奇怪的问题,即我仍然需要手动添加<name>CED2AR 3</name>
到每个子 POM 中。 - bbarker