You learned in a previous chapter how we can publish our project artifacts to a Maven repository. In this chapter, we are going to use an Ivy repository to which we can publish.
Just as with publishing to a Maven repository, we are going to use the new and incubating publishing feature in Gradle to publish to an Ivy repository.
We must add the ivy-publish
plugin to our project to be able to publish our artifacts to an Ivy repository. The plugin allows us to use the Ivy format to describe our artifacts that need to be published.
The ivy-publish
plugin is based on the general publishing
plugin. The publishing
plugin adds a new publishing
extension to our project. We can use a publications
configuration block in our build script to configure the artifacts we want to publish and the repositories we want to deploy to. The publications
extension has the PublishingExtension
type in the org.gradle.api.publish
package. The plugin also adds a general life cycle publish
task to the project. Other tasks can be added as task dependencies to this task, so with a single publish
task, all the project's publications can be published.
The ivy-publish
plugins also adds some extra task rules to the project. There is a task to generate an Ivy descriptor file to each publication in the project. The plugins also add a task rule based on a combination of the publication and the repository to publish a publication to the specified repository.
Let's create an example build file and apply the ivy-publish
plugin to see the new task:
apply plugin: 'ivy-publish' apply plugin: 'java'
Now, we will invoke the tasks
task from the command line:
$ gradle tasks ... Publishing tasks ---------------- publish - Publishes all publications produced by this project. ... BUILD SUCCESSFUL Total time: 4.589 secs
In the output, we see the publish
task. The dynamic task rules to publish single publications to repositories are not shown.
To configure our publications, we must first add a publishing
configuration block. Inside the block, we will define the publications
configuration block. In this block, we define a publication. A publication defines what needs to be published. The ivy-publish
plugin expects that a publication of the IvyPublication
type is found in the org.gradle.api.publish.ivy
package. Besides the artifacts that need to be published, we can also define details for the generated Ivy descriptor file.
3.144.15.154