Home > Blockchain >  maven-resolver-ant with gcloud artifact registry
maven-resolver-ant with gcloud artifact registry

Time:11-23

I have strange problem

I want to use maven-resolver-ant to resolve dependencies in old project that builds with ant. so I ve created simple pom and for start I've set single jar dependency - this dependency is in my private gcloud artifact registry. to integrate with that gcloud service I added artifactregistry-maven-wagon extension to the pom and mvn clean compile works without a problem.

but when I reference the pom in build.xml nothing is downloaded from remote registry

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project
        default="run"
        name="old project"
        xmlns:resolver="antlib:org.apache.maven.resolver.ant">

    <taskdef uri="antlib:org.apache.maven.resolver.ant"
             resource="org/apache/maven/resolver/ant/antlib.xml">
        <classpath>
            <fileset dir="./jars" includes="maven-resolver-ant-tasks-1.4.*uber.jar"/>
        </classpath>
    </taskdef>

    <property name="target.lib" location="dist/lib" />

    <resolver:pom id="pom"
                  file="./pom.xml" />

    <target name="process-resources">
        <mkdir dir="${target.lib}"/>

        <resolver:resolve failOnMissingAttachments="true">
            <resolver:dependencies id="deps" >
                <pom refid="pom"/>
            </resolver:dependencies>
            <resolver:files dir="${target.lib}"
                            layout="{artifactId}-{classifier}.{extension}" />
        </resolver:resolve>
    </target>
</project>

resolver goes through maven's central remote repo, rather than use definitions from pom. So I thought that I just need to declare remote repo for resolver

    <resolver:remoterepo id="remote-registry" url="${pom.properties.my-registry-url}"
                         type="default" releases="true" snapshots="true"
                         updates="always" checksums="fail"/>


    <target name="process-resources">
        <mkdir dir="${target.lib}"/>

        <resolver:resolve failOnMissingAttachments="true">
            <resolver:dependencies id="deps" >
                <pom refid="pom"/>
            </resolver:dependencies>
            <resolver:remoterepos refid="remote-registry"/>
            <resolver:files dir="${target.lib}"
                            layout="{artifactId}-{classifier}.{extension}" />
        </resolver:resolve>
    </target>

but this fails with

Caused by: org.apache.maven.resolver.internal.ant.org.eclipse.aether.collection.DependencyCollectionException: Failed to collect dependencies at com.google.cloud.artifactregistry
Cannot access artifactregistry://...

this seems to me that resolver is not really using maven definition, and it cannot authenticate into gcloud. any hints? or I have bad luck and I should use something else as registry

I would expect that resolver will look at maven's model and use it's configuration and plugins to fetch all dependencies and just reference them in ant.

CodePudding user response:

first change I did was to set same id of the resolver:remoterepo as I have in my pom xml.

second was to add a task to target

<exec executable="mvn">
    <arg value="-Drat.skip=true" />
    <arg value="dependency:resolve"/>
</exec>

so now ant is calling maven so it resolves all dependencies graph, install those artifacts in local repo and ant's resolver plugin is happy to gather those artifacts from local repo without using gcloud's remote repo.

  • Related