当前位置:网站首页>使用JFrog Artifactory上传aar包并在项目中使用

使用JFrog Artifactory上传aar包并在项目中使用

2021-03-05 11:28:41 哆啦大梦幻

1. 下载

JFrog开源版本

2. 安装和创建仓库

1). 解压后运行:YOUR PATH/artifactory-oss-6.23.13/bin/artifactory.bat

2). 在浏览器输入localhost:8081,默认用户名(admin)和密码(password)

3). 创建自己的本地仓库,选择maven,并输入Repository Key(例:my_local_repo)

4). 创建远程代理仓库,可以将Android Studio gradle默认的jcenter(),google()仓库替换成阿里云的镜像。

5). 创建虚拟仓库,并把本地仓库和远程仓库加入到虚拟仓库

 

3. 在Android Library中使用

1). 项目的build.gradle

buildScript {
    repositories {
//        google()
//        jcenter()
        maven {
            url "http://localhost:8081/artifactory/my_virtual_repo/"
        }
    }
    ...
    dependencies {
        ...
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.15.2"
    }
}
allprojects {
    repositories {
//        google()
//        jcenter()
        maven {
            url "http://localhost:8081/artifactory/my_virtual_repo/"
        }
    }
}

2). library module的build.gradle

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


def MAVEN_LOCAL_PATH = "http://localhost:8081/artifactory"
def GROUP_ID = "YOUR GROUP ID"
def ARTIFACT_ID = "YOUR ARTIFACT ID"
def VERSION_NAME = "YOUR PROJECT VERSION NAME"

publishing {
    publications {
        aar_pub(MavenPublication) {
            groupId = GROUP_ID
            artifactId = ARTIFACT_ID
            version = VERSION_NAME

            artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")

            pom.withXml {
                def dependencies = asNode().appendNode("dependencies")
                configurations.api.allDependencies.each {
                    def dependency = dependencies.appendNode("dependency")
                    dependency.appendNode("groupId", it.group)
                    dependency.appendNode("artifactId", it.name)
                    dependency.appendNode("version", it.version)
                    //自己使用的一个第三方库
                    if (it.group == "org.linphone") {
                        dependency.appendNode("type", "aar")
                    }
                }
            }
        }
    }
}

artifactoryPublish {
    contextUrl = MAVEN_LOCAL_PATH
    publications("aar_pub")
    clientConfig.publisher.repoKey = "my_local_repo"
    clientConfig.publisher.username = "YOUR USERNAME"
    clientConfig.publisher.password = "YOUR PASSWORD"
}

dependencies {
    ...
    //使用api可以在其他项目引用本库的时候不用再添加此依赖
    api 'com.google.code.gson:gson:2.8.6'
    api "org.linphone:linphone-sdk-android:4.4.8"

}

3). 在Android Studio右侧打开Gradle,运行YOUR LIBRARY->Tasks->other->assembleRelease

4). 运行YOUR LIBRARY->Tasks->publishing->artifactoryPublish, gradle会上传aar到jfrog的本地仓库

5). JFrog的Artifacts可以看到上传的aar和pom文件,pom文件包含了library相关的依赖文件信息

4. 在项目中使用上传的aar文件

1). 修改项目的build.gradle

buildscript {
    ...
    repositories {
//        google()
//        jcenter()
        maven {
            url "http://localhost:8081/artifactory/my_virtual_repo/"
        }
    }
    ...
}

allprojects {
    repositories {
//        google()
//        jcenter()
        maven {
            url "http://localhost:8081/artifactory/my_virtual_repo/"
        }
    }
}

2). 修改app的build.gradle

dependencies {

    ...
    implementation 'YOUR_LIBRARY_GROUP_ID:YOUR_LIBRARY_ARTIFACT_ID:1.1.1'
}

注意事项:

每次上传新的aar需要先Clean Project,再执行assembleRelease和artifactoryPublish,否则jfrog里面不会更新。

参考文章:

最新jfrog artifactory搭建Android本地仓库教程

Android Artifactory仓库使用

AndroidStudio加速之--(三)发布aar到Artifactory

maven publish aar 打包第三依赖方法

版权声明
本文为[哆啦大梦幻]所创,转载请带上原文链接,感谢
https://my.oschina.net/yuewawa/blog/4972001