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.
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/" } } } } }
Since
1.4
abstract fun artifact(source: Any): MavenArtifact
Creates a custom MavenArtifact to be included in the publication. The
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. The first parameter is used to create a custom artifact and add it to the publication, as per
|
|
abstract fun from(component: SoftwareComponent): Unit
Provides the software component that should be published.
|
|
abstract fun getArtifactId(): String
Returns the artifactId for this publication. |
|
abstract fun getArtifacts(): MavenArtifactSet
Returns the complete set of artifacts for this publication. |
|
abstract fun getGroupId(): String
Returns the groupId for this publication. |
|
abstract fun getPom(): MavenPom
The POM that will be published. |
|
abstract fun getVersion(): String
Returns the version for this publication. |
|
abstract fun pom(configure: Action<in MavenPom>): Unit
Configures the POM that will be published. The supplied action will be executed against the |
|
abstract fun setArtifactId(artifactId: String): Unit
Sets the artifactId for this publication. |
|
abstract fun setArtifacts(sources: MutableIterable<*>): Unit
Clears any previously added artifacts from
|
|
abstract fun setGroupId(groupId: String): Unit
Sets the groupId for this publication. |
|
abstract fun setVersion(version: String): Unit
Sets the version for this publication. |