Gradle Maven Publish Plugin: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 15: Line 15:


=Procedure=
=Procedure=
-----------------------
"maven-publish" is an newer alternative to publishing with [[Gradle Maven Plugin#Overview|Maven Plugin]], which uses the a task of type "[[Gradle_Maven_Plugin#Overview|Upload]]" task. It generates Maven metadata and pushes the artifacts and the metadata to a Maven repository.
<syntaxhighlight lang='groovy'>
apply plugin: 'maven-publish'
</syntaxhighlight>
="publishing" Extension=
The plugin creates a "publishing" [[Gradle_Concepts#Extension|extension]] of type [https://docs.gradle.org/current/dsl/org.gradle.api.publish.PublishingExtension.html PublishingExtension]. This extension provides a [https://docs.gradle.org/current/dsl/org.gradle.api.publish.maven.MavenPublication.html container of named publications] and a [https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.repositories.MavenArtifactRepository.html container of named repositories].
<syntaxhighlight lang='groovy'>
publishing {
  publications {
    myPublicationName(MavenPublication) {
      // Configure the publication here
    }
  }
}
</syntaxhighlight>
<syntaxhighlight lang='groovy'>
repositories {
    maven {
        url "${url}"
        authentication {
            basic(BasicAuthentication)
        }
    }
}
</syntaxhighlight>
Publications are published to repositories via tasks and the configuration of the publication object determines exactly what is published.
The plugin does not have effect if no MavenPublication is added to the publications [[Gradle_Concepts#Container|container]]. A publication determines which artifacts are actually published as well as the details included in the associated POM file. A publication can be configured by adding components, customizing artifacts, and by modifying the generated POM file directly.
=Publishing to a Maven Repository=
==Apply the Plugin==
<syntaxhighlight lang='groovy'>
apply plugin: 'maven-publish'
</syntaxhighlight>
==Define the Publications==
==Define the Repository==
==Execute==
gradle publish

Revision as of 21:28, 15 May 2018

External

Internal

Overview

The concepts behind publishing with "maven-publish", and the publishing mechanics, are described in the Concepts and Plugin Mechanics below. A step by step procedure is available under the Procedure section.

Concepts and Plugin Mechanics

Procedure