“从服务器接收到状态代码400:错误的请求”将aar文件发布到Github软件包时

我正在尝试将我的库推送到GitHub Packages。 我已经配置了个人访问令牌,并且在根文件夹中有github.properties文件。

使用gradle assemble来组装aar文件。

当我运行gradle publish命令时。 我收到此错误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

这是我在build.gradle文件中的配置

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")
            }
        }
    }
}


有人知道为什么会这样吗?

shadowryo 回答:“从服务器接收到状态代码400:错误的请求”将aar文件发布到Github软件包时

我设法通过更改版本名称来解决此问题。 Github不允许推送相同版本来覆盖现有版本。您每次发布时都必须更新版本名称。

本文链接:https://www.f2er.com/3102450.html

大家都在问