|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | METHOD | DETAIL: FIELD | METHOD |
org.gradle.api.publish.maven.MavenPublication org.gradle.api.publish.Publication org.gradle.api.Named
@Incubating @HasInternalProtocol public interface MavenPublication extends 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:
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.
For any other tweaks to the publication, it is possible to modify the generated POM prior to publication. This is done using the MavenPom.withXml method of the POM returned via the getPom() method, or directly by an action (or closure) passed into pom(org.gradle.api.Action).
apply plugin: "java" apply plugin: "maven-publish" task sourceJar(type: Jar) { from sourceSets.main.allJava } publishing { publications { myPublication(MavenPublication) { from components.java artifact sourceJar { classifier "source" } pom.withXml { asNode().appendNode('description', 'A demonstration of Maven POM customization') } } } }
Method Summary | |
---|---|
MavenArtifact
|
artifact(Object source)
Creates a custom MavenArtifact to be included in the publication. |
MavenArtifact
|
artifact(Object source, Action config)
Creates an MavenArtifact to be included in the publication, which is configured by the associated action. |
void
|
from(SoftwareComponent component)
Provides the software component that should be published. |
String
|
getArtifactId()
Returns the artifactId for this publication. |
MavenArtifactSet
|
getArtifacts()
Returns the complete set of artifacts for this publication. |
String
|
getGroupId()
Returns the groupId for this publication. |
MavenPom
|
getPom()
The POM that will be published. |
String
|
getVersion()
Returns the version for this publication. |
void
|
pom(Action configure)
Configures the POM that will be published. |
void
|
setArtifactId(String artifactId)
Sets the artifactId for this publication. |
void
|
setArtifacts(Iterable sources)
Clears any previously added artifacts from getArtifacts and creates artifacts from the specified sources. |
void
|
setGroupId(String groupId)
Sets the groupId for this publication. |
void
|
setVersion(String version)
Sets the version for this publication. |
Methods inherited from interface Named | |
---|---|
getName |
Method Detail |
---|
public MavenArtifact artifact(Object source)
artifact
method can take a variety of input:
apply plugin: "maven-publish" task sourceJar(type: Jar) { classifier "source" } publishing { publications { maven(MavenPublication) { artifact sourceJar // Publish the output of the sourceJar task artifact 'my-file-name.jar' // Publish a file created outside of the build artifact source: sourceJar, classifier: 'src', extension: 'zip' } } }
source
- The source of the artifact content.
public MavenArtifact artifact(Object source, Action config)
apply plugin: "maven-publish" task sourceJar(type: Jar) { classifier "source" } publishing { publications { maven(MavenPublication) { artifact sourceJar { // These values will be used instead of the values from the task. The task values will not be updated. classifier "src" extension "zip" } artifact("my-docs-file.htm") { classifier "documentation" extension "html" } } } }
source
- The source of the artifact.config
- An action to configure the values of the constructed MavenArtifact.
public void from(SoftwareComponent component)
apply plugin: "java" apply plugin: "maven-publish" publishing { publications { maven(MavenPublication) { from components.java } } }
component
- The software component to publish.
public String getArtifactId()
public MavenArtifactSet getArtifacts()
public String getGroupId()
public MavenPom getPom()
public String getVersion()
public void pom(Action configure)
configure
- The configuration action.
public void setArtifactId(String artifactId)
public void setArtifacts(Iterable sources)
apply plugin: "java" apply plugin: "maven-publish" task sourceJar(type: Jar) { classifier "source" } publishing { publications { maven(MavenPublication) { from components.java artifacts = ["my-custom-jar.jar", sourceJar] } } }
sources
- The set of artifacts for this publication.
public void setGroupId(String groupId)
public void setVersion(String version)
Gradle API 1.12