Gradle Maven Publish Plugin: Difference between revisions
Line 26: | Line 26: | ||
==Publications== | ==Publications== | ||
The Maven Publish plugin publications are defined by the [https://docs.gradle.org/current/dsl/org.gradle.api.publish.maven.MavenPublication.html MavenPublication] type. | A Maven Publication is the representation of how Gradle publishes an artifact in Maven format. The Maven Publish plugin publications are defined by the [https://docs.gradle.org/current/dsl/org.gradle.api.publish.maven.MavenPublication.html MavenPublication] type. They are added to the <tt>publishing.publications</tt> as follows: | ||
<syntaxhighlight lang='groovy'> | |||
publishing { | |||
publications { | |||
publicationOne(MavenPublication) { | |||
// Configure the publication here | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
==Repositories== | ==Repositories== |
Revision as of 21:55, 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.
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) {
// Configure the publication here
}
}
}
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