gpt4 book ai didi

maven-assembly-plugin - Maven Assembly Plugin 在子项目上执行

转载 作者:行者123 更新时间:2023-12-04 08:40:19 25 4
gpt4 key购买 nike

我有以下问题。我有一个多模块项目。我想在顶层 pom 上运行 maven-assembly 插件,它也是其模块的父 pom。我希望插件仅在顶级 pom 上执行。目前它也尝试在所有子模块上执行。我不希望这样,因为我只需要在一个地方(顶级目标目录)从所有模块和子模块中获取所有源。

这是我的描述符:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>src</id>
<formats>
<format>zip</format>
</formats>
<moduleSets>
<moduleSet>
<includeSubModules>true</includeSubModules>
<sources>
<useDefaultExcludes>true</useDefaultExcludes>
<includeModuleDirectory>false</includeModuleDirectory>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>src/main/**</include>
<include>src/test/**</include>
<include>target/classes/**</include>
</includes>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>

pom 文件如下所示:
<?xml version="1.0"?>
<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/maven-v4_0_0.xsd"
>

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>myid</groupId>
<artifactId>myartid</artifactId>
<version>1.1</version>
</parent>
<groupId>myid2</groupId>
<artifactId>TopLevelBuild</artifactId>
<packaging>pom</packaging>
<version>5.5-SNAPSHOT</version>
<name>Some Application</name>
<modules>
<module>1</module>
<module>2</module>
<module>3</module>
<module>4</module>
<module>5</module>
<module>6</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.8.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

父 pom 只包含一些我想在所有模块中继承的依赖项。子模块将当前 pom 作为父模块。
现在,如果我运行:

mvn assembly:single -Ddescriptor=somedes.xml



它在顶层 pom 上运行良好,并收集了我需要的所有资源。但它并没有停止并开始在所有子项目上执行这个目标,当然也没有为它定义描述符。如何仅在顶级 pom 上强制执行?
...
[INFO] Processing sources for module project: LAST MODULE
[INFO] Building zip: ..../target/TopLevelBuild-5.5-SNAPSHOT-src.zip
[INFO] ------------------------------------------------------------------------
[INFO] Building deploy
[INFO] task-segment: [assembly:single]
[INFO] ------------------------------------------------------------------------
[INFO] [assembly:single {execution: default-cli}]
[INFO] Processing sources for module project: module1-submodule1:jar:5.5-SNAPSHOT
[INFO] Processing sources for module project: module1-submodule1:jar:5.5-SNAPSHOT
[INFO] Building zip: .../module1/target/module1-5.5-SNAPSHOT-src.zip
[INFO] ------------------------------------------------------------------------
[INFO] Building module1
[INFO] task-segment: [assembly:single]
[INFO] ------------------------------------------------------------------------
[INFO] [assembly:single {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to create assembly: Error creating assembly archive src: You must set at least one file.

我试图添加:

-Dexecution.inherited=false



但这没有帮助。添加

-Dassembly.ignoreMissingDescriptor=true



也没有帮助。有任何想法吗?

最佳答案

将其放入父 pom.xml 中的 maven-assembly-plugin 的配置中。

<runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot>

关于maven-assembly-plugin - Maven Assembly Plugin 在子项目上执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5885028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com