# Ivy Publishing (new)

This chapter describes the new incubating Ivy publishing support provided by the “`ivy-publish`” plugin. Eventually this new publishing support will replace publishing via the `Upload` task.

If you are looking for documentation on 'traditional' Ivy publishing using the `Upload` task please see artifact_management.

This chapter describes how to publish build artifacts in the Apache Ivy format, usually to a repository for consumption by other builds or projects. What is published is one or more artifacts created by the build, and an Ivy module descriptor (normally `ivy.xml`) that describes the artifacts and the dependencies of the artifacts, if any.

A published Ivy module can be consumed by Gradle (see dependency_management) and other tools that understand the Ivy format.

## The “`ivy-publish`” Plugin

The ability to publish in the Ivy format is provided by the “`ivy-publish`” plugin.

The “`publishing`” plugin creates an extension on the project named “`publishing`” of type . This extension provides a container of named publications and a container of named repositories. The “`ivy-publish`” plugin works with publications and repositories.

Applying the “`ivy-publish`” plugin does the following:

- Applies the “`publishing`” plugin
- Establishes a rule to automatically create a task for each added (see publishing_ivy:publications).
- Establishes a rule to automatically create a task for the combination of each added (see publishing_ivy:publications), with each added (see publishing_ivy:repositories).

## Publications

If you are not familiar with project artifacts and configurations, you should read the artifact_management that introduces these concepts. This chapter also describes “publishing artifacts” using a different mechanism than what is described in this chapter. The publishing functionality described here will eventually supersede that functionality.

Publication objects describe the structure/configuration of a publication to be created. Publications are published to repositories via tasks, and the configuration of the publication object determines exactly what is published. All of the publications of a project are defined in the container. Each publication has a unique name within the project.

For the “`ivy-publish`” plugin to have any effect, a must be added to the set of publications. This publication determines which artifacts are actually published as well as the details included in the associated Ivy module descriptor file. A publication can be configured by adding components, customising artifacts, and by modifying the generated module descriptor file directly.

### Publishing a Software Component

The simplest way to publish a Gradle project to an Ivy repository is to specify a to publish. The components presently available for publication are:

### Software Components

Name | Provided By | Artifacts | Dependencies
`java` | Java Plugin | Generated jar file | Dependencies from 'runtime' configuration
`web` | War Plugin | Generated war file | No dependencies

In the following example, artifacts and runtime dependencies are taken from the `java` component, which is added by the `Java Plugin`.

### Publishing custom artifacts

It is also possible to explicitly configure artifacts to be included in the publication. Artifacts are commonly supplied as raw files, or as instances of (e.g. Jar, Zip).

For each custom artifact, it is possible to specify the `name`, `extension`, `type`, `classifier` and `conf` values to use for publication. Note that each artifacts must have a unique name/classifier/extension combination.

Configure custom artifacts as follows:

See for more detailed documentation on how artifacts can be customised.

### Identity values for the published project

The generated Ivy module descriptor file contains an`<info>` tag that identifies the module. The default identity values are derived from the following project properties:

- `organisation` -
- `module` -
- `revision` -
- `status` -

Certain repositories are not able to handle all supported characters. For example, the ':' character cannot be used as an identifier when publishing to a filesystem-backed repository on Windows.

Note that you can set the value of these project properties in your build script, with the exception of `name`.

Gradle will handle any valid Unicode character for organisation, module and revision (as well as artifact name, extension and classifier). The only values that are explicitly prohibited are '`\`', '`/`' and any ISO control character. The supplied values are validated early in publication.

### Modifying the generated module descriptor

At times, the module descriptor file generated from the project information will need to be tweaked before publishing. The “`ivy-publish`” plugin provides a hook to allow such modification.

In this example we are adding a 'description' element to the generated Ivy dependency descriptor, but this this hook, allows you to modify any aspect of the generated descriptor. For example, you could replace the version range for a dependency with the actual version used to produce the build.

See for the relevant API reference documentation.

It is possible to modify virtually any aspect of the created descriptor should you need to. This means that it is also possible to modify the descriptor in such a way that it is no longer a valid Ivy module descriptor, so care must be taken when using this feature.

The identifier (organisation, module, revision) of the published module is an exception; these values cannot be modified in the descriptor using the `withXML` hook.

## Repositories

Publications are published to repositories. The repositories to publish to are defined by the container.

The DSL used to declare repositories for publishing is the same DSL that is used to declare repositories for dependencies (). However, in the context of Ivy publication only the repositories created by the `ivy()` methods can be used as publication destinations. You cannot publish an `IvyPublication` to a Maven repository for example.

## Performing a publish

The “`ivy-publish`” plugin automatically creates a task for each and combination in the `publishing.publications` and `publishing.repositories` containers respectively.

The created task is named using the pattern "`publish«NAME OF PUBLICATION»PublicationTo«NAME OF REPOSITORY»Repository`". So in this example a single task is be added, named '`publishIvyJavaPublicationToIvyRepository`'.

### The “`publish`” lifecycle task

The “`publish`” plugin (that the “`ivy-publish`” plugin implicitly applies) adds a lifecycle task that can be used to publish all publications to all applicable repositories named “`publish`”.

In more concrete terms, executing this task will execute all tasks in the project. This is usually the most convenient way to perform a publish.

## Generating the Ivy module descriptor file without publishing

At times it is useful to generate the Ivy module descriptor file (normally `ivy.xml`) without publishing your module to an Ivy repository. Since descriptor file generation is performed by a separate task, this is very easy to do.

The “`ivy-publish`” plugin automatically wires in one task for each registered . This task is given a name based on the name of the publication: "`generate«NAME OF PUBLICATION»IvyModuleDescriptor`". So in the above example where the publication is named "`ivyJava`", the task will be named "`generateIvyJavaIvyModuleDescriptor`".

You can specify where the generated Ivy file will be located by setting the `destination` property on the generate task. By default this file is generated to `build/publications/«NAME OF PUBLICATION»/ivy.xml`.

The “`ivy-publish`” plugin leverages some experimental support for late plugin configuration, and the `GenerateIvyDescriptor` task will not be constructed until the publishing extension is configured. The simplest way to ensure that the publishing plugin is configured when you attempt to access the `GenerateIvyDescriptor` task is to place the access inside a `publishing` block, as the above example demonstrates.

The same applies to any attempt to access publication-specific tasks like . These tasks should be referenced from within a `publishing` block.

## Complete example

The following example demonstrates publishing with a multi-project build. Each project publishes a java component and a configured additional source artifact. The descriptor file is customized to include the project description for each project.

The result is that the following artifacts will be published for each project:

- The Ivy module descriptor file: `ivy-1.0.xml`.
- The primary “jar” artifact for the java component: `project1-1.0.jar`.
- The source “jar” artifact that has been explicitly configured:`project1-1.0-source.jar`.

When `project1` is published, the module descriptor (i.e. the `ivy.xml` file) that is produced will look like…

Note that the `«PUBLICATION-TIME-STAMP»` in this example Ivy module descriptor will be the timestamp of when the descriptor was generated.

## Future features

The “`ivy-publish`” plugin functionality as described above is incomplete, as the feature is still incubating. Over the coming Gradle releases, the functionality will be expanded to include (but not limited to):

- Convenient customisation of module attributes (`module`, `organisation` etc.)
- Convenient customisation of dependencies reported in `module descriptor`.
- Multiple discreet publications per project