0

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.

  • If you have create a simple pom why not using Maven itself to resolve the dependency and use the maven-antrun-pugin to integrate into the rest apart from migration to Maven... – khmarbaise Nov 18 '22 at 13:38
  • if you ever worked with legacy code... to answer your unrelated question - this is a proof of concept, imagine ant build script that is hundreds lines long, I dont want to change everything in one go – Paweł Kamiński Nov 18 '22 at 13:41
  • 1
    but I could probably run maven first install deps to local repo and then let m-resolver to use those deps there – Paweł Kamiński Nov 18 '22 at 13:42
  • but I thought that resolver would be a glue code between maven and ant and it seems not to be exactly this – Paweł Kamiński Nov 18 '22 at 13:43
  • I've worked a lot with legacy code+projects... and the migration is simpler and does not need intermediate steps with large efforts... The resolver is for resolving dependencies...but not a glue code between maven and ant... – khmarbaise Nov 18 '22 at 13:59
  • > he resolver is for resolving dependencies...but not a glue code between maven and ant... I am starting to realize that :) so what would you suggest I approach the problem. like 1. resolve dependencies with mvn dependency:tree - this will solve problem of interacting with gclooud via extension 2. .. – Paweł Kamiński Nov 18 '22 at 15:30

1 Answers1

1

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.