# Failed to publish publication 'gpr' to repository 'GitHubPackages' because of HTTP 422 error

**URL:** <https://discuss.gradle.org/t/failed-to-publish-publication-gpr-to-repository-githubpackages-because-of-http-422-error/45692>\
**Category:** Help/Discuss\
**Created:** [May 26, 2023, 6:36am UTC](https://discuss.gradle.org/t/failed-to-publish-publication-gpr-to-repository-githubpackages-because-of-http-422-error/45692 "2023-05-26T06:36:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeWarren](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@MikeWarren](https://discuss.gradle.org/u/MikeWarren)\
**Post date:** [May 26, 2023, 6:36am UTC](https://discuss.gradle.org/t/failed-to-publish-publication-gpr-to-repository-githubpackages-because-of-http-422-error/45692/1 "2023-05-26T06:36:43Z")

</div>

I am trying to publish my Katalon Studio SDK to GitHub packages.

I have been [following these instructions](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#example-using-gradle-groovy-for-a-single-package-in-a-repository) to do so.

I created environment variables `GITHUB_ACTOR` and `GITHUB_TOKEN` on my machine, set up my `build.gradle` and then tried to run it.

My `build.gradle` looks like:

## The `build.gradle` file

```gradle
plugins {
  id 'java'
  id 'maven-publish'
  id "com.katalon.gradle-plugin" version "0.1.1"
}

group = 'com.mikewarren.katalonstudiosdk'
version = '1.0'

dependencies {
  implementation 'com.github.javafaker:javafaker:1.0.2'
}

repositories {
    mavenCentral()
}

sourceSets {
    main {
        groovy {
            srcDirs = ['Keywords', 'Libs']
            excludes = ['CustomKeywords.groovy', "Temp*.groovy"]
        }
    }
    test {
        groovy {
            srcDirs = ['Include/scripts/groovy']
        }
    }
}

publishing {
    repositories { 
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/MikeWarren2014/KatalonStudioSDK")
            credentials {
                username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
                password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
            }
        }
    }
    publications {
        gpr(MavenPublication) {
            from components.java
        }
    }
}

```

## How I tried to run it

At the BASH shell, I said:

```gradle
gradle clean build --info

```

## What happened

What ended up happening…is this:

```gradle
> Task :publishGprPublicationToGitHubPackagesRepository FAILED
Caching disabled for task ':publishGprPublicationToGitHubPackagesRepository' because:
  Build cache is disabled
Task ':publishGprPublicationToGitHubPackagesRepository' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Publishing to repository 'GitHubPackages' (https://maven.pkg.github.com/MikeWarren2014/KatalonStudioSDK)
Uploading KatalonStudioSDK-1.0.jar to /MikeWarren2014/KatalonStudioSDK/com/mikewarren/katalonstudiosdk/KatalonStudioSDK/1.0/KatalonStudioSDK-1.0.jar
:publishGprPublicationToGitHubPackagesRepository (Thread[Execution worker for ':' Thread 3,5,main]) completed. Took 1.5 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':publishGprPublicationToGitHubPackagesRepository'.
> Failed to publish publication 'gpr' to repository 'GitHubPackages'
   > Could not PUT 'https://maven.pkg.github.com/MikeWarren2014/KatalonStudioSDK/com/mikewarren/katalonstudiosdk/KatalonStudioSDK/1.0/KatalonStudioSDK-1.0.jar'. Received status code 422 from server: Unprocessable Entity

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

```

I did a sanity check on the environment variables prior to running this script, they were initialized.

## What did you try?

I tried to check the artifact ID, whatever it is in this context (is it the `group` and `version`?) and can’t seem to find it here… idk what to do here…

I tried to check if something with `${group}:${version}` existed already, via [this guy’s code snippet](https://discuss.gradle.org/t/how-to-check-maven-artifact-exists-before-publish/17192/7), which returned an HTTP 401 error instead. The `GITHUB_TOKEN` environment variable came straight from a package-read-write-authorized [personal access token (classic) created on GitHub](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-personal-access-token-classic) .

What is the way to fix this once and for all?!

---

<div class="post-metadata">

**Author:** ![MikeWarren](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@MikeWarren](https://discuss.gradle.org/u/MikeWarren)\
**Post date:** [May 26, 2023, 7:28pm UTC](https://discuss.gradle.org/t/failed-to-publish-publication-gpr-to-repository-githubpackages-because-of-http-422-error/45692/2 "2023-05-26T19:28:31Z")

</div>

**UPDATE** : I found the solution here, and it is two-fold:

- to take care of the HTTP 422 error: It turns out that it was taking the folder name `KatalonStudioSDK` as the artifact ID. I fixed that by writing

```gradle
artifactId = 'katalon-studio-sdk'

```

inside the `gpr` closure , and then

- to take care of the HTTP 401 error: restart the BASH shell, so that the environment variables `GITHUB_ACTOR` and `GITHUB_TOKEN` get recognized by it
