Gradle Maven Publish Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 22: Line 22:
==Mechanics==
==Mechanics==


The plugin creates an [[Gradle_Concepts#Extension|extension]] of type [https://docs.gradle.org/current/dsl/org.gradle.api.publish.PublishingExtension.html PublishingExtension] named "publishing". The extension provides a [[Gradle_Concepts#Container|container]] of named [[#Publications|publications]] and a [[Gradle_Concepts#Container|container]] of named [[#Repositories|repositories]]. The plugin does not have effect if no Maven publication is added to the publications container. If publications and repositories are present, the plugin creates [[tasks]] that can be used to carry out the publishing action.
The plugin creates an [[Gradle_Concepts#Extension|extension]] of type [https://docs.gradle.org/current/dsl/org.gradle.api.publish.PublishingExtension.html PublishingExtension] named "publishing". The extension provides a [[Gradle_Concepts#Container|container]] of named [[#Publications|publications]] and a [[Gradle_Concepts#Container|container]] of named [[#Repositories|repositories]]. The plugin does not have effect if no Maven publication is added to the publications container. If publications and repositories are present, the plugin creates [[#Publishing_Tasks|publishing tasks]] that can be used to carry out the publishing action.


==Publications==
==Publications==

Revision as of 22:04, 15 May 2018

External

Internal

Overview

"maven-publish" is an newer alternative to publishing with Maven Plugin, using "publish" tasks instead of Maven Plugin "Upload" tasks. The plugin generates Maven metadata and publishes the generated metadata and the associated artifacts to Maven repositories. The concepts behind publishing with "maven-publish", and the plugin mechanics, are described in the Concepts and Plugin Mechanics below. A step by step procedure is available under the Procedure section.

The plugin is activated with:

apply plugin: 'maven-publish'

Concepts and Plugin Mechanics

Mechanics

The plugin creates an extension of type PublishingExtension named "publishing". The extension provides a container of named publications and a container of named repositories. The plugin does not have effect if no Maven publication is added to the publications container. If publications and repositories are present, the plugin creates publishing tasks that can be used to carry out the publishing action.

Publications

A Maven Publication is the representation of how Gradle publishes an artifact in Maven format. The Maven Publish plugin publications are defined by the MavenPublication type. They are added to the publishing.publications as follows:

publishing {
  publications {
    publicationOne(MavenPublication) {
        artifact(source)
        artifact(source, configuration)
        from(component)
        pom(configuration)
    }
  }
}

The above syntax shows that an artifact can be specified by indicating the software component that should be published, or by defining the artifact in-line. If the artifact (or artifacts) are specified in-line, their details can be configured. The generated POM can be configured in-line as well.

Repositories

The Maven Publish plugin publications are defined by the MavenArtifactRepository type.

Relationship to pre-declared repositories, how can we use it?

Publishing Tasks

The plugin creates publishing tasks, based on available publications and repositories, and makes them available for use. All publishing tasks are triggered by the overarching "publish" tasks, which publishes all publications produced by the project.

Procedure

Activate the plugin:

apply plugin: 'maven-publish'

Declare the publications.

publishing {
  publications {
    myPublicationName(MavenPublication) {
      // Configure the publication here
    }
  }
}

Declared the target repositories. The example below assumes we want to publish locally into the local Maven repository, and also into a remote Maven repository:

repositories {
    maven {
        url "${url}"
        authentication {
            basic(BasicAuthentication)
        }
    }
}

Publish:

gradle publish