You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用nexus-staging-maven-plugin时,如何跳过Maven多模块的Module B上传至Maven Central?

解决Maven多模块项目跳过指定模块上传至Central的问题

针对你遇到的Parent+Module A上传、Module B跳过的需求,以下是几种可行的解决方法:

方法一:在父模块的nexus-staging-maven-plugin中排除Module B

直接在父模块的插件配置里指定要排除的模块,让staging插件完全忽略Module B的构件处理,这是最彻底的配置层面解决方式:

<plugin>
    <groupId>org.sonatype.plugins</groupId>
    <artifactId>nexus-staging-maven-plugin</artifactId>
    <version>你的插件版本</version>
    <configuration>
        <!-- 保留你原有的其他配置,比如serverId、url等 -->
        <modulesToExclude>你的Module B坐标:如com.example:module-b</modulesToExclude>
    </configuration>
</plugin>

注意modulesToExclude的格式是groupId:artifactId,必须和Module B的pom中定义的坐标完全一致。

方法二:在Module B的pom中彻底禁用上传相关插件

确保Module B的pom中同时覆盖继承自父模块的插件配置,明确跳过deploy和staging操作:

<properties>
    <!-- 全局属性跳过deploy -->
    <maven.deploy.skip>true</maven.deploy.skip>
    <!-- 跳过staging插件 -->
    <nexus.staging.skip>true</nexus.staging.skip>
</properties>

<build>
    <plugins>
        <!-- 显式禁用deploy插件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>
        <!-- 显式禁用staging插件 -->
        <plugin>
            <groupId>org.sonatype.plugins</groupId>
            <artifactId>nexus-staging-maven-plugin</artifactId>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>
    </plugins>
</build>

这种方式需要确保父模块的插件配置没有强制覆盖子模块的skip设置,子模块的配置会默认覆盖继承的内容。

方法三:通过命令行参数指定仅处理目标模块

如果不想修改pom配置,可以在执行deploy命令时,用-pl参数指定要处理的模块,-am参数确保依赖的父模块也被处理:

mvn clean deploy -pl :parent,:module-a -am

这里的:前缀表示当前项目中的模块,这种方式会让Maven完全跳过Module B的构建和上传流程,适合临时或者灵活的场景。

为什么之前的配置未生效?

nexus-staging-maven-plugin默认会扫描整个多模块项目的所有模块并收集构件,即使子模块设置了skip,父模块的staging配置可能依然会将Module B纳入处理范围(尤其是开启自动发布时)。因此需要从父模块层面排除,或者通过命令行精准控制处理范围。

内容的提问来源于stack exchange,提问作者Maithilish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 18:13:21