maven multi-module 工件部署

maven multi-module artifact deployment

我有一个 multi-module Maven 项目,其中 parent 构建所有模块,child pom 聚合器处理配置文件部署。

我可以通过 mvn clean deploy 从 parent 模块部署捆绑包;但是,这无法附加 child 模块的 build-helper 插件部分中指定的 config-files。

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

这是我的 POM 文件的示例:

Parent

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

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

Child

<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>

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

编辑

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

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.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.0-SNAPSHOT\child-1.0-SNAP
SHOT.jar
[INFO] Installing C:\Temp\child\pom.xml to C:\Users\u14053\.m2\repository\com\sample\child.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.0-SNAPSHOT\featu
res-1.0-SNAPSHOT.jar
[INFO] Installing C:\Temp\features\pom.xml to C:\Users\u14053\.m2\repository\com\sample\features.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] ------------------------------------------------------------------------

删除或更改为 false runOnlyAtExecutionRoot 属性。

如果设置为true则:"This will cause the execution to be run only at the top of a given module tree. That is, run in the project contained in the same folder where the mvn execution was launched."

可能找不到 cfgs 文件。