How can I download artifacts from a Maven repository in a private Gitlab project using Ivy?

38 Views Asked by At

As part of an Apache Ant execution I need to download a set of artefacts using an incantation as shown below using resolve and retrieve.

The artefacts are located in a Maven Repository that is part of a private project. Due to this, I need to retrieve the artefacts using authenticated access.

<ivy:resolve>                          
    <dependency org="org.some"      
                name="artefact"  
                rev="0.0.1-SNAPSHOT" />
</ivy:resolve>                         
                                       
<ivy:retrieve />                       

How do I need to configure such access?

I have

1

There are 1 best solutions below

0
Jörn Guy Süß On

The solution uses basic auth and is based on this comment on sbt.

The credentials element has four attributes:

  • host: the name of the host

  • realm: the name of the realm (optional)

  • username: the username

  • passwd: the password

  • The realm can be left out, as it is automatically set by Gitlab.

  • The username is one of the Custom HTTP header Token type names, in the example below it is Private-Token.

  • The passwd is the value of the private token.

  • The host must be the DNS name of the gitlab host, below it is gitlab.com

Below is the resulting <ivysettings file: Two maven2 compatible resolvers are chained, with the first lacking a root attribute and so defaulting to ${ivy.ibiblio.default.artifact.root} which is Maven Central. The second points at the private repository on gitlab.

These settings can be enhanced to make use of interpolation of the project ID, so this template can be copied. Likewise, username and password can be extracted.

https://gitlab.example.com/api/v4/projects/<project_id>/packages/maven

using the Predefined Variable CI_PROJECT_ID via Ivy Properties and Ant environment import as shown here.

<ivysettings>
    <settings defaultResolver="local-chain" />
    <credentials host="gitlab.com"
        username="Private-Token" passwd="glpat-29Z9xUf-ns4RytWz-nV6" />
    <resolvers>
        <ibiblio name="maven2" m2compatible="true" />
        <ibiblio name="gitlab" m2compatible="true"
            root="https://gitlab.com/api/v4/projects/53177094/packages/maven" />
        <chain name="local-chain">
            <resolver ref="maven2" />
            <resolver ref="gitlab" />
        </chain>
    </resolvers>
</ivysettings>