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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With