【问题标题】:'Received status code 400 from server: Bad Request' While publishing aar file to Github packages“从服务器收到状态码 400:错误请求”将 aar 文件发布到 Github 包时
【发布时间】:2019-11-14 12:59:25
【问题描述】:

我正在尝试将我的库推送到 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")
            }
        }
    }
}


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

【问题讨论】:

    标签: android gradle maven-publish github-package-registry


    【解决方案1】:

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

    【讨论】:

    • 我相信去年确实如此,但我很难相信 2020 年年中仍然如此。自从您回答后,您还发现了什么?
    • 截至 2020 年 10 月,它仍然是正确的——尽管他们现在返回 409 Conflict。可以先使用 GraphQL API 删除(私有)包版本。
    猜你喜欢
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 2022-01-20
    • 2019-12-12
    相关资源
    最近更新 更多