MavenPublication

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

Since

1.4

Functions

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.
Link copied to clipboard
abstract fun from(component: SoftwareComponent)
Provides the software component that should be published.
Link copied to clipboard
abstract fun getArtifactId(): String
Returns the artifactId for this publication.
Link copied to clipboard
Returns the complete set of artifacts for this publication.
Link copied to clipboard
abstract fun getGroupId(): String
Returns the groupId for this publication.
Link copied to clipboard
abstract fun getName(): String
Link copied to clipboard
abstract fun getPom(): MavenPom
The POM that will be published.
Link copied to clipboard
abstract fun getVersion(): String
Returns the version for this publication.
Link copied to clipboard
abstract fun pom(configure: Action<in MavenPom>)
Configures the POM that will be published.
Link copied to clipboard
abstract fun setArtifactId(artifactId: String)
Sets the artifactId for this publication.
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.
Link copied to clipboard
abstract fun setGroupId(groupId: String)
Sets the groupId for this publication.
Link copied to clipboard
abstract fun setVersion(version: String)
Sets the version for this publication.
Link copied to clipboard
Silences all the compatibility warnings for the Maven publication.
Link copied to clipboard
abstract fun suppressPomMetadataWarningsFor(variantName: String)
Silences the compatibility warnings for the Maven publication for the specified variant.
Link copied to clipboard
abstract fun versionMapping(configureAction: Action<in VersionMappingStrategy>)
Configures the version mapping strategy.
Link copied to clipboard
abstract fun withBuildIdentifier()
Link copied to clipboard
abstract fun withoutBuildIdentifier()