android - 'Received status code 400 from server: Bad Request' While publishing aar file to Github packages
问题描述
I am trying to push my library to GitHub Packages. I have configured the personal access token and have the github.properties file in the root folder.
The aar file is assembled, using gradle assemble
.
When I am running the gradle publish
command.
I am getting this error Received status code 400 from server: Bad Request
* What went wrong:
Execution failed for task ':library_to_publish:publishProductionPublicationToGitHubPackagesRepository'.
> Failed to publish publication 'Production' to repository 'GitHubPackages'
> Could not write to resource 'https://maven.pkg.github.com/<user>/GitHubPackagesDemo/com/avp/test/lib/githubpackages/library_to_publish/1.0.6/library_to_publish-1.0.6.aar'.
> Could not PUT 'https://maven.pkg.github.com/<user>/GitHubPackagesDemo/com/avp/test/lib/githubpackages/library_to_publish/1.0.6/library_to_publish-1.0.6.aar'. Received status code 400 from server: Bad Request
Here is my configuration in build.gradle
file
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'maven-publish'
def githubProperties = new Properties()
githubProperties.load(new FileInputStream(rootProject.file("github.properties")))
def getVersionName = { ->
return "1.0.6"
}
def getArtificatId = { ->
return "library_to_publish"
}
publishing {
publications {
Production(MavenPublication) {
groupId 'com.avp.test.lib.githubpackages' // Replace with group ID
artifactId getArtificatId()
version getVersionName()
artifact("$buildDir/outputs/aar/${getArtificatId()}-release.aar")
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
// Iterate over the implementation dependencies (we don't want the test ones),
// adding a <dependency> node for each
configurations.implementation.allDependencies.each {
// Ensure dependencies such as fileTree are not included in the pom.
if (it.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/<user>/GitHubPackagesDemo")
credentials {
username = githubProperties['gpr.usr'] ?: System.getenv("GPR_USER")
password = githubProperties['gpr.key'] ?: System.getenv("GPR_API_KEY")
}
}
}
}
Does anyone have any idea why is this happening?
解决方案
我设法通过更改版本名称来解决问题。Github 不允许推送相同的版本来覆盖现有版本。每次发布时都必须更新版本名称。
推荐阅读
- reactjs - “不可分配”使用泛型进行排序的类型错误
- posix - Mac OS 中的 POSIX_NAME_MAX 值是否仅为 14?
- flutter - 修复 Flutter 打印包 UI
- azure-active-directory - 调用 .\auth\refresh 端点后 Azure 应用服务身份验证令牌未刷新
- reactjs - 我收到一个错误“未定义许可证”,即使我确定它们在 setdetails 函数中是什么?我该如何解决这个问题?
- android-tv - 如何检测消防电视应用程序何时最小化?
- visual-studio - 通过命令行发布 Windows 应用程序包项目
- c - 带返回值的 pthread 函数的基本用法
- tensorflow - 为 SQLite 格式的 TFF 创建自定义联合图像数据集的最佳方法是什么?
- sql - SQL returning two rows matching different criteria into separate columns