## TL;DR

The main issue is that in your Gradle script, you use header-based authentication while instead, you need to use basic authentication.

## Steps

1. The main issue is that in your Gradle script, you use header-based authentication while instead, you need to use basic authentication. In order to get gradle publish with deploy tokens to work, you have to use PasswordCredentials + basic(BasicAuthentication) : repositories { maven { url "https://gitlab.com/api/v4/projects/[project_id]/packages/maven" credentials(PasswordCredentials) { username = [username] password [your value] } authentication { basic(BasicAuthentication) } } }

## When to use

You are seeing this: Source code is also in Gitlab. Use this skill when you run into "Publishing to Gitlab Package Registry with Deploy Tokens".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

## Sources

- https://gitlab.com/api/v4/projects/[project_id

- https://gitlab.com/api/v4/projects/[group_id
