Artifactoty教程

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

二、代理多个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-releaseartifactory.release.url>

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

    properties>

    <repositories>

        <repository>

            <id>releasesid>

            <name>release repositoryname>

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

            <releases>

                <enabled>trueenabled>

            releases>

            <snapshots>

                <enabled>falseenabled>

            snapshots>

        repository>

        <repository>

            <id>snapshotsid>

            <name>snapshot repositoryname>

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

            <releases>

                <enabled>falseenabled>

            releases>

            <snapshots>

                <enabled>trueenabled>

                <updatePolicy>alwaysupdatePolicy>

            snapshots>

        repository>

    repositories>

    

    <pluginRepositories>

        <pluginRepository>

            <id>releasesid>

            <name>release repositoryname>

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

            <releases>

                <enabled>trueenabled>

            releases>

            <snapshots>

                <enabled>falseenabled>

            snapshots>

        pluginRepository>

        <pluginRepository>

            <id>snapshotsid>

            <name>snapshot repositoryname>

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

            <releases>

                <enabled>falseenabled>

            releases>

            <snapshots>

                <enabled>trueenabled>

                <updatePolicy>alwaysupdatePolicy>

            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>adminusername>

          <password>adminpassword>

          <id>releasesid>

        server>

        <server>

          <username>adminusername>

          <password>adminpassword>

          <id>snapshotsid>

        server>

      servers>

      <profiles>

        <profile>

          <repositories>

            <repository>

              <snapshots>

                <enabled>falseenabled>

              snapshots>

              <id>releasesid>

              <name>libs-releasename>

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

            repository>

            <repository>

              <snapshots />

              <id>snapshotsid>

              <name>libs-snapshotname>

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

            repository>

          repositories>

          <pluginRepositories>

            <pluginRepository>

              <snapshots>

                <enabled>falseenabled>

              snapshots>

              <id>releasesid>

              <name>libs-releasename>

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

            pluginRepository>

            <pluginRepository>

              <snapshots />

              <id>snapshotsid>

              <name>libs-snapshotname>

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

            pluginRepository>

          pluginRepositories>

          <id>artifactoryid>

        profile>

      profiles>

      <activeProfiles>

        <activeProfile>artifactoryactiveProfile>

      activeProfiles>

    settings>

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

    ....

    <distributionManagement>

        <repository>

            <id>releasesid>

            <name>releasesname>

            <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教程)