Ivy-maven-plugin

From Evgeny Goldin

Jump to: navigation, search

"Fly away, Stanley. Be free!"


Contents

Introduction

"ivy-maven-plugin" widens Maven boundaries and brings Ivy repositories to your Maven builds! It allows to perform 2 major actions:

  • Use Ivy resolvers to retrieve artifacts from repositories non-compatible with Maven, such as those of TeamCity, Launchpad or local file system.
    This is useful if your Maven build needs to access artifacts available online or locally in some kind of non-Maven storage for which a custom resolver can be defined.
  • Add Ivy artifacts to Maven scope such as "compile" or "test" and use them in the corresponding compilation or testing phases.
    This is useful if your Maven build needs to compile sources or run tests using libraries not available in Maven repositories.


Ivy artifacts can be specified in two ways:

  • Standard "ivy.xml" file.
  • Standard Maven <dependencies>.


Details

Provided By
Mailing List Nabble
Source Code GitHub
License
Tests GitHub
GroovyDoc <groovydoc>
Issue Tracker YouTrack
Build Server Maven
TeamCity
Maven Coordinates
  • com.github.goldin:ivy-maven-plugin:0.2.5
Goal
  • ivy
Default Phase
  • initialize
Maven Repository Artifactory Online


Examples

Downloading Intellij IDEA Ivy artifacts - Maven dependencies

Let's say you need to download Intellij IDEA Community Edition artifacts, available in the publicly available TeamCity build, similarly to how it can be done with Ant.

1. Define "ivyconf.xml" with TeamCity-specific resolver:

<ivysettings>
    <property name='ivy.checksums' value=''/>
    <statuses>
        <status name='integration' integration='true'/>
    </statuses>
    <resolvers>
        <url name='idea-repo'   alwaysCheckExactRevision='yes' checkmodified='true'>
            <ivy      pattern='http://teamcity.jetbrains.com/guestAuth/repository/download/[module]/[revision]/teamcity-ivy.xml'/>
            <artifact pattern='http://teamcity.jetbrains.com/guestAuth/repository/download/[module]/[revision]/[artifact](.[ext])'/>
        </url>
    </resolvers>
    <modules>
        <module organisation='org' name='bt343' matcher='regexp' resolver='idea-repo'/>
    </modules>
</ivysettings>

2. Plug it in and download IDEA artifacts, specifying them explicitly together with any other Maven dependencies, similarly to Ivy's <retrieve> (taken from this test):

<plugin>
    <groupId>com.github.goldin</groupId>
    <artifactId>ivy-maven-plugin</artifactId>
    <version>0.2.5</version>
    <executions>
        <execution>
            <id>get-idea-artifacts</id>
            <goals>
                <goal>ivy</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
                <ivyconf>${project.basedir}/src/main/resources/ivyconf.xml</ivyconf>
                <dir>${outputDir}/idea</dir>
                <dependencies>
                    <dependency>
                        <groupId>ivy.org</groupId>
                        <artifactId>bt343</artifactId>
                        <version>latest.lastSuccessful</version>
                        <classifier>core/intellij-core</classifier>
                        <destFileName>intellij-core.jar</destFileName>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.ant</groupId>
                        <artifactId>ant</artifactId>
                        <version>1.8.2</version>
                    </dependency>
                </dependencies>
            </configuration>
        </execution>
    </executions>
</plugin>

Note:

  • You could also use "copy-maven-plugin" or "maven-dependency-plugin" to download artifacts as if they were regular Maven dependencies but it is not required, as "ivy-maven-plugin" provides a convenient <dir> configuration.
  • Ivy dependency <groupId> should start with "ivy." to distinguish it from regular Maven dependency.
  • See additional information about TeamCity acting as Ivy repository and various <version> values you may use such as "latest.lastFinished", "latest.lastSuccessful", and "latest.lastPinned".
  • Ivy dependency <classifier> plays a role of Ivy <include> element with "exact" pattern matcher to match a single file. It should be used when multiple artifacts with identical "org:name:rev" ("groupId:artifactId:version") coordinates are available. For example, IDEA build produces multiple artifacts ("sources.zip", "core/intellij-core.jar", etc), all having "org:bt343:latest.lastSuccessful" coordinates so you need to specify a <classifier> and a <type> where required to select a single artifact:


<dependency>
    <groupId>ivy.org</groupId>
    <artifactId>bt343</artifactId>
    <version>31</version>
    <classifier>sources</classifier>
    <type>zip</type>
</dependency>
<dependency>
    <groupId>ivy.org</groupId>
    <artifactId>bt343</artifactId>
    <version>latest.lastSuccessful</version>
    <classifier>core/intellij-core</classifier>
</dependency>


Downloading Intellij IDEA Ivy artifacts - Ivy dependencies

Alternatively, you may specify dependencies you need using "ivy.xml".

1. Define "ivyconf.xml" with TeamCity-specific resolver, as previously.
2. Define "ivy.xml" with IDEA-specific dependencies or any other dependencies you may need.

<ivy-module version="1.3">
    <info organisation="com.jetbrains" module="idea"/>
    <dependencies>
        <dependency org="org" name="bt343" rev="latest.lastSuccessful">
            <include name="core/.*" ext="jar" matcher="exactOrRegexp"/>
        </dependency>
    </dependencies>
</ivy-module>

2. Plug them in and download all dependencies defined in "ivy.xml", similarly to Ivy's <retrieve> (taken from this test):

<plugin>
    <groupId>com.github.goldin</groupId>
    <artifactId>ivy-maven-plugin</artifactId>
    <version>0.2.5</version>
    <executions>
        <execution>
            <id>get-idea-artifacts</id>
            <goals>
                <goal>ivy</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
                <ivyconf>${project.basedir}/src/main/resources/ivyconf.xml</ivyconf>
                <ivy>${project.basedir}/src/main/resources/ivy.xml</ivy>
                <dir>${outputDir}/idea</dir>
            </configuration>
        </execution>
    </executions>
</plugin>


Adding Ivy artifacts to Maven "compile" scope

Let's say you want to develop an IDEA plugin and you need "intellij-core.jar" to be added to the compilation classpath, similarly to Ivy's <cachepath>. All you need to do is replace <dir> we've seen before with <scope>compile</scope> (taken from this test):

<plugin>
    <groupId>com.github.goldin</groupId>
    <artifactId>ivy-maven-plugin</artifactId>
    <version>0.2.5</version>
    <executions>
        <execution>
            <id>add-idea-artifacts-compile-scope</id>
            <goals>
                <goal>ivy</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
                <ivyconf>${project.basedir}/src/main/resources/ivyconf.xml</ivyconf>
                <ivy>${project.basedir}/src/main/resources/ivy.xml</ivy>
                <scope>compile</scope>
            </configuration>
        </execution>
    </executions>
</plugin>
  • Make sure you run this execution before "compile" phase so that artifacts resolved are added to the compilation classpath before it begins.


<configuration>

Name Optional Description
<ivyconf> false Ivy settings file path. Local path and resource URL retrieved with ClassLoader.getResource() is accepted.
<ivy> true Ivy dependencies file path. Local path and resource URL retrieved with ClassLoader.getResource() is accepted.
<dependencies> true <ivy> alternative - dependencies to resolve. Each <dependency> is an instance of ArtifactItem.
<scope> true Comma-separated Maven scopes to add artifacts resolved to, similarly to Ivy's <cachepath>.

"plugin-runtime" is a special scope, normally used programmatically. Using it adds artifacts to caller's runtime classloader.

<dir> true Local directory to copy artifacts resolved to, similarly to Ivy's <retrieve>.
<verbose> true Whether Ivy-related actibity should be logged verbosely.

Only download processes are logged when <verbose> is set to false, general Ivy information is logged when it is not specified and verbose logging is provided when it is set to true.

<failOnError> true Whether execution should fail if resolving artifacts didn't succeed, true by default.
Personal tools