Gradle Maven Publish Plugin: Difference between revisions
Line 50: | Line 50: | ||
publishing { | publishing { | ||
publications { | publications { | ||
javacomp(MavenPublication) { | |||
from components.java | from components.java | ||
} | } |
Revision as of 22:24, 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 processes those configurations and based on their content, creates POM generation tasks and 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 {
<publication-name>(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.
Each publication must have an unique name within the project. All the artifacts associated with a publication share the groupID/artifactID/version project coordinates. A publication has a POM and at least one artifact, but it can have several artifacts (or example the class JAR and the source JAR).
Software Component Publication
publishing {
publications {
javacomp(MavenPublication) {
from components.java
}
}
}
Repositories
The Maven Publish plugin publications are defined by the MavenArtifactRepository type.
Relationship to pre-declared repositories, how can we use it?
POM Generation Tasks
Publishing Tasks
The plugin creates publishing tasks, based on declared publications and repositories, for the combination of each publication and repository, 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