Linux JFrog Artifactory 搭建

JFrog Artifactory

Artifactory是一款二进制存储管理工具,用来管理构建构建工具(如:gradle)等所依赖的二进制仓库,以方便管理第三方库和发布目标版本库,从而提高软件开发效率。它提供大量的插件以利于和不同工具之间的整合,内部使用权限管理更加安全,并支持高并发等等特性。另外我们搭建Artifactory私服的原因还有:

私有仓库的目的是作为团队内所使用的所有软件构件的内部私有构件仓库,将Maven构件(jar和pom)存储到一个专门的Maven仓库比将它们存储到版本控制系统中更有优势,这是因为:

·构件(jar)是二进制文件,不属于git版本控制系统,后者在处理文本文件方面比较好

·减少可能的版本冲突

·减少首次构建时需要的手动干涉

·中央仓库包含所有依赖的软件构件,引用单一的中央仓库比引用多个独立的本地库要好

·使用内部仓库做clean构建时会快些,因为Maven构件是从内部服务器而不是从因特网上获取。

JFrog Artifactory开源版:

http://www.jfrogchina.com/open-source/

Ubuntu环境搭建

1.下载开源版.rpm

https://jfrog.com/open-source/

2.安装

用alien转换Redhat Linux包.rmp为Ubuntu包.deb

$sudo apt-get install alien ##alien默认没有安装,所以首先要安装它

$sudo alien xxxx.rpm ##将rpm转换为deb,完成后会生成一个xxxx.deb

$sudo dpkg -i xxxx.deb ##这样xxxx软件就可以安装完成了

安装.deb

Sudo dpkg –i xxx.deb

3.运行

默认安装路径为/opt/jfrog/,Artifactory自带了Tomcat服务器。

可以先启动Tomcat(/opt/jfrog/artifactory/tomcat/bin/startup.sh),再启动artifactory(/opt/jfrog/artifactory/bin/artifactoryctlstart)。

或直接一起启动(/opt/jfrog/artifactory/bin/artifactory.shstart)

启动服务:sudo /opt/jfrog/artifactory/bin/artifactory.sh

因为是新新装系统,系统里面没有 jdk,因此需要安装 java 环境,可以按照之前文档

https://shareintelli.com/2018/08/16/how-to-install-openjdk-java-8-in-ubuntu/

系统中原先有 1.8 的 openjdk,卸载 1.8 之后安装 1.9 需要强制安装

sudo apt-get -o Dpkg::Options::=”–force-overwrite” install openjdk-9-jdk

https://cloud.tencent.com/developer/news/44535

开放对应端口:https://www.cnblogs.com/zqunor/p/6417938.html

4.配置

默认在8081端口开启服务。初始用户为admin:password。第一次使用时会触发配置向导,要求修改密码创建仓库。Artifactory的仓库类型有:

·本地私有仓库:用于内部使用,上传的组件不会向外部进行同步。

·远程仓库:用于代理及缓存公共仓库,不能向此类型的仓库上传私有组件。

·虚拟仓库:不是真实在存储上的仓库,它用于组织本地仓库和远程仓库。

5.Gradle上传、引用文件

5.1 Gradle 上传


buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.9.0'
        classpath 'com.github.megatronking.stringfog:gradle-plugin:1.4.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url artifactory_url + 'libs-release-local'// The Artifactory (preferably virtual) repository to resolve from
            credentials {               // Optional resolver credentials (leave out to use anonymous resolution)
                username = artifactory_user // Artifactory user name
                password = artifactory_password // Password or API Key
            }
        }
    }
}

apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

task androidJavadocs(type: Javadoc) {
    failOnError false
    source = android.sourceSets.main.java.sourceFiles
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
    classifier = 'javadoc'
    baseName = rootProject.ext.encryptId
    from androidJavadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
    baseName = rootProject.ext.encryptId
}

publishing {
    publications {
        aar(MavenPublication) {
            groupId rootProject.ext.libGroupId
            version rootProject.ext.libVersion
            artifactId rootProject.ext.encryptId
            artifact("$buildDir/outputs/aar/${archivesBaseName}-v${versionName}.aar")
            artifact androidSourcesJar
            artifact androidJavadocsJar

            pom.withXml {
                List needAddDependencyNameList = ['lib']
                def dependenciesNode = asNode().appendNode('dependencies')
                configurations.implementation.allDependencies.each {
                    for (String name : needAddDependencyNameList) {
                        if (name == it.name) {
                            def dependencyNode = dependenciesNode.appendNode('dependency')
                            dependencyNode.appendNode('groupId', it.group)
                            dependencyNode.appendNode('artifactId', it.name)
                            dependencyNode.appendNode('version', it.version)
                        }
                    }

                }
            }
        }
    }
}

artifactory {
    contextUrl = artifactory_url
    //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        //A closure defining publishing information
        repository {
            repoKey = 'libs-release'   //The Artifactory repository key to publish to
            username = artifactory_user          //The publisher user name
            password = artifactory_password      //The publisher password or API key
        }
        defaults {
            //List of Gradle Publications (names or objects) from which to collect the list of artifacts to be deployed to Artifactory.
            publications('aar')
            properties = ['qa.level': 'basic', 'q.os': 'android', 'dev.team': 'core']
            //Optional map of properties to attach to all published artifacts
            publishArtifacts = true   //Publish artifacts to Artifactory (true by default)
            publishPom = true   //Publish generated POM files to Artifactory (true by default).
//            publishIvy = true
            //Publish generated Ivy descriptor files to Artifactory (true by default).
        }

        artifactoryPublish.dependsOn  androidJavadocsJar
        artifactoryPublish.dependsOn  androidSourcesJar
    }
}

5.2 Gradle引用文件

与之前环境一样,不过少了上传的操作

https://cloud.tencent.com/developer/news/44535

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注