【问题标题】:maven multi-module artifact deploymentmaven 多模块工件部署
【发布时间】:2015-05-11 15:53:03
【问题描述】:

我有一个多模块 maven 项目,其中父级构建所有模块,子级 pom 聚合器处理配置文件部署。

我可以通过父模块的mvn clean deploy 部署捆绑包;但是,这无法附加子模块的 build-helper 插件部分中指定的配置文件。

这需要我为每个具有配置工件的子 pom 运行 mvn -f <child-module> clean deploy。对于特征等工件也是如此。

这是我的 POM 文件的示例:

家长

<project>
    <groupId>com.sample</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>

    <modules>
        <module>child</module>
    </modules>
</project>

儿童

<project>
    <parent>
        <groupId>com.sample</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>child</artifactId>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-config-file</id>
                        <phase>install</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>
                            <artifacts>
                                <artifact>
                                    <file>properties.cfg</file>
                                    <type>cfg</type>
                                    <classifier>properties</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我想要在每个子模块上执行attach-artifact 目标,而无需编写自定义批处理脚本来单独执行这些。我正在部署到档案存储库。

编辑

父构建输出(目标服务器已编辑):

C:\Temp>mvn clean deploy -DskipTests
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parent
[INFO] child
[INFO] features
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parent 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ parent ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ parent ---
[INFO] Installing C:\Temp\pom.xml to C:\Users\u14053\.m2\repository\com\sample\parent\1.0-SNAPSHOT\parent-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ parent ---
Downloading: http://<server>/archiva/repository/snapshots/com/sample/parent/1.0-SNAPSHOT/maven-metadata.xml
Downloaded: http://<server>/archiva/repository/snapshots/com/sample/parent/1.0-SNAPSHOT/maven-metadata.xml (589 B at 7.4 KB/sec)

Uploading: http://<server>/archiva/repository/snapshots/com/sample/parent/1.0-SNAPSHOT/parent-1.0-20150511.162118-2.pom
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/parent/1.0-SNAPSHOT/parent-1.0-20150511.162118-2.pom (4 KB at
31.6 KB/sec)
Downloading: http://<server>/archiva/repository/snapshots/com/sample/parent/maven-metadata.xml
Downloaded: http://<server>/archiva/repository/snapshots/com/sample/parent/maven-metadata.xml (274 B at 5.4 KB/sec)
Uploading: http://<server>/archiva/repository/snapshots/com/sample/parent/1.0-SNAPSHOT/maven-metadata.xml
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/parent/1.0-SNAPSHOT/maven-metadata.xml (589 B at 2.6 KB/sec)
Uploading: http://<server>/archiva/repository/snapshots/com/sample/parent/maven-metadata.xml
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/parent/maven-metadata.xml (274 B at 2.5 KB/sec)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building child 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ child ---
[INFO] Deleting C:\Temp\child\target
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (filter) @ child ---
[INFO] Using '1.6' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ child ---
[INFO] Using '1.6' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ child ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ child ---
[INFO] Using '1.6' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Temp\child\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ child ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ child ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child ---
[INFO] Building jar: C:\Temp\child\target\child-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ child ---
[INFO] Installing C:\Temp\child\target\child-1.0-SNAPSHOT.jar to C:\Users\u14053\.m2\repository\com\sample\child\1.0-SNAPSHOT\child-1.0-SNAP
SHOT.jar
[INFO] Installing C:\Temp\child\pom.xml to C:\Users\u14053\.m2\repository\com\sample\child\1.0-SNAPSHOT\child-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:attach-artifact (attach-config-file) @ child ---
[INFO] Skip attaching artifacts in this project because it's not the Execution Root
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ child ---
Downloading: http://<server>/archiva/repository/snapshots/com/sample/child/1.0-SNAPSHOT/maven-metadata.xml
Downloaded: http://<server>/archiva/repository/snapshots/com/sample/child/1.0-SNAPSHOT/maven-metadata.xml (759 B at 30.9 KB/sec)

Uploading: http://<server>/archiva/repository/snapshots/com/sample/child/1.0-SNAPSHOT/child-1.0-20150511.162120-2.jar
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/child/1.0-SNAPSHOT/child-1.0-20150511.162120-2.jar (2 KB at 21
.1 KB/sec)
Uploading: http://<server>/archiva/repository/snapshots/com/sample/child/1.0-SNAPSHOT/child-1.0-20150511.162120-2.pom
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/child/1.0-SNAPSHOT/child-1.0-20150511.162120-2.pom (2 KB at 6.
1 KB/sec)
Downloading: http://<server>/archiva/repository/snapshots/com/sample/child/maven-metadata.xml
Downloaded: http://<server>/archiva/repository/snapshots/com/sample/child/maven-metadata.xml (273 B at 9.2 KB/sec)
Uploading: http://<server>/archiva/repository/snapshots/com/sample/child/1.0-SNAPSHOT/maven-metadata.xml
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/child/1.0-SNAPSHOT/maven-metadata.xml (759 B at 33.7 KB/sec)
Uploading: http://<server>/archiva/repository/snapshots/com/sample/child/maven-metadata.xml
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/child/maven-metadata.xml (273 B at 10.7 KB/sec)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building features 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ features ---
[INFO] Deleting C:\Temp\features\target
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (filter) @ features ---
[INFO] Using '1.6' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ features ---
[INFO] Using '1.6' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ features ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ features ---
[INFO] Using '1.6' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Temp\features\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ features ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ features ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ features ---
[INFO] Building jar: C:\Temp\features\target\features-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ features ---
[INFO] Installing C:\Temp\features\target\features-1.0-SNAPSHOT.jar to C:\Users\u14053\.m2\repository\com\sample\features\1.0-SNAPSHOT\featu
res-1.0-SNAPSHOT.jar
[INFO] Installing C:\Temp\features\pom.xml to C:\Users\u14053\.m2\repository\com\sample\features\1.0-SNAPSHOT\features-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ features ---
Downloading: http://<server>/archiva/repository/snapshots/com/sample/features/1.0-SNAPSHOT/maven-metadata.xml
Downloaded: http://<server>/archiva/repository/snapshots/com/sample/features/1.0-SNAPSHOT/maven-metadata.xml (762 B at 27.6 KB/s
ec)
Uploading: http://<server>/archiva/repository/snapshots/com/sample/features/1.0-SNAPSHOT/features-1.0-20150511.162120-2.jar
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/features/1.0-SNAPSHOT/features-1.0-20150511.162120-2.jar (2 KB
 at 24.0 KB/sec)
Uploading: http://<server>/archiva/repository/snapshots/com/sample/features/1.0-SNAPSHOT/features-1.0-20150511.162120-2.pom
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/features/1.0-SNAPSHOT/features-1.0-20150511.162120-2.pom (2 KB
 at 7.9 KB/sec)
Downloading: http://<server>/archiva/repository/snapshots/com/sample/features/maven-metadata.xml
Downloaded: http://<server>/archiva/repository/snapshots/com/sample/features/maven-metadata.xml (276 B at 5.1 KB/sec)
Uploading: http://<server>/archiva/repository/snapshots/com/sample/features/1.0-SNAPSHOT/maven-metadata.xml
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/features/1.0-SNAPSHOT/maven-metadata.xml (762 B at 7.4 KB/sec)

Uploading: http://<server>/archiva/repository/snapshots/com/sample/features/maven-metadata.xml
Uploaded: http://<server>/archiva/repository/snapshots/com/sample/features/maven-metadata.xml (276 B at 12.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent ............................................. SUCCESS [  1.011 s]
[INFO] child .............................................. SUCCESS [  1.183 s]
[INFO] features ........................................... SUCCESS [  0.563 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.853 s
[INFO] Finished at: 2015-05-11T12:21:21-04:00
[INFO] Final Memory: 11M/244M
[INFO] ------------------------------------------------------------------------

【问题讨论】:

  • 是否有任何错误信息之类的?你的 Maven 输出是什么?
  • @AdamArold 构建成功; cfgs 位于目标目录中,但如果没有从子模块进行额外部署,则不会复制到存档。
  • 你能发布构建的输出吗?不是“构建成功”,而是整个日志。

标签: java maven deployment configuration


【解决方案1】:

删除或更改为 false runOnlyAtExecutionRoot 属性。

如果设置为true,则:“这将导致执行仅在给定模块树的顶部运行。也就是说,在启动 mvn 执行的同一文件夹中包含的项目中运行。”

可能是找不到 cfgs 文件。

【讨论】:

  • 不幸的是,在真正的交易场景中,子模块是一个 pom,它位于其他没有 cfg 文件的子模块之上。删除 runOnlyAtExecutionRoot 会导致构建失败,因为下面没有要附加的内容。
  • 在您发送的日志中,它正在跳过工件,因为它不是“root”:[INFO] [INFO] --- build-helper-maven-plugin:1.8:attach-artifact (attach-config-file) @ child --- [INFO] Skip attaching artifacts in this project because it's not the Execution Root [INFO] 我建议您在没有 cfg 的子模块中使用属性:skipAttach要上传的工件,并删除 runOnlyAtExecutionRoot
  • 谢谢,我会在删除runOnlyAtExecutionRoot 时尝试将skipAttach 添加到子模块中。
猜你喜欢
  • 2015-01-30
  • 2023-03-11
  • 1970-01-01
  • 2017-02-02
  • 1970-01-01
  • 1970-01-01
  • 2011-12-26
  • 2021-09-04
  • 2012-03-19
相关资源
最近更新 更多