Publish Pre-Built MAVEN dependency into GCP Artifact Registry

Karthick
2 min readSep 20, 2024

--

This is my first post, and I decided to share it based on the challenges I faced while trying to accomplish a seemingly simple task.

Goal: Publish jar & POM files to GCP artifact registry from local machine.

Existing Docs: GCP Document provided a standard document but it doesn’t fulfill the requirements.

Refer footer for Maven commands to push jar files.

The main issue lies in adding the extensions as specified in the document. Even after updating the `pom.xml` with the necessary extensions, the `maven-deploy` command fails, leaving you uncertain about what exactly went wrong.

[INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.499 s
[INFO] Finished at: 2024-09-19T16:17:56-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: Failed to deploy artifacts/metadata: Cannot access artifactregistry://<artifact-path> with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access artifactregistry://<artifact-path> using the registered transporter factories: WagonTransporterFactory: Unsupported transport protocol artifactregistry: java.util.NoSuchElementException
[ERROR] role: org.apache.maven.wagon.Wagon
[ERROR] roleHint: artifactregistry
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

To resolve the error, create a .mvn/extensions.xml file in the folder containing the dependent JARs and POM files.

extensions.xml

<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.2.0</version>
</extension>
</extensions>

Above extension works well for GCP and it might be the similar case with other cloud providers as well.

Maven commands:

Following commands might be helpful for reference incase you haven’t used.

Publish Jar file:

mvn deploy:deploy-file \
-Durl=artifactregistry://<artifact path from GCP AR> \
-DpomFile=<path-to-pom-file> -Dfile=<path-to-jar-file>

Publish POM file only:

mvn deploy:deploy-file \
-Durl=artifactregistry://<artifact path from GCP AR> \
-Dfile=<path-to-pom-file> -Dpackaging=pom -DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version>

--

--