doc/user/packages/maven_repository/_index.md
{{< details >}}
{{< /details >}}
Publish Maven artifacts in your project's package registry. Then, install the packages whenever you need to use them as a dependency.
For documentation of the specific API endpoints that the Maven package manager client uses, see the Maven API documentation.
Supported clients:
You need a token to publish a package. There are different tokens available depending on what you're trying to achieve. For more information, review the guidance on tokens.
Create a token and save it to use later in the process.
Do not use authentication methods other than the methods documented here. Undocumented authentication methods might be removed in the future.
Update your configuration to authenticate to the Maven repository with HTTP.
You must add the authentication details to the configuration file for your client.
{{< tabs >}}
{{< tab title="mvn" >}}
| Token type | Name must be | Token |
|---|---|---|
| Personal access token | Private-Token | Paste token as-is, or define an environment variable to hold the token |
| Deploy token | Deploy-Token | Paste token as-is, or define an environment variable to hold the token |
| CI Job token | Job-Token | ${CI_JOB_TOKEN} |
[!note] The
<name>field must be named to match the token you chose.
Add the following section to your
settings.xml file.
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>REPLACE_WITH_NAME</name>
<value>REPLACE_WITH_TOKEN</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
{{< /tab >}}
{{< tab title="gradle" >}}
| Token type | Name must be | Token |
|---|---|---|
| Personal access token | Private-Token | Paste token as-is, or define an environment variable to hold the token |
| Deploy token | Deploy-Token | Paste token as-is, or define an environment variable to hold the token |
| CI Job token | Job-Token | System.getenv("CI_JOB_TOKEN") |
[!note] The
<name>field must be named to match the token you chose.
In your GRADLE_USER_HOME directory,
create a file gradle.properties with the following content:
gitLabPrivateToken=REPLACE_WITH_YOUR_TOKEN
Add a repositories section to your
build.gradle
file:
In Groovy DSL:
repositories {
maven {
url "https://gitlab.example.com/api/v4/groups/<group>/-/packages/maven"
name "GitLab"
credentials(HttpHeaderCredentials) {
name = 'REPLACE_WITH_NAME'
value = gitLabPrivateToken
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
In Kotlin DSL:
repositories {
maven {
url = uri("https://gitlab.example.com/api/v4/groups/<group>/-/packages/maven")
name = "GitLab"
credentials(HttpHeaderCredentials::class) {
name = "REPLACE_WITH_NAME"
value = findProperty("gitLabPrivateToken") as String?
}
authentication {
create("header", HttpHeaderAuthentication::class)
}
}
}
{{< /tab >}}
{{< /tabs >}}
You can also use basic HTTP authentication to authenticate to the Maven package registry.
{{< tabs >}}
{{< tab title="mvn" >}}
| Token type | Name must be | Token |
|---|---|---|
| Personal access token | The username of the user | Paste token as-is, or define an environment variable to hold the token |
| Deploy token | The username of deploy token | Paste token as-is, or define an environment variable to hold the token |
| CI Job token | gitlab-ci-token | ${CI_JOB_TOKEN} |
Add the following section to your
settings.xml file.
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<username>REPLACE_WITH_NAME</username>
<password>REPLACE_WITH_TOKEN</password>
<configuration>
<authenticationInfo>
<userName>REPLACE_WITH_NAME</userName>
<password>REPLACE_WITH_TOKEN</password>
</authenticationInfo>
</configuration>
</server>
</servers>
</settings>
{{< /tab >}}
{{< tab title="gradle" >}}
| Token type | Name must be | Token |
|---|---|---|
| Personal access token | The username of the user | Paste token as-is, or define an environment variable to hold the token |
| Deploy token | The username of deploy token | Paste token as-is, or define an environment variable to hold the token |
| CI Job token | gitlab-ci-token | System.getenv("CI_JOB_TOKEN") |
In your GRADLE_USER_HOME directory,
create a file gradle.properties with the following content:
gitLabPrivateToken=REPLACE_WITH_YOUR_TOKEN
Add a repositories section to your
build.gradle.
In Groovy DSL:
repositories {
maven {
url "https://gitlab.example.com/api/v4/groups/<group>/-/packages/maven"
name "GitLab"
credentials(PasswordCredentials) {
username = 'REPLACE_WITH_NAME'
password = gitLabPrivateToken
}
authentication {
basic(BasicAuthentication)
}
}
}
In Kotlin DSL:
repositories {
maven {
url = uri("https://gitlab.example.com/api/v4/groups/<group>/-/packages/maven")
name = "GitLab"
credentials(BasicAuthentication::class) {
username = "REPLACE_WITH_NAME"
password = findProperty("gitLabPrivateToken") as String?
}
authentication {
create("basic", BasicAuthentication::class)
}
}
}
{{< /tab >}}
{{< tab title="sbt" >}}
| Token type | Name must be | Token |
|---|---|---|
| Personal access token | The username of the user | Paste token as-is, or define an environment variable to hold the token |
| Deploy token | The username of deploy token | Paste token as-is, or define an environment variable to hold the token |
| CI Job token | gitlab-ci-token | sys.env.get("CI_JOB_TOKEN").get |
Authentication for SBT is based on basic HTTP Authentication. You must to provide a name and a password.
[!note] The name field must be named to match the token you chose.
To install a package from the Maven GitLab package registry by using sbt, you must configure
a Maven resolver.
If you're accessing a private or an internal project or group, you need to set up
credentials.
After configuring the resolver and authentication, you can install a package
from a project, group, or namespace.
In your build.sbt, add the following lines:
resolvers += ("gitlab" at "<endpoint url>")
credentials += Credentials("GitLab Packages Registry", "<host>", "<name>", "<token>")
In this example:
<endpoint url> is the endpoint URL.
Example: https://gitlab.example.com/api/v4/projects/<project_id>/packages/maven.<host> is the host present in the <endpoint url> without the protocol
scheme or the port. Example: gitlab.example.com.<name> and <token> are explained in the previous table.{{< /tab >}}
{{< /tabs >}}
You can use one of three endpoints to install a Maven package. You must publish a package to a project, but the endpoint you choose determines the settings you add to your pom.xml file for publishing.
The three endpoints are:
For the instance-level endpoint, ensure the relevant section of your pom.xml in Maven looks like this:
<groupId>group-slug.subgroup-slug</groupId>
<artifactId>project-slug</artifactId>
Only packages that have the same path as the project are exposed by the instance-level endpoint.
| Project | Package | Instance-level endpoint available |
|---|---|---|
foo/bar | foo/bar/1.0-SNAPSHOT | Yes |
gitlab-org/gitlab | foo/bar/1.0-SNAPSHOT | No |
gitlab-org/gitlab | gitlab-org/gitlab/1.0-SNAPSHOT | Yes |
| Endpoint | Endpoint URL for pom.xml | Additional information |
|---|---|---|
| Project | https://gitlab.example.com/api/v4/projects/<project_id>/packages/maven | Replace gitlab.example.com with your domain name. Replace <project_id> with your project ID, found on your project overview page. |
| Group | https://gitlab.example.com/api/v4/groups/<group_id>/-/packages/maven | Replace gitlab.example.com with your domain name. Replace <group_id> with your group ID, found on your group's homepage. |
| Instance | https://gitlab.example.com/api/v4/packages/maven | Replace gitlab.example.com with your domain name. |
You must add publishing details to the configuration file for your client.
{{< tabs >}}
{{< tab title="mvn" >}}
No matter which endpoint you choose, you must have:
distributionManagement section.repository and distributionManagement section.The relevant repository section of your pom.xml in Maven should look like this:
<repositories>
<repository>
<id>gitlab-maven</id>
<url><your_endpoint_url></url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.example.com/api/v4/projects/<project_id>/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.example.com/api/v4/projects/<project_id>/packages/maven</url>
</snapshotRepository>
</distributionManagement>
id is what you defined in settings.xml.<your_endpoint_url> depends on which endpoint you choose.gitlab.example.com with your domain name.{{< /tab >}}
{{< tab title="gradle" >}}
To publish a package by using Gradle:
Add the Gradle plugin maven-publish to the plugins section:
In Groovy DSL:
plugins {
id 'java'
id 'maven-publish'
}
In Kotlin DSL:
plugins {
java
`maven-publish`
}
Add a publishing section:
In Groovy DSL:
publishing {
publications {
library(MavenPublication) {
from components.java
}
}
repositories {
maven {
url "https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/maven"
credentials(HttpHeaderCredentials) {
name = "REPLACE_WITH_TOKEN_NAME"
value = gitLabPrivateToken // the variable resides in $GRADLE_USER_HOME/gradle.properties
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
In Kotlin DSL:
publishing {
publications {
create<MavenPublication>("library") {
from(components["java"])
}
}
repositories {
maven {
url = uri("https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/maven")
credentials(HttpHeaderCredentials::class) {
name = "REPLACE_WITH_TOKEN_NAME"
value =
findProperty("gitLabPrivateToken") as String? // the variable resides in $GRADLE_USER_HOME/gradle.properties
}
authentication {
create("header", HttpHeaderAuthentication::class)
}
}
}
}
{{< /tab >}}
{{< /tabs >}}
[!warning] Using the
DeployAtEndoption can cause an upload to be rejected with400 bad request {"message":"Validation failed: Name has already been taken"}. For more details, see issue 424238.
After you have set up the authentication and chosen an endpoint for publishing, publish a Maven package to your project.
{{< tabs >}}
{{< tab title="mvn" >}}
To publish a package by using Maven:
mvn deploy
If the deploy is successful, the build success message should be displayed:
...
[INFO] BUILD SUCCESS
...
The message should also show that the package was published to the correct location:
Uploading to gitlab-maven: https://example.com/api/v4/projects/PROJECT_ID/packages/maven/com/mycompany/mydepartment/my-project/1.0-SNAPSHOT/my-project-1.0-20200128.120857-1.jar
{{< /tab >}}
{{< tab title="gradle" >}}
Run the publish task:
gradle publish
Go to your project's Packages and registries page and view the published packages.
{{< /tab >}}
{{< tab title="sbt" >}}
Configure the publishTo setting in your build.sbt file:
publishTo := Some("gitlab" at "<endpoint url>")
Ensure the credentials are referenced correctly. See the sbt documentation for more information.
To publish a package using sbt:
sbt publish
If the deploy is successful, the build success message is displayed:
[success] Total time: 1 s, completed Jan 28, 2020 12:08:57 PM
Check the success message to ensure the package was published to the correct location:
[info] published my-project_2.12 to https://gitlab.example.com/api/v4/projects/PROJECT_ID/packages/maven/com/mycompany/my-project_2.12/0.1.1-SNAPSHOT/my-project_2.12-0.1.1-SNAPSHOT.pom
{{< /tab >}}
{{< /tabs >}}
[!note] If you protect a Maven package before publishing it, the package will be rejected with a
403 Forbiddenerror and anAuthorization failederror message. Ensure the Maven package is not protected when publishing. For more information about package protection rules, see how to protect a package.
To install a package from the GitLab package registry, you must configure the remote and authenticate. When this is completed, you can install a package from a project, group, or namespace.
If multiple packages have the same name and version, when you install a package, the most recently-published package is retrieved.
{{< tabs >}}
{{< tab title="mvn" >}}
To install a package by using mvn install:
Add the dependency manually to your project pom.xml file.
To add the example created earlier, the XML would be:
<dependency>
<groupId>com.mycompany.mydepartment</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
In your project, run the following:
mvn install
The message should show that the package is downloading from the package registry:
Downloading from gitlab-maven: http://gitlab.example.com/api/v4/projects/PROJECT_ID/packages/maven/com/mycompany/mydepartment/my-project/1.0-SNAPSHOT/my-project-1.0-20200128.120857-1.pom
You can also install packages by using the Maven dependency:get command directly.
In your project directory, run:
mvn dependency:get -Dartifact=com.nickkipling.app:nick-test-app:1.1-SNAPSHOT -DremoteRepositories=gitlab-maven::::<gitlab endpoint url> -s <path to settings.xml>
<gitlab endpoint url> is the URL of the GitLab endpoint.<path to settings.xml> is the path to the settings.xml file that contains the authentication details.[!note] The repository IDs in the
gitlab-mavencommand and thesettings.xmlfile must match.
The message should show that the package is downloading from the package registry:
Downloading from gitlab-maven: http://gitlab.example.com/api/v4/projects/PROJECT_ID/packages/maven/com/mycompany/mydepartment/my-project/1.0-SNAPSHOT/my-project-1.0-20200128.120857-1.pom
{{< /tab >}}
{{< tab title="gradle" >}}
To install a package by using gradle:
Add a dependency to build.gradle in the dependencies section:
In Groovy DSL:
dependencies {
implementation 'com.mycompany.mydepartment:my-project:1.0-SNAPSHOT'
}
In Kotlin DSL:
dependencies {
implementation("com.mycompany.mydepartment:my-project:1.0-SNAPSHOT")
}
In your project, run the following:
gradle build
{{< /tab >}}
{{< tab title="sbt" >}}
To install a package by using sbt:
Add an inline dependency to build.sbt:
libraryDependencies += "com.mycompany.mydepartment" % "my-project" % "8.4"
In your project, run the following:
sbt update
{{< /tab >}}
{{< /tabs >}}
{{< history >}}
{{< /history >}}
The GitLab Maven package registry uses remote included checksums. When you download a file, the registry proxies the file and sends both the file and its related checksums to Maven clients in a single request.
Using remote included checksums with recent Maven clients:
Due to technical constraints, when you use object storage, the Maven package registry ignores the proxy download
setting in the object storage configuration for packages.
Instead, proxy download is always enabled for Maven package registry downloads.
[!note] If you don't use object storage, this behavior has no impact on your instance.
You can use CI/CD to automatically build, test, and publish Maven packages. The examples in this section cover scenarios like:
You can adapt and combine these examples to suit your specific project needs.
Remember to adjust the Maven version, Java version, and other specifics according to your project requirements. Also, make sure you properly configured the necessary credentials and settings for publishing to the GitLab package registry.
This example configures a pipeline that builds and publishes a Maven package:
default:
image: maven:3.8.5-openjdk-17
cache:
paths:
- .m2/repository/
- target/
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
stages:
- build
- test
- publish
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
publish:
stage: publish
script:
- mvn $MAVEN_CLI_OPTS deploy
rules:
- if: $CI_COMMIT_BRANCH == "main"
For larger projects with multiple modules, you can use parallel jobs to speed up the build process:
default:
image: maven:3.8.5-openjdk-17
cache:
paths:
- .m2/repository/
- target/
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
stages:
- build
- test
- publish
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile
test:
stage: test
parallel:
matrix:
- MODULE: [module1, module2, module3]
script:
- mvn $MAVEN_CLI_OPTS test -pl $MODULE
publish:
stage: publish
script:
- mvn $MAVEN_CLI_OPTS deploy
rules:
- if: $CI_COMMIT_BRANCH == "main"
This example creates versioned releases when a tag is pushed:
default:
image: maven:3.8.5-openjdk-17
cache:
paths:
- .m2/repository/
- target/
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
stages:
- build
- test
- publish
- release
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
publish:
stage: publish
script:
- mvn $MAVEN_CLI_OPTS deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
release:
stage: release
script:
- mvn versions:set -DnewVersion=${CI_COMMIT_TAG}
- mvn $MAVEN_CLI_OPTS deploy
rules:
- if: $CI_COMMIT_TAG
This example publishes packages only when certain files are changed:
default:
image: maven:3.8.5-openjdk-17
cache:
paths:
- .m2/repository/
- target/
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
stages:
- build
- test
- publish
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
publish:
stage: publish
script:
- mvn $MAVEN_CLI_OPTS deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
changes:
- pom.xml
- src/**/*
This example integrates code quality checks and security scans into the pipeline:
default:
image: maven:3.8.5-openjdk-17
cache:
paths:
- .m2/repository/
- target/
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
include:
- template: Security/SAST.gitlab-ci.yml
- template: Code-Quality.gitlab-ci.yml
stages:
- build
- test
- quality
- publish
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
code_quality:
stage: quality
sast:
stage: quality
publish:
stage: publish
script:
- mvn $MAVEN_CLI_OPTS deploy
rules:
- if: $CI_COMMIT_BRANCH == "main"
When you publish a package with the same name and version as an existing package, the new package files are added to the existing package. You can still use the UI or API to access and view the existing package's older assets.
To delete older package versions, consider using the Packages API or the UI.
{{< history >}}
{{< /history >}}
To prevent users from publishing duplicate Maven packages, you can use the GraphQl API or the UI.
In the UI:
[!note] If Allow duplicates is turned on, you can specify package names and versions that should not have duplicates in the Exceptions text box.
Your changes are automatically saved.
{{< history >}}
maven_central_request_forwarding. Disabled by default.{{< /history >}}
[!flag] The availability of this feature is controlled by a feature flag. For more information, see the history.
When a Maven package is not found in the package registry, the request is forwarded to Maven Central.
When the feature flag is enabled, administrators can disable this behavior in the Continuous Integration settings.
Maven forwarding is restricted to only the project level and group level endpoints. The instance level endpoint has naming restrictions that prevent it from being used for packages that don't follow that convention and also introduces too much security risk for supply-chain style attacks.
mvnWhen using mvn, there are many ways to configure your Maven project so that it requests packages
in Maven Central from GitLab. Maven repositories are queried in a
specific order.
By default, Maven Central is usually checked first through the
Super POM, so
GitLab needs to be configured to be queried before maven-central.
To ensure all package requests are sent to GitLab instead of Maven Central,
you can override Maven Central as the central repository by adding a <mirror>
section to your settings.xml:
<settings>
<servers>
<server>
<id>central-proxy</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value><personal_access_token></value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
<mirrors>
<mirror>
<id>central-proxy</id>
<name>GitLab proxy of central repo</name>
<url>https://gitlab.example.com/api/v4/projects/<project_id>/packages/maven</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
After you have configured your repository to use the Package Repository for Maven, you can configure GitLab CI/CD to build new packages automatically.
{{< tabs >}}
{{< tab title="mvn" >}}
You can create a new package each time the default branch is updated.
Create a ci_settings.xml file that serves as Maven's settings.xml file.
Add the server section with the same ID you defined in your pom.xml file.
For example, use gitlab-maven as the ID:
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${CI_JOB_TOKEN}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
Make sure your pom.xml file includes the following.
You can either let Maven use the predefined CI/CD variables, as shown in this example,
or you can hard code your server's hostname and project's ID.
<repositories>
<repository>
<id>gitlab-maven</id>
<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
</snapshotRepository>
</distributionManagement>
Add a deploy job to your .gitlab-ci.yml file:
deploy:
image: maven:3.6-jdk-11
script:
- 'mvn deploy -s ci_settings.xml'
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Push those files to your repository.
The next time the deploy job runs, it copies ci_settings.xml to the
user's home location. In this example:
root, because the job runs in a Docker container.{{< /tab >}}
{{< tab title="gradle" >}}
You can create a package each time the default branch is updated.
Authenticate with a CI job token in Gradle.
Add a deploy job to your .gitlab-ci.yml file:
deploy:
image: gradle:6.5-jdk11
script:
- 'gradle publish'
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Commit files to your repository.
When the pipeline is successful, the Maven package is created.
{{< /tab >}}
{{< /tabs >}}
The version string is validated by using the following regex.
\A(?!.*\.\.)[\w+.-]+\z
You can experiment with the regex and try your version strings on this regular expression editor.
To use different URLs or settings for snapshots and releases:
<distributionManagement> section of your pom.xml file, define separate <repository> and <snapshotRepository> elements.There are some Maven command-line options that you can use when performing tasks with GitLab CI/CD.
File transfer progress can make the CI logs hard to read.
Option -ntp,--no-transfer-progress was added in
3.6.1.
Alternatively, look at -B,--batch-mode
or lower level logging changes.
Specify where to find the pom.xml file (-f,--file):
package:
script:
- 'mvn --no-transfer-progress -f helloworld/pom.xml package'
Specify where to find the user settings (-s,--settings) instead of
the default location. There's also a -gs,--global-settings option:
package:
script:
- 'mvn -s settings/ci.xml package'
The GitLab Maven repository supports the following CLI commands:
{{< tabs >}}
{{< tab title="mvn" >}}
mvn deploy: Publish your package to the package registry.mvn install: Install packages specified in your Maven project.mvn dependency:get: Install a specific package.{{< /tab >}}
{{< tab title="gradle" >}}
gradle publish: Publish your package to the package registry.gradle build: Assembles and tests this project.{{< /tab >}}
{{< /tabs >}}
While working with Maven packages in GitLab, you might encounter an issue. To resolve many common issues, try these steps:
settings.xml file for correct configuration.mvn commands - Always run Maven commands with the -s option, for example, mvn package -s settings.xml. Without this option, authentication settings aren't applied, and Maven might fail to find packages.To improve performance, clients cache files related to a package. If you encounter issues, clear the cache with these commands:
{{< tabs >}}
{{< tab title="mvn" >}}
rm -rf ~/.m2/repository
{{< /tab >}}
{{< tab title="gradle" >}}
rm -rf ~/.gradle/caches # Or replace ~/.gradle with your custom GRADLE_USER_HOME
{{< /tab >}}
{{< /tabs >}}
If you are having issues with the Maven Repository, you may want to review network trace logs. Reviewing network trace logs provides more detailed error messages, which Maven clients do not include by default.
For example, try to run mvn deploy locally with a PAT token and use these options:
mvn deploy \
-Dorg.slf4j.simpleLogger.log.org.apache.maven.wagon.providers.http.httpclient=trace \
-Dorg.slf4j.simpleLogger.log.org.apache.maven.wagon.providers.http.httpclient.wire=trace
[!warning] When you set these options, all network requests are logged and a large amount of output is generated.
If you encounter issues within CI/CD that relate to the settings.xml file, try adding
an additional script task or job to verify the effective settings.
The help plugin can also provide system properties, including environment variables:
mvn-settings:
script:
- 'mvn help:effective-settings'
package:
script:
- 'mvn help:system'
- 'mvn package'
401 Unauthorized error when trying to publish a packageThis usually indicates an authentication issue. Check that:
api, read_api, or read_repository).-s option with your mvn commands (for example, mvn deploy -s settings.xml). Without this option, Maven won't apply the authentication settings from your settings.xml file, leading to unauthorized errors.400 Bad Request error with message "Validation failed: Version is invalid"GitLab has specific requirements for version strings. Ensure your version follows the format:
^(?!.*\.\.)(?!.*\.$)[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*(\+[0-9A-Za-z-]+)?$
For example, "1.0.0", "1.0-SNAPSHOT", and "1.0.0-alpha" are valid, but "1..0" or "1.0." are not.
403 Forbidden error when trying to publish a packageThe 403 Forbidden error with the message Authorization failed usually indicates either an authentication or permissions issue. Check that:
Artifact already exists errors when publishingThis error occurs when you try to publish a package version that already exists. To resolve:
If you've just published a package, it might take a few moments to appear. If it still doesn't show:
Dependency conflicts can be resolved by:
pom.xml.<exclusions> tag to exclude conflicting transitive dependencies.Unable to find valid certification path to requested target errorThis is typically a SSL certificate issue. To resolve:
No plugin found for prefix pipeline errorsThis usually means Maven can't find the plugin. To fix:
pom.xml.