api / org.gradle.api.publish.maven

Package org.gradle.api.publish.maven



interface MavenArtifact : PublicationArtifact

An artifact published as part of a MavenPublication.


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" }) 


interface MavenDependency

A dependency declared as part of an MavenPublication.


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.


interface MavenPomCiManagement

The CI management system of a Maven publication.


interface MavenPomContributor

A contributor of a Maven publication.


interface MavenPomContributorSpec

Allows to add contributors of a Maven publication.


interface MavenPomDeveloper

A developer of a Maven publication.


interface MavenPomDeveloperSpec

Allows to add developers to a Maven publication.


interface MavenPomDistributionManagement

The distribution management configuration of a Maven publication.


interface MavenPomIssueManagement

The issue management system of a Maven publication.


interface MavenPomLicense

A license of a Maven publication.


interface MavenPomLicenseSpec

Allows to add licenses to a Maven publication.


interface MavenPomMailingList

A mailing list of a Maven publication.


interface MavenPomMailingListSpec

Allows to add mailing lists to a Maven publication.


interface MavenPomOrganization

The organization of a Maven publication.


interface MavenPomRelocation

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


interface MavenPomScm

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


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/" } } } } } 



open class InvalidMavenPublicationException : InvalidUserDataException

Thrown when attempting to publish with an invalid MavenPublication.