gpt4 book ai didi

android - 为 Android 库项目中的 AAR Artifact 指定部署的文件名

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:22:50 25 4
gpt4 key购买 nike

我正在尝试配置一个 Android 库项目以将多个 Artifact 部署到本地托管的 Maven 存储库。我已经走得够远了,两个 Artifact 都有自己的 POM 生成,并且它被正确部署到 repo,使用以下脚本:

android {
// Publish both debug and release
publishNonDefault true
}

uploadArchives {
repositories.mavenDeployer {
def majorVersion = 1
def minorVersion = 1
def buildVersion = project.properties.get('RELEASE', '0').toInteger()

addFilter('release') { artifact, file ->
file.name.contains('release')
}

addFilter('debug') { artifact, file ->
file.name.contains('debug')
}

activePomFilters.each { filter ->
pom(filter.name) {
groupId = 'com.redacted'
artifactId = 'redacted'
packaging = 'aar'
version = "${majorVersion}.${minorVersion}.${buildVersion}"

if (!project.hasProperty('RELEASE')) {
version += "-SNAPSHOT"
}

if (filter.name == 'debug') {
artifactId += '-debug'
}
}
}
}
}

预期的交付是:

com/
redacted/
redacted/
1.1.0-SNAPSHOT/
redacted-debug/
1.1.0-SNAPSHOT/

这是按预期发生的,但它似乎发布了带有附加后缀的 Artifact (这破坏了依赖项发现),我无法弄清楚它来自哪里,也不知道如何更改它。我看到的是:

com/redacted/redacted/1.1.0-SNAPSHOT/
redacted-1.1.0-20150717.213849-1-release.aar
redacted-1.1.0-20150717.213849-1-release.aar.md5
redacted-1.1.0-20150717.213849-1-release.aar.sha1
redacted-1.1.0-20150717.213849-1.pom
redacted-1.1.0-20150717.213849-1.pom.md5
redacted-1.1.0-20150717.213849-1.pom.sha1

出于某种原因,它仅将日期和 -release 后缀附加到与 AAR 相关的文件,而不是 POM 文件。如果我手动重命名这些文件,一切都会按预期进行。例如,这是我期望的输出:

com/redacted/redacted/1.1.0-SNAPSHOT/
redacted-1.1.0-20150717.213849-1.aar
redacted-1.1.0-20150717.213849-1.aar.md5
redacted-1.1.0-20150717.213849-1.aar.sha1
redacted-1.1.0-20150717.213849-1.pom
redacted-1.1.0-20150717.213849-1.pom.md5
redacted-1.1.0-20150717.213849-1.pom.sha1

如何更改这些文件的传送方式?

最佳答案

你遇到的是这个(强调我的):

Important: When enabling publishing of non default, the Maven publishing plugin will publish these additional variants as extra packages (with classifier). This means that this is not really compatible with publishing to a maven repository. You should either publish a single variant to a repository OR enable all config publishing for inter-project dependencies.

请参阅文档:http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication

后缀releasedebug您看到的是通过启用非默认 Artifact 的发布而引入的分类器。 <artifact> build/ivy.xml 中的元素,用作 Maven 配置的基础,包含这些分类器。

迭代配置中的 Artifact 并删除分类器不起作用。虽然允许设置分类器,但它的原始值被保留。

但真正起作用的是包装原始 Artifact 。包装器将始终返回 null对于分类器。这确实会导致发布和调试 Artifact 具有相同的完全限定 ID(= 名称 + 分类器),从而导致仅发布一个 Artifact 。这可以通过为调试 Artifact 使用不同的名称来解决:

class UnclassifiedPublishArtifact implements PublishArtifact {

private PublishArtifact delegatee;
private boolean isDebugArtifact;

UnclassifiedPublishArtifact(PublishArtifact delegatee, isDebugArtifact) {
this.delegatee = delegatee
this.isDebugArtifact = isDebugArtifact
}

@Override
String getName() {
return delegatee.name + (isDebugArtifact ? '-debug' : '')
}

@Override
String getExtension() {
return delegatee.extension
}

@Override
String getType() {
return delegatee.type
}

@Override
String getClassifier() {
return null
}

@Override
File getFile() {
return delegatee.file
}

@Override
Date getDate() {
return delegatee.date
}

@Override
TaskDependency getBuildDependencies() {
return delegatee.buildDependencies
}
}

project.afterEvaluate {
configurations.each { configuration ->
def artifacts = configuration.artifacts
if (!artifacts.isEmpty()) {
def unclassifiedArtifacts = []
unclassifiedArtifacts.addAll(artifacts.collect { classifiedArtifact ->
new UnclassifiedPublishArtifact(classifiedArtifact, classifiedArtifact.classifier == 'debug')
})
artifacts.clear()
artifacts.addAll(unclassifiedArtifacts)
}
}
}

我无法从文档中完全理解项目依赖项的后果是什么,因此您应该检查这些是否仍然有效。

关于android - 为 Android 库项目中的 AAR Artifact 指定部署的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31485298/

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