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
Publishing a package 1 Create or use an existing access token with the appropriate scopes for the task you want to accomplish. For more... 2 Authenticate to GitHub Packages using your access token and the instructions for your package client. 3 Publish the package using the instructions for your package client. More ...
If a new version of a package fixes a security vulnerability, you should publish a security advisory in your repository. GitHub reviews each published security advisory and may use it to send Dependabot alerts to affected repositories. For more information, see " About GitHub Security Advisories ."
A repository can be connected to more than one package. To prevent confusion, make sure the README and description clearly provide information about each package. If a new version of a package fixes a security vulnerability, you should publish a security advisory in your repository.
GitHub Packages is not available for private repositories owned by accounts using legacy per-repository plans. Also, accounts using legacy per-repository plans cannot access the Container registry since these accounts are billed by repository. For more information, see " GitHub's products ."
Could you try lower casing your artifact ID? I was facing the same issue and lowercasing it made it work.
Reference: https://github.community/t/gradle-maven-deploy-failing-with-422-unprocessable-entity/137299/3
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.
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