如何在多模块maven项目中单独构建一个模块?
How to build a module separately in multimodular maven project?
已创建以下 maven-ci-friendly article in official Maven documentation, this multimodule project (minimal example)。
共有三个模块和一个根项目(inception):
/inception
/modules
/base (common parent of 'core' and 'facade')
/core (child of 'base')
/facade (child of 'base' having 'core' as a dependency)
从 inception
执行 mvn package
按预期工作 - 所有 3 *.jar
工件都在相应的 target
forlders 中创建。
我想要 单独构建 facade
模块的选项。
不幸的是,来自 modules/facade
的 mvn package
无法收集依赖项并因错误
而失败
[ERROR] Failed to execute goal on project sample-facade:
Could not resolve dependencies for project sample.group:sample-facade:jar:0.0.1:
Failed to collect dependencies at sample.group:sample-core:jar:0.0.1:
Failed to read artifact descriptor for sample.group:sample-core:jar:0.0.1:
Could not transfer artifact sample.group:sample-base:pom:${revision}
表面问题是 ${revision}
没有被解析为 0.0.1
。
你能帮我解决这个问题吗?
flatten-maven-plugin
解决了问题。
感谢@khmarbaise,他在阅读 the docs 到最后的评论中提出了建议。
将插件添加到 /modules/base/pom.xml
解决了单独构建子模块的问题:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.5</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</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>
在 facade
模块上开始一个阶段之前,本地存储库中需要有 base
和 core
,这样 Maven 才能找到工件。因此,这是 root 中的操作序列:
mvn install -pl modules/base,modules/core
(或只是mvn install
)
mvn package -pl modules/facade
已创建以下 maven-ci-friendly article in official Maven documentation, this multimodule project (minimal example)。
共有三个模块和一个根项目(inception):
/inception
/modules
/base (common parent of 'core' and 'facade')
/core (child of 'base')
/facade (child of 'base' having 'core' as a dependency)
从 inception
执行 mvn package
按预期工作 - 所有 3 *.jar
工件都在相应的 target
forlders 中创建。
我想要 单独构建 facade
模块的选项。
不幸的是,来自 modules/facade
的 mvn package
无法收集依赖项并因错误
[ERROR] Failed to execute goal on project sample-facade:
Could not resolve dependencies for project sample.group:sample-facade:jar:0.0.1:
Failed to collect dependencies at sample.group:sample-core:jar:0.0.1:
Failed to read artifact descriptor for sample.group:sample-core:jar:0.0.1:
Could not transfer artifact sample.group:sample-base:pom:${revision}
表面问题是 ${revision}
没有被解析为 0.0.1
。
你能帮我解决这个问题吗?
flatten-maven-plugin
解决了问题。
感谢@khmarbaise,他在阅读 the docs 到最后的评论中提出了建议。
将插件添加到 /modules/base/pom.xml
解决了单独构建子模块的问题:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.5</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</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>
在 facade
模块上开始一个阶段之前,本地存储库中需要有 base
和 core
,这样 Maven 才能找到工件。因此,这是 root 中的操作序列:
mvn install -pl modules/base,modules/core
(或只是mvn install
)mvn package -pl modules/facade