gpt4 book ai didi

android - 使用 gradle maven-publish 插件导出的 Kotlin Android 库模块不添加依赖项

转载 作者:搜寻专家 更新时间:2023-11-01 08:26:58 25 4
gpt4 key购买 nike

我正在尝试使用 gradle 的 maven-publish 导出在 Kotlin 中开发的 Android 库模块 plugin . aar 文件已成功生成并导出,但没有添加任何依赖项 - 根本没有,甚至没有 Kotlin 的依赖项。下面是基于this的插件配置回答:

apply plugin: 'maven-publish'

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

ext {
releaseRepository = "s3://****/maven/releases"
snapshotsRepository = "s3://****/maven/snapshots"
artifactRepository = "$buildDir/outputs/aar/render-engine-release.aar"

_version = properties.getProperty('lib.version')
_artifact = properties.getProperty('lib.name')
_group = properties.getProperty('lib.group')
}


task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier "source"
}

publishing {
publications {
maven(MavenPublication) {
groupId _group
artifactId _artifact
version _version
artifact (sourceJar)
artifact artifactRepository

pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

configurations.compile.allDependencies.each {
if(_group != null && (_artifact != null || "unspecified" == _artifact) && _version != null) {
def dependencyNode = dependenciesNode.appendNode('dependency')

dependencyNode.appendNode('groupId', _group)
dependencyNode.appendNode('artifactId', _artifact)
dependencyNode.appendNode('version', _version)
}
}
}
}
}

repositories {
maven {
if(_version.endsWith('-SNAPSHOT')) {
url snapshotsRepository
} else {
url releaseRepository
}

credentials(AwsCredentials) {
accessKey AWS_ACCESS_KEY
secretKey AWS_SECRET_KEY
}
}
}
}

最佳答案

好的,继续阅读链接 question 上的答案我已经实现了 this那解决了我的问题。我最终的 publish.gradle 是这样的:

apply plugin: 'maven-publish'

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

ext {
releaseRepository = "s3://****/maven/releases"
snapshotsRepository = "s3://****/maven/snapshots"
artifactRepository = "$buildDir/outputs/aar/render-engine-release.aar"

_version = properties.getProperty('lib.version')
_artifact = properties.getProperty('lib.name')
_group = properties.getProperty('lib.group')
}


task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier "source"
}

publishing {
publications {
maven(MavenPublication) {
groupId _group
artifactId _artifact
version _version
artifact(sourceJar)
artifact artifactRepository

pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

configurations.compile.getAllDependencies().each { Dependency dep ->
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
return

def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)

if (!dep.transitive) {
def exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('groupId', '*')
exclusionNode.appendNode('artifactId', '*')
} else if (!dep.properties.excludeRules.empty) {
def exclusionsNode = dependencyNode.appendNode('exclusions')
dep.properties.excludeRules.each { ExcludeRule rule ->
def exclusionNode = exclusionsNode.appendNode('exclusion')
exclusionNode.appendNode('groupId', rule.group ?: '*')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
}
}
}
}
}
}

repositories {
maven {
if (_version.endsWith('-SNAPSHOT')) {
url snapshotsRepository
} else {
url releaseRepository
}

credentials(AwsCredentials) {
accessKey AWS_ACCESS_KEY
secretKey AWS_SECRET_KEY
}
}
}
}

关于android - 使用 gradle maven-publish 插件导出的 Kotlin Android 库模块不添加依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43979348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com