'Maven project can't find dependency when deploy on Google Cloud Build
I will try to be brief
My problem is that Cloud Build is not looking for the parent of my project where it should. I explain what I have installed:
On the one hand, I have a Maven project of type "POM" uploaded in Artifact Registry. This project is successfully uploaded as I have been able to use it as a dependency in my current project
On the other hand, I have a Maven project with Spring Boot, which uses the project uploaded to Artifact Registry as parent
<parent>
<groupId>blorks.corp</groupId>
<artifactId>pom-repo</artifactId>
<version>1.0</version>
</parent>
The problem is that although I am able to use the dependency if I start my project on my PC, when I try to deploy it using Cloud Build it is not able to find the dependency
When I build my app on my PC, I can see in the console that the parent is being downloaded from the Artifact Repository
But when I try to deploy the app using Cloud Build, instead of looking for the dependency in the Artifact Repository, it looks for it in the Maven central repository
I upload my project code to Bitbucket, and Cloud Build tries to build the "master" branch of my bitbucket repository
To give more information, I put the POM file of the project that I try to deploy
<parent>
<groupId>blorks.corp</groupId>
<artifactId>pom-repo</artifactId>
<version>1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>com.google.cloud.artifactregistry</groupId>
<artifactId>artifactregistry-maven-wagon</artifactId>
<version>2.1.4</version>
</dependency>
</dependencies>
<distributionManagement>
<snapshotRepository>
<id>artifact-registry</id>
<url>artifactregistry://europe-west1-maven.pkg.dev/blorks-corp-gaming-wow/pom-repo</url>
</snapshotRepository>
<repository>
<id>artifact-registry</id>
<url>artifactregistry://europe-west1-maven.pkg.dev/blorks-corp-gaming-wow/pom-repo</url>
</repository>
</distributionManagement>
<repositories>
<repository>
<id>artifact-registry</id>
<url>artifactregistry://europe-west1-maven.pkg.dev/blorks-corp-gaming-wow/pom-repo</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
<extensions>
<extension>
<groupId>com.google.cloud.artifactregistry</groupId>
<artifactId>artifactregistry-maven-wagon</artifactId>
<version>2.1.4</version>
</extension>
</extensions>
</build>
I am a bit lost. I don't know where the error can come from... Maven? Cloud Build? Artifact Registry?
Solution 1:[1]
To add packages to the repository, use mvn deploy and mvn release.
The Artifact Registry Wagon provider must be included in a core extensions file to correctly deploy a Maven project that references a parent, as indicated in the authentication requirements.
To upload assets created outside of Maven, use mvn deploy:deploy-file.
This sample command, for example, deploys example/external.jar and its project file example/pom.xml to the us-central1-maven.pkg.dev/my-project/my-repo repository.
mvn deploy:deploy-file \
-Durl=artifactregistry://us-central1-maven.pkg.dev/my-project/my-repo \
-DpomFile=example/pom.xml -Dfile=example/external.jar
When connecting to a repository with a third-party application, you must first authenticate with Artifact Registry.
You must use the core extensions technique to ensure that Maven can identify parent POM files and plugins if your project needs to resolve these dependencies.
Create the file `$maven.projectBasedir/.mvn/extensions.xml? in your project with the following information. The wagon is defined by the extension> element.
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>com.google.cloud.artifactregistry</groupId>
<artifactId>artifactregistry-maven-wagon</artifactId>
<version>2.1.4</version>
</extension>
</extensions>
Maven may now use Artifact Registry to resolve parent or plugin dependencies.
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 | Jose German Perez Sanchez |




