Artifactory搭建maven私服

1概述

在我们的项目开发中通常希望将很多公用的东西提成一个工具工程,然后这个工程可以以maven依赖的形式让其他项目进行添加。这就是以使用Artifactory来建立maven私服。

2具体步骤

(1)下载Artifactory。下载地址:Artifactory

(2)直接解压下载好的zip文件,并且点击...\artifactory-3.9.2\bin目录下的artifactory.bat进行安装,当出现

###########################################################
### Artifactory successfully started (20.911 seconds)   ###
###########################################################

则表示安装完成。

(3)打开http://localhost:8081/artifactory/webapp/home.html链接,查看是否安装成功。

(4)登录Artifactory,用户名和密码为admin/password。登录成功后,我们可以看见如下信息


上面的distributionManagement就是我们在自己的util工程中的pom文件中需要加入的。

(5)在我们对应的util工程的maven配置文件中添加如下内容:

 <repositories>
        <repository>
            <id>artifactory</id>
            <name>your local artifactory</name>
            <url>http://localhost:8081/artifactory/libs-release-local</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>artifactory</id>
            <name>your local artifactory</name>
            <url>http://localhost:8081/artifactory/plugins-release-local</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    <distributionManagement>
        <repository>
            <id>artifactory</id>
            <url>http://localhost:8081/artifactory/libs-release-local</url>
        </repository>
    </distributionManagement>

当然,上面的内容并不是都需要的,如果util工程仅仅用于工具编写,不依赖其他工程,我们可以仅仅添加distributionManagement就行。但要注意这里的id必须和setting.xml中的server中的id一致。现在我们就可以直接点击deploy向maven私服发包了。发布成功后我们直接打开distributionManagement的url就可以看见相关信息。

3如何依赖maven私服

直接在我们需要引入maven私服中的jar包的工程中的pom文件中添加如下配置即可

<repositories>
        <repository>
            <id>artifactory</id>
            <name>your local artifactory</name>
            <url>http://localhost:8081/artifactory/libs-release-local</url>
        </repository>
    </repositories>

注意在上面deploy之前我们一定要给我们的maven授权,因此需要在我们的settings.xml文件中的services节点中加入以下节点

<server>
      <id>artifactory</id>
      <username>admin</username>
      <password>password</password>
    </server>
。如有疑问欢迎留言

猜你喜欢

转载自blog.csdn.net/onroad0612/article/details/80509646
今日推荐