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

如何用Maven将制品部署到Nexus自定义路径/文件名,无需长类路径

自定义Nexus部署路径与文件名配置方案

要实现将Jar包部署到Nexus仓库的指定路径REPONAME/servicename/servicename.jar,且不部署pom.xml等其他文件,你需要调整Maven的部署配置,替换原有的nexus-staging-maven-plugin配置为更适合自定义路径的maven-deploy-plugin配置,具体修改如下:

修改后的POM配置段

<build>
    <plugins>
        <!-- 禁用默认的deploy插件执行,避免自动部署pom等文件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>3.1.1</version>
            <executions>
                <execution>
                    <id>default-deploy</id>
                    <phase>none</phase>
                </execution>
            </executions>
        </plugin>
        
        <!-- 自定义部署配置:仅部署指定Jar到目标路径 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>3.1.1</version>
            <executions>
                <execution>
                    <id>custom-deploy</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>deploy-file</goal>
                    </goals>
                    <configuration>
                        <!-- 指定要部署的Jar包路径 -->
                        <file>${project.build.directory}/${project.build.finalName}.jar</file>
                        <!-- Nexus仓库ID,与settings.xml中配置的server.id一致 -->
                        <repositoryId>nexus</repositoryId>
                        <!-- 目标仓库URL,加上自定义路径servicename -->
                        <url>https://nexusurl.com/repository/ESB_TI/REPO1/servicename/</url>
                        <!-- 指定部署后的文件名 -->
                        <destFileName>servicename.jar</destFileName>
                        <!-- 跳过pom文件的部署 -->
                        <skipPom>true</skipPom>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<distributionManagement>
    <!-- 保留原有配置,但实际部署会使用上面自定义的URL -->
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <name>Snapshots</name>
        <url>https://nexusurl.com/repository/ESB_TI/REPO1</url>
    </snapshotRepository>
    <repository>
        <id>nexus</id>
        <name>Versions</name>
        <url>https://nexusurl.com/repository/ESB_TI/REPO1</url>
    </repository>
</distributionManagement>

关键配置说明

  • 先禁用默认的deploy执行,防止Maven自动部署pom.xml和其他附属文件
  • 使用deploy-file目标直接指定要部署的Jar包路径,通过destFileName设置部署后的文件名
  • 在url中添加自定义路径/servicename/,确保Jar包被部署到目标目录下
  • 设置skipPom=true彻底跳过POM文件的部署

执行mvn deploy命令后,Jar包就会被部署到https://nexusurl.com/repository/ESB_TI/REPO1/servicename/servicename.jar路径下,不会生成多余的目录结构或部署其他文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 19:58:27