Maven如何发布jar包到Nexus私库

时间:2021-11-14 22:20:48

1.修改maven主目录.setting.xml配置文件

nexus认证的用户名和密码配置信息

<servers>
    <server>
          <id>nexus-releases</id>
          <privateKey>admin</privateKey>
          <passphrase>admin123</passphrase>
    </server>
    <server>
          <id>nexus-snapshots</id>
          <privateKey>admin</privateKey>
          <passphrase>admin123</passphrase>
    </server>
</servers>

添加mirror镜像

<mirrors>
    <mirror>
          <id>Nexus</id>
          <mirrorOf>*</mirrorOf>
          <name>Nexus</name>
          <url>http://127.0.0.1:8081/repository/maven-public/</url>
     </mirror>
  </mirrors>

添加私库

<profiles>
    <profile>
        <id>Nexus</id>
        <repositories>
            <repository>
                <id>Nexus</id>
                <name>Nexus</name>
                <url>http://127.0.0.1:8081/repository/maven-public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>Nexus</id>
                <name>Nexus</name>
                <url>http://127.0.0.1:8081/repository/maven-public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>

激活私库

<activeProfiles>
        <activeProfile>Nexus</activeProfile>
</activeProfiles>

2.在pom配置文件中添加

<!-- nexus-releases nexus-snapshots与settings.xml中server下的id对应 -->
<distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <name>Nexus Releases Repository</name>
        <url>http://localhost:8081/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <name>Nexus Snapshots Repository</name>
        <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

3.发布到私库

在项目上使用命令mvn deploy打包就能发布到私库

参考博文链接:https://blog.csdn.net/Mrs_chens/article/details/90113121