# 发布AAR至Maven仓库 站点:答源(https://www.dandroid.cn/) 原文:https://www.dandroid.cn/archives/12433 Canonical:https://www.dandroid.cn/archives/12433 作者:dandroid007 发布日期:2023-07-20 最后更新:2023-09-09 04:20 分类:技术方案 内容类型:post 说明:本页是原文的纯文本镜像,供大模型与检索器完整读取;不含导航、广告、付费框。引用请以上方「原文」链接为准。 ## 正文 一、打包配置 1、编辑脚本 在需要打包的module下创建 publish.gradle apply plugin: 'maven-publish' task generateSourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier 'sources' } afterEvaluate { publishing { publications { Production(MavenPublication) { // Applies the component for the release build variant. from components.release groupId = GROUP_ID artifactId = ARTIFACT_ID version = VERSION // 上传source,这样使用放可以看到方法注释 artifact generateSourcesJar } } repositories { // 定义一个 maven 仓库 maven { url = VERSION.endsWith('SNAPSHOT') ? SNAPSHOT_URL : RELEASE_URL // 仓库用户名密码 credentials { username = USER_NAME password = PASSWORD } // 允许通过不安全的HTTP连接与仓库通信 allowInsecureProtocol(true) } } } } gradle.properties(配置打包脚本中依赖的资源) RELEASE_URL=http://120.66.66.66:6666/repository/maven-releases/ SNAPSHOT_URL=http://120.66.66.66:6666/repository/maven-snapshots/ GROUP_ID=com.test.library ARTIFACT_ID=library # 在nexus配置的用户名 USER_NAME=userName # 在nexus配置的用户密码 PASSWORD=password # 版本号 VERSION=1.0.1-SNAPSHOT 2、其他配置 在需要打包的module下的build.gradle中配置 apply from : "publish.gradle" 3、执行打包 在Android studio的Terminal中执行命令 ./gradlew publish 二、使用配置 项目根目录下的build.gradle添加依赖仓库 maven { // maven仓库地址 url 'http://120.66.66.66:6666/repository/maven-public/' // 允许使用http访问的maven仓库,如果是https则不用配置 allowInsecureProtocol = true } module下的build.gradle中添加依赖 // com.test.library 是groupId // library 是artifactId // 1.0.1-SNAPSHOT 是版本号 implementation 'com.test.library:library:1.0.1-SNAPSHOT' 三、报错集合 does not allow updating artifact 报错信息 Artifact updating: Repository ='releases:Releases' does not allow updating artifact='/com/github/120011676/vine/maven-metadata.xml.sha256' 解决方案 Gradle 6.x及以上发布仓库去除sha256、sha512 CheckSum文件 Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. 报错信息 Failed to apply plugin 'com.android.internal.application'. > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8. You can try some of the following options: - changing the IDE settings. - changing the JAVA_HOME environment variable. - changing `org.gradle.java.home` in `gradle.properties`. 解决方案 在项目根目录的gradle.properties中配置 # 指定Gradle依赖的JAVA版本 org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home --- 由 答源 DAN 底座 1.4.1 生成 · 2026-11-16T16:03:15+00:00