android aar上传gitlab

在对应module目录下的build.gradle文件中

1、引入maven上传插件

plugins {
   id 'maven-publish'
}

2、在最后一行复制这些脚本

def BUILD_VERSION = '0.0.1'
// 源代码一起打包
task androidSourcesJar(type: Jar) {
    archiveClassifier.set('sources')
//    from android.sourceSets.main.java.sourceFiles
    from android.sourceSets.main.java.srcDirs
}
artifacts {
    archives androidSourcesJar
}
afterEvaluate {
    publishing {
        publications {
            aar(MavenPublication) {
//            from components.java
                groupId "com.xxx.xxx" // 包名
                artifactId "mylibrary" // module的名字   这个不配置的话,默认为 library 的名字,
                version BUILD_VERSION // 版本号
                artifact androidSourcesJar
                artifact("$buildDir/outputs/aar/mylibrary-release.aar") 

//                //maven-publish does not capture dependencies from this file
                pom.withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')
                    // Iterate over the api dependencies (we don't want the test ones), adding a <dependency> node for each
                    configurations.api.allDependencies.each {
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', it.group)
                        dependencyNode.appendNode('artifactId', it.name)
                        dependencyNode.appendNode('version', it.version)
                    }
                }
            }
        }
        repositories {
            maven {
                url "https://gitlab.com/api/v4/projects/projectsId/packages/maven"
                name "Gitlab"
                credentials(HttpHeaderCredentials) {
                    name = 'Deploy-Token'
                    value = 'Deploy-Token_Value'
                }
                authentication {
                    header(HttpHeaderAuthentication)
                }
            }
        }
    }
}

然后把这些修改成你自己的就行了。

groupId:包名

artifactId:module名

artifact("$buildDir/outputs/aar/module名-release.aar") 

url中的projectsId改成你自己的。比如projectsId是123.则 url "https://gitlab.com/api/v4/projects/123/packages/maven"

projectsId指的是gitlab项目下的projects Id。

Deploy-Token_Value改为你项目中的Deploy token。

Deploy token获取:

进入你项目,Settings -> Repository -> Deploy tokens ,然后创建deploy token

 

 

这里一定要复制一下deploy token ,因为页面关闭之后就再也看不到了

3、生成aar包

进入对应module下 执行clean命令,执行完成,再执行build命令

如图:

4、上传aar

执行publish命令。如上图

5、 aar成功之后,可以在Package Registry中看到。

6、引用aar,在根目录下的build.gradle文件中写入

 maven {
            url "https://gitlab.com/api/v4/projects/xxx/packages/maven"
            name "Gitlab"
            credentials(HttpHeaderCredentials) {
                name = 'Deploy-Token'
                value = 'xxx'
            }
            authentication {
                header(HttpHeaderAuthentication)
            }
        }

 xxx 需改为你的

引用aar包:

implementation 'com.xxx.xxx:mylibrary:0.0.1'

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值