3

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?

SproutinGeek
  • 327
  • 3
  • 19

1 Answers1

3

I managed to fix the problem, by changing the version name. Github won't allow pushing the same version to overwrite the existing one. you have to update the version name every time you publish.

SproutinGeek
  • 327
  • 3
  • 19
  • I believe this was true last year, but I find it hard to believe this is still the case in mid-2020. Have you found anything else since your answer? – Leo supports Monica Cellio May 14 '20 at 15:02
  • 2
    As of Oct 2020, its still true -- they return 409 Conflict now though. One can use the GraphQL API to delete (private) package versions first. – Raman Oct 02 '20 at 23:01