'Publishing GitHub Packages returns 422 error
I have been using GitHub packages for a while, in an Android project, without having any issue. Now when I try to publish a new package I get the error:
Could not PUT Received status code 422 from server: Unprocessable Entity
To be sure that I hadn't change anything I went back to a git-tag from which I successfully managed to publish a package a few days ago, I changed only the version to generate a different package. I get the same error.
I added logs and I can see that the token is read correctly, all the value (GROUP, VERSION, etc) seem correct and that the file that I'm trying to publish is there in the correct folder. I have also tried to create and use a new token in case something was wrong with the old one but it didn't help.
Would GitHub reject the publishing with that error in case I published too many files? I did not find any documentation about the error that you get in that case.
EDIT
I have also tried to create a new project and post to that one, in case something had got messed up in the initial one, but it did not work either.
I have tried to PUT a file directly using CURL and this worked that means that the token is correct and that the problem is not the limit in the total size of the published packages:
curl -X PUT \
"https://maven.pkg.github.com/companyname/repositoryname/com/companyname/artifactid/v2.1.520/artifactid-v2.1.520.aar" \
-H "Authorization: token mytoken” \
--upload-file “/full/path/to/file.aar" -vvv
Of course, this is not the solutions since I need to post the maven repo with the pom etc.
END EDIT
Here my configuration that had been working for a long time and that is just following the documentation + the logs that I added to investigate the issue.
In the build.gradle:
allprojects {
repositories {
google()
jcenter()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/companyname/companyname-android-sdk")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GitHubPackagesUsername")
password = project.findProperty("gpr.key") ?: System.getenv("GitHubPackagesToken")
println "GitHubPackages build.gradle\n\tusername=$username\n\ttoken=$password"
}
}
}
}
in the publish-artifacts.gradle:
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/companyname/companyname-android-sdk")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GitHubPackagesUsername")
password = project.findProperty("gpr.key") ?: System.getenv("GitHubPackagesToken")
println "GitHubPackages Publish Artifact:\n\tusername=$username\n\ttoken=$password"
}
}
}
publications {
gpr(MavenPublication) {
println "\tskSdkVersion=$SK_SDK_VERSION\n\tarchivesBaseName=$archivesBaseName\n\tGROUP=$GROUP\n\tdesciption=$POM_DESCRIPTION"
println "artifact from $buildDir/outputs/aar/$archivesBaseName-${VARIANT_SUFFIX}.aar"
groupId SK_GROUP
version SK_SDK_VERSION
artifactId archivesBaseName
artifact "$buildDir/outputs/aar/$archivesBaseName-${VARIANT_SUFFIX}.aar"
description POM_DESCRIPTION
pom.packaging POM_PACKAGING
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
println "dependency=$it"
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
in the gradle.properties file:
POM_NAME=PackageName
POM_PACKAGING=aar
GROUP=com.companyname
POM_DESCRIPTION=CompanyName SDK Core library
VARIANT_SUFFIX is set from an env variable.
archivesBaseName is set in the module's build.gradle
Solution 1:[1]
In my case when the artifact had the name api or service or serde it was being blocked. eg. this worked <artifactId>database-ervice</artifactId> this did not database-service
Edit: When using Postman to do the put request I got
Package "io.XXX.mydomain.xyz-service" is already associated with another repository. so realised that the package was previously deplloyed in another repo.
The maven-deployer-plugin is extremely poor at reporting the error message of the PUT response so had to use mintm to lookup the url and Postman to figure out the message.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
