api / org.gradle.api.publish.maven

Package org.gradle.api.publish.maven

Types

MavenArtifact

interface MavenArtifact : PublicationArtifact

An artifact published as part of a MavenPublication.

MavenArtifactSet

interface MavenArtifactSet : DomainObjectSet<MavenArtifact>

A Collection of MavenArtifacts to be included in a MavenPublication. Being a DomainObjectSet, a MavenArtifactSet provides convenient methods for querying, filtering, and applying actions to the set of MavenArtifacts.

 apply plugin: 'maven-publish' def publication = publishing.publications.create("name", MavenPublication) def artifacts = publication.artifacts artifacts.matching({ it.classifier == "classy" }).all({ it.extension = "ext" }) 

MavenDependency

interface MavenDependency

A dependency declared as part of an MavenPublication.

MavenPom

interface MavenPom

The POM for a Maven publication.

The #withXml(org.gradle.api.Action) method can be used to modify the descriptor after it has been generated according to the publication data. However, the preferred way to customize the project information to be published is to use the dedicated properties exposed by this class, e.g. #getDescription(). Please refer to the official POM Reference for detailed information about the individual properties.

MavenPomCiManagement

interface MavenPomCiManagement

The CI management system of a Maven publication.

MavenPomContributor

interface MavenPomContributor

A contributor of a Maven publication.

MavenPomContributorSpec

interface MavenPomContributorSpec

Allows to add contributors of a Maven publication.

MavenPomDeveloper

interface MavenPomDeveloper

A developer of a Maven publication.

MavenPomDeveloperSpec

interface MavenPomDeveloperSpec

Allows to add developers to a Maven publication.

MavenPomDistributionManagement

interface MavenPomDistributionManagement

The distribution management configuration of a Maven publication.

MavenPomIssueManagement

interface MavenPomIssueManagement

The issue management system of a Maven publication.

MavenPomLicense

interface MavenPomLicense

A license of a Maven publication.

MavenPomLicenseSpec

interface MavenPomLicenseSpec

Allows to add licenses to a Maven publication.

MavenPomMailingList

interface MavenPomMailingList

A mailing list of a Maven publication.

MavenPomMailingListSpec

interface MavenPomMailingListSpec

Allows to add mailing lists to a Maven publication.

MavenPomOrganization

interface MavenPomOrganization

The organization of a Maven publication.

MavenPomRelocation

interface MavenPomRelocation

The relocation information of a Maven publication that has been moved to a new group and/or artifact ID.

MavenPomScm

interface MavenPomScm

The SCM (source control management) of a Maven publication.

MavenPublication

interface MavenPublication : Publication

A MavenPublication is the representation/configuration of how Gradle should publish something in Maven format. You directly add a named Maven Publication the project's publishing.publications container by providing MavenPublication as the type.

 publishing { publications { myPublicationName(MavenPublication) { // Configure the publication here } } } 
The default Maven POM identifying attributes are mapped as follows:
  • groupId - project.group
  • artifactId - project.name
  • version - project.version

For certain common use cases, it's often sufficient to specify the component to publish, and nothing more (#from(org.gradle.api.component.SoftwareComponent). The published component is used to determine which artifacts to publish, and which dependencies should be listed in the generated POM file.

To add additional artifacts to the set published, use the #artifact(Object) and #artifact(Object, org.gradle.api.Action) methods. You can also completely replace the set of published artifacts using #setArtifacts(Iterable). Together, these methods give you full control over what artifacts will be published.

To customize the metadata published in the generated POM, set properties, e.g. MavenPom#getDescription(), on the POM returned via the #getPom() method or directly by an action (or closure) passed into #pom(org.gradle.api.Action). As a last resort, it is possible to modify the generated POM using the MavenPom#withXml(org.gradle.api.Action) method.

Example of publishing a Java module with a source artifact and a customized POM
 apply plugin: "java" apply plugin: "maven-publish" task sourceJar(type: Jar) { from sourceSets.main.allJava classifier "sources" } publishing { publications { myPublication(MavenPublication) { from components.java artifact sourceJar pom { name = "Demo" description = "A demonstration of Maven POM customization" url = "http://www.example.com/project" licenses { license { name = "The Apache License, Version 2.0" url = "http://www.apache.org/licenses/LICENSE-2.0.txt" } } developers { developer { id = "johnd" name = "John Doe" email = "john.doe@example.com" } } scm { connection = "scm:svn:http://subversion.example.com/svn/project/trunk/" developerConnection = "scm:svn:https://subversion.example.com/svn/project/trunk/" url = "http://subversion.example.com/svn/project/trunk/" } } } } } 

Exceptions

InvalidMavenPublicationException

open class InvalidMavenPublicationException : InvalidUserDataException

Thrown when attempting to publish with an invalid MavenPublication.