mavenmaven-3artifactorynexusartifact

Download Maven artifact with version range


I need download specific Maven artifact using version range e.g.:
GroupId:org.apache.logging.log4j
ArtifactId=log4j-api
Version=[2.17.1,)

Right now I need it in one CI job.

How can I do it?


Solution

  • I was hoping to find an easier solution, but at least this works:

    Create pom.xml file

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    
        <modelVersion>4.0.0</modelVersion>
        <groupId>cz.vondr</groupId>
        <artifactId>maven-dependency-download</artifactId>
        <version>1.0.0</version>
    
        <properties>
            <dep.group>org.apache.commons</dep.group>
            <dep.artifact>commons-lang3</dep.artifact>
            <dep.version>3.12.0</dep.version>
            <dep.type>jar</dep.type>
            <dep.classifier></dep.classifier>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>${dep.group}</groupId>
                <artifactId>${dep.artifact}</artifactId>
                <version>${dep.version}</version>
                <type>${dep.type}</type>
                <classifier>${dep.classifier}</classifier>
            </dependency>
        </dependencies>
    
    </project>
    

    And then use it to download artifact using command:
    mvn dependency:copy-dependencies "-DoutputDirectory=./downloaded-dependencies" -Ddep.group="org.apache.logging.log4j" -Ddep.artifact="log4j-api" -Ddep.version="[2.17.1,)"

    Additional information

    Basic description is here: http://vondrnotes.blogspot.com/2022/09/download-maven-artifact-with-version.html
    Working example is here: https://github.com/bugs84/download-maven-dependency-with-version-range