我是靠谱客的博主 愤怒老虎,最近开发中收集的这篇文章主要介绍Artifactoty教程二、代理多个Maven Repository三、工程发布,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

说明:一、二两个流程互不影响,如果不想使用一,可以直接使用二的构建管理

二、代理多个Maven Repository

如果你还在为配置多个maven repo而烦恼,

如果你还在忍受nexus不友好的交互页面,

那么可以考虑暂时使用artifactory来解决,配置pom.xml如下:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    ....

    <properties>

        <artifactory.release.url>http://{ip}:{port}/artifactory/libs-release</artifactory.release.url>

        <artifactory.snapshot.url>http://{ip}:{port}/artifactory/libs-snapshot</artifactory.snapshot.url>

    </properties>

    <repositories>

        <repository>

            <id>releases</id>

            <name>release repository</name>

            <url>${artifactory.release.url}</url>

            <releases>

                <enabled>true</enabled>

            </releases>

            <snapshots>

                <enabled>false</enabled>

            </snapshots>

        </repository>

        <repository>

            <id>snapshots</id>

            <name>snapshot repository</name>

            <url>${artifactory.snapshot.url}</url>

            <releases>

                <enabled>false</enabled>

            </releases>

            <snapshots>

                <enabled>true</enabled>

                <updatePolicy>always</updatePolicy>

            </snapshots>

        </repository>

    </repositories>

    <!-- 注意加上这个配置,不然你的maven plugin不会被代理,比如compile,resource等插件 -->

    <pluginRepositories>

        <pluginRepository>

            <id>releases</id>

            <name>release repository</name>

            <url>${artifactory.release.url}</url>

            <releases>

                <enabled>true</enabled>

            </releases>

            <snapshots>

                <enabled>false</enabled>

            </snapshots>

        </pluginRepository>

        <pluginRepository>

            <id>snapshots</id>

            <name>snapshot repository</name>

            <url>${artifactory.snapshot.url}</url>

            <releases>

                <enabled>false</enabled>

            </releases>

            <snapshots>

                <enabled>true</enabled>

                <updatePolicy>always</updatePolicy>

            </snapshots>

        </pluginRepository>

    </pluginRepositories>

    ....

</project>

然后执行mvn clean compile即可体验

三、工程发布

3.1 使用mvn deploy

  1. 配置setting.xml,可以从artifactory的home页面获取,点击home页面的任何一个repo,然后点击generate maven settings即可,配置如下:

    <?xml version="1.0" encoding="UTF-8"?>

    <settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <servers>

        <server>

          <username>admin</username>

          <password>admin</password>

          <id>releases</id>

        </server>

        <server>

          <username>admin</username>

          <password>admin</password>

          <id>snapshots</id>

        </server>

      </servers>

      <profiles>

        <profile>

          <repositories>

            <repository>

              <snapshots>

                <enabled>false</enabled>

              </snapshots>

              <id>releases</id>

              <name>libs-release</name>

              <url>http://{ip}:{port}/artifactory/libs-release</url>

            </repository>

            <repository>

              <snapshots />

              <id>snapshots</id>

              <name>libs-snapshot</name>

              <url>http://{ip}:{port}/artifactory/libs-snapshot</url>

            </repository>

          </repositories>

          <pluginRepositories>

            <pluginRepository>

              <snapshots>

                <enabled>false</enabled>

              </snapshots>

              <id>releases</id>

              <name>libs-release</name>

              <url>http://{ip}:{port}/artifactory/libs-release</url>

            </pluginRepository>

            <pluginRepository>

              <snapshots />

              <id>snapshots</id>

              <name>libs-snapshot</name>

              <url>http://{ip}:{port}/artifactory/libs-snapshot</url>

            </pluginRepository>

          </pluginRepositories>

          <id>artifactory</id>

        </profile>

      </profiles>

      <activeProfiles>

        <activeProfile>artifactory</activeProfile>

      </activeProfiles>

    </settings>

  2. 配置工程的pom.xml,添加如下配置:

    ....

    <distributionManagement>

        <repository>

            <id>releases</id>

            <name>releases</name>

            <url>${artifactory.release.url}</url>

        </repository>

    </distributionManagement>

    ....

  3. mvn clean deploy,成功后即可在artifactory中看到发布的artifact。

 

3.2 使用jenkins

新建一个pipeline类型的jenkins,jenkinsfile配置如下:

node("master") {

    def server = Artifactory.newServer url: "http://{ip}:{port}/artifactory", credentialsId: 'jfrog-artifactory'

    def rtMaven = Artifactory.newMavenBuild()

    def buildInfo

    stage ('Clone') {

        git url: '{git-url}', credentialsId: 'gitlab-admin', branch: 'master'

    }

    stage ('Artifactory configuration') {

        rtMaven.tool = 'maven64' // Tool name from Jenkins configuration

        rtMaven.deployer releaseRepo: 'libs-release-local', snapshotRepo: 'libs-snapshot-local', server: server

        rtMaven.resolver releaseRepo: 'libs-release', snapshotRepo: 'libs-snapshot', server: server

        buildInfo = Artifactory.newBuildInfo()

    }

     

    stage ('Maven install') {

        rtMaven.run pom: 'pom.xml', goals: 'clean package -DskipTests', buildInfo: buildInfo

    }

    stage ('Publish build info') {

        server.publishBuildInfo buildInfo

    }

}

配置完成后,点击立即构建即可,成功后可以在artifactory中看到发布的版本。

p.s. 此处在maven中的version配置如果带有snapshot,会自动发布到snapshot的repo中。

最后

以上就是愤怒老虎为你收集整理的Artifactoty教程二、代理多个Maven Repository三、工程发布的全部内容,希望文章能够帮你解决Artifactoty教程二、代理多个Maven Repository三、工程发布所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(64)

评论列表共有 0 条评论

立即
投稿
返回
顶部