发布AAR至Maven堆栈

计算机软件开发 2024-10-3 23:42:51 44 0 来自 中国
一、打包配置

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.libraryARTIFACT_ID=library# 在nexus配置的用户名USER_NAME=userName# 在nexus配置的用户暗码PASSWORD=password# 版本号VERSION=1.0.1-SNAPSHOT2、其他配置


  • 在必要打包的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
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 16:52, Processed in 0.152116 second(s), 32 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表