# MavenPublication

interface MavenPublication : Publication(source)

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

Content copied to clipboard
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. 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 and artifact methods. You can also completely replace the set of published artifacts using setArtifacts. 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. getDescription, on the POM returned via the getPom method or directly by an action (or closure) passed into pom. As a last resort, it is possible to modify the generated POM using the withXml method.

    // Example of publishing a Java module with a source artifact and a customized POM
    plugins {
        id 'java'
        id 'maven-publish'
    }

    task sourceJar(type: Jar) {
      from sourceSets.main.allJava
      archiveClassifier = "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/"
            }
          }
        }
      }
    }

Content copied to clipboard

#### Since

1.4

## Functions

artifact
Link copied to clipboard
abstract fun artifact(source: Any): MavenArtifact
Creates a custom MavenArtifact to be included in the publication.
abstract fun artifact(source: Any, config: Action<in MavenArtifact>): MavenArtifact
Creates an MavenArtifact to be included in the publication, which is configured by the associated action.
from
Link copied to clipboard
abstract fun from(component: SoftwareComponent)
Provides the software component that should be published.
getArtifactId
Link copied to clipboard
abstract fun getArtifactId(): String
Returns the artifactId for this publication.
getArtifacts
Link copied to clipboard
abstract fun getArtifacts(): MavenArtifactSet
Returns the complete set of artifacts for this publication.
getGroupId
Link copied to clipboard
abstract fun getGroupId(): String
Returns the groupId for this publication.
getName
Link copied to clipboard
abstract fun getName(): String
The object's name.
getPom
Link copied to clipboard
abstract fun getPom(): MavenPom
The POM that will be published.
getVersion
Link copied to clipboard
abstract fun getVersion(): String
Returns the version for this publication.
pom
Link copied to clipboard
abstract fun pom(configure: Action<in MavenPom>)
Configures the POM that will be published.
setArtifactId
Link copied to clipboard
abstract fun setArtifactId(artifactId: String)
Sets the artifactId for this publication.
setArtifacts
Link copied to clipboard
abstract fun setArtifacts(sources: Iterable<out Any>)
Clears any previously added artifacts from getArtifacts and creates artifacts from the specified sources.
setGroupId
Link copied to clipboard
abstract fun setGroupId(groupId: String)
Sets the groupId for this publication.
setVersion
Link copied to clipboard
abstract fun setVersion(version: String)
Sets the version for this publication.
suppressAllPomMetadataWarnings
Link copied to clipboard
abstract fun suppressAllPomMetadataWarnings()
Silences all the compatibility warnings for the Maven publication.
suppressPomMetadataWarningsFor
Link copied to clipboard
abstract fun suppressPomMetadataWarningsFor(variantName: String)
Silences the compatibility warnings for the Maven publication for the specified variant.
versionMapping
Link copied to clipboard
abstract fun versionMapping(configureAction: Action<in VersionMappingStrategy>)
Configures the version mapping strategy.
withBuildIdentifier
Link copied to clipboard
abstract fun withBuildIdentifier()
Enables publication of a unique build identifier in Gradle Module Metadata.
withoutBuildIdentifier
Link copied to clipboard
abstract fun withoutBuildIdentifier()
Disables publication of a unique build identifier in Gradle Module Metadata.