I have a project that is moving from the self-hosted Nexus to Google Artifact Registry. Migration was smooth till I've got deal with parent-dependency.
Everything is running in GitActions on ubuntu-22.04.
I have a project that builds and deploys as POM file like this:
mvn deploy:deploy-file -Dpackaging=pom -Dfile=$svcname-$version.pom -DrepositoryId=${{ inputs.maven-registry-type }} -Durl=${{ inputs.maven-registry }} -DgroupId="$grpname" -DartifactId="$svcname" -Dversion="$revision"
I can see that package appears in GCR. Works great.
Next, another project(another repo) needs this package and has to use it as parent. In my pom.xml file I have:
<parent>
<groupId>com.company.name</groupId>
<artifactId>common-parent</artifactId>
<version>VERSRION</version>
</parent>
<repositories>
<repository>
<id>common-parent</id>
<url>artifactregistry://region-maven.pkg.dev/project/common-parent</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.2.1</version>
</extension>
</extensions>
</build>
Package from Nexus was working great! But from GCR doesn't want to be downloaded. I'm getting error:
Cannot access artifactregistry://region-maven.pkg.dev/project/common-parent with type default using the available connector factories: BasicRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM @ line 10, column 10'
Locally behavior the same till I install parent package manually. With Nexus I haven't install it separately.
I was playing around and noticed that if I put the package to dependencies - it will be downloaded, but as parent doesn't work.
What am I missing?
UPD: I saw possible fix with adding empty parent.relativePath to pom.xml
<parent>
...
<relativePath />
</parent>
It didn't help.
Also, didn't help tricks with adding to maven -U like:
mvn install -U
But, I've found a solution, it is in the answer.
After hours of investigation I ran maven in debug more
mvn package -U -X
And got detailed errors in the output:
Caused by: org.eclipse.aether.transfer.NoTransporterException: Unsupported transport protocol artifactregistry
at org.eclipse.aether.transport.wagon.WagonTransporter.<init> (WagonTransporter.java:131)
at org.eclipse.aether.transport.wagon.WagonTransporterFactory.newInstance (WagonTransporterFactory.java:116)
at org.eclipse.aether.internal.impl.DefaultTransporterProvider.newTransporter (DefaultTransporterProvider.java:104)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector.<init> (BasicRepositoryConnector.java:129)
at org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory.newInstance (BasicRepositoryConnectorFactory.java:155)
at org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider.newRepositoryConnector (DefaultRepositoryConnectorProvider.java:107)
This error pointed me on a git issue opened back in 2021: wagon is not loaded for parent pom resolution. Which, eventually, points on the official doc page with notice:
Maven resolves some dependencies before applying a wagon defined in pom.xml, including:
Ok, so, parent is exactly my case, where solution is to add to the project folder .mvn with the file extensions.xml in it:
<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.1</version>
</extension>
</extensions>