如何阻止向Bintray额外上传app-unspecified.aar文件?
我尝试创建Android库并发布至Bintray仓库,但执行bintrayUpload Gradle任务时,除了原始构件,还会额外上传名为app-unspecified.aar的文件。以下是我的publish.gradle配置代码及任务执行输出日志,请问如何阻止该额外文件的上传?
publish.gradle配置代码
apply plugin: 'maven-publish' apply plugin: 'com.jfrog.bintray' publishing { publications { library(MavenPublication) { groupId publishGroupId artifactId publishArtifactId version android.defaultConfig.versionName pom { name = publishArtifactId description = libraryDescription withXml { def dependenciesNode = asNode().appendNode('dependencies') configurations.implementation.allDependencies.each { if (it.name != 'unspecified') { def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', it.group) dependencyNode.appendNode('artifactId', it.name) dependencyNode.appendNode('version', it.version) } } } } } } } def _user = System.getenv("BINTRAY_USER") def _key = System.getenv("BINTRAY_API_KEY") if(project.rootProject.file('local.properties').exists() && (_user == null || _user.isEmpty())){ Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) _user = properties.getProperty("bintray.user") _key = properties.getProperty("bintray.apikey"); } bintray { user = _user key = _key override = true publications = ['library'] configurations = ['archives'] pkg { repo = bitrayRepo name = bintrayPackage desc = libraryDescription websiteUrl = siteUrl vcsUrl = gitUrl licenses = allLicenses publish = true publicDownloadNumbers = true version { name = android.defaultConfig.versionName released = new Date() vcsTag = android.defaultConfig.versionName } } }
任务执行输出日志
> Task :app:bintrayUpload Uploading to https://api.bintray.com/content/chathurabuddi/android/datetime-picker-wheel/0.0.1/datetime-picker-wheel/app/unspecified/app-unspecified.aar... Uploaded to 'https://api.bintray.com/content/chathurabuddi/android/datetime-picker-wheel/0.0.1/datetime-picker-wheel/app/unspecified/app-unspecified.aar'. Uploading to https://api.bintray.com/content/chathurabuddi/android/datetime-picker-wheel/0.0.1/lk/chathurabuddi/datetime-picker-wheel/0.0.1/datetime-picker-wheel-0.0.1.aar... Uploaded to 'https://api.bintray.com/content/chathurabuddi/android/datetime-picker-wheel/0.0.1/lk/chathurabuddi/datetime-picker-wheel/0.0.1/datetime-picker-wheel-0.0.1.aar'. Uploading to https://api.bintray.com/content/chathurabuddi/android/datetime-picker-wheel/0.0.1/lk/chathurabuddi/datetime-picker-wheel/0.0.1/datetime-picker-wheel-0.0.1.pom... Uploaded to 'https://api.bintray.com/content/chathurabuddi/android/datetime-picker-wheel/0.0.1/lk/chathurabuddi/datetime-picker-wheel/0.0.1/datetime-picker-wheel-0.0.1.pom'.
这个问题的核心原因是你在bintray配置里同时启用了publications和configurations = ['archives']。其中archives配置会默认包含Android模块自动生成的默认AAR文件(也就是那个app-unspecified.aar),而publications已经帮你处理了自定义命名的构件,两者叠加就导致了额外文件的上传。
解决起来很简单,只需要两步调整:
移除多余的
configurations配置
直接删掉bintray块里的configurations = ['archives']这一行,因为我们已经通过publications指定了要上传的构件,不需要再让archives配置来凑热闹了:bintray { user = _user key = _key override = true publications = ['library'] // 删掉这一行:configurations = ['archives'] pkg { // 原pkg配置内容不变... } }显式指定要上传的Artifact(可选但推荐)
虽然Gradle可能会自动关联正确的AAR,但为了避免后续出现其他意外,建议在MavenPublication块里明确指定要上传的AAR文件路径,让配置更清晰:library(MavenPublication) { groupId publishGroupId artifactId publishArtifactId version android.defaultConfig.versionName // 新增这一行,明确指定构件文件 artifact("$buildDir/outputs/aar/${publishArtifactId}-release.aar") pom { // 原pom配置内容不变... } }
做完这两步后,重新执行bintrayUpload任务,就只会上传你需要的datetime-picker-wheel-0.0.1.aar和对应的pom文件,那个烦人的app-unspecified.aar就不会再出现了。
内容的提问来源于stack exchange,提问作者Chathura Buddhika

