利用Maven将项目打包上传到nexus私服共享

1、pom.xml文件添加distributionManagement节点

<!-- 使用分发管理将本项目打成jar包,直接上传到指定服务器(私服) -->
<distributionManagement>
    <!--正式版本-->
    <repository>
        <!-- setting.xml中配置私服用户名和密码 -->
        <id>releases</id>
        <name>Release Repository</name>
        <url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>
    </repository>
    <!--快照版本-->
    <snapshotRepository>
        <!-- setting.xml中配置私服用户名和密码 -->
        <id>snapshots</id>
        <name>Snapshots Repository</name>
        <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

2、setting.xml文件节点配置

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository>D:\repo</localRepository>
    <servers>
        <server>
            <!-- 需要与pom.xml中的distributionManagement>repository>id一致 -->
            <id>releases</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
        <server>
            <!-- 需要与pom.xml中的distributionManagement>repository>id一致 -->
            <id>snapshots</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
    <mirrors>
        <!-- 私库配置 -->
        <mirror>
            <id>public</id>
            <mirrorOf>*</mirrorOf>
            <name>私库 公共仓库</name>
            <url>http://127.0.0.1:8081/nexus/content/groups/public</url>
        </mirror>
        <!-- https://developer.aliyun.com/mvn/guide -->
        <mirror>
            <id>aliyunmaven</id>
            <mirrorOf>*</mirrorOf>
            <name>阿里云 公共仓库</name>
            <url>https://maven.aliyun.com/repository/public</url>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>dev</id>
            <repositories>
                <repository>
                    <id>public</id>
                    <name>私库 代理仓</name>
                    <url>http://127.0.0.1:8081/nexus/content/groups/public</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>spring</id>
                    <name>spring 代理仓</name>
                    <url>https://maven.aliyun.com/repository/spring</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>spring-plugin</id>
                    <name>spring-plugin 代理仓</name>
                    <url>https://maven.aliyun.com/repository/spring-plugin</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>public</id>
                    <name>私库 代理仓</name>
                    <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
                </pluginRepository>
                <pluginRepository>
                    <id>spring</id>
                    <name>spring 代理仓</name>
                    <url>https://maven.aliyun.com/repository/spring</url>
                </pluginRepository>
                <pluginRepository>
                    <id>spring-plugin</id>
                    <name>spring-plugin 代理仓</name>
                    <url>https://maven.aliyun.com/repository/spring-plugin</url>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>dev</activeProfile>
    </activeProfiles>
</settings>

3、执行deploy上传至远程仓库

4、查看远程仓库是否存在

posted @ 2022-03-14 11:59  聚散彡流沙  阅读(482)  评论(0编辑  收藏  举报