Interface MavenPublication
-
- All Superinterfaces:
Named
,Publication
public interface MavenPublication extends Publication
AMavenPublication
is the representation/configuration of how Gradle should publish something in Maven format. You directly add a named Maven publication the project'spublishing.publications
container by providingMavenPublication
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)
andartifact(Object, org.gradle.api.Action)
methods. You can also completely replace the set of published artifacts usingsetArtifacts(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 thegetPom()
method or directly by an action (or closure) passed intopom(org.gradle.api.Action)
. As a last resort, it is possible to modify the generated POM using theMavenPom.withXml(org.gradle.api.Action)
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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.gradle.api.Named
Named.Namer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description MavenArtifact
artifact(java.lang.Object source)
Creates a customMavenArtifact
to be included in the publication.MavenArtifact
artifact(java.lang.Object source, Action<? super MavenArtifact> config)
Creates anMavenArtifact
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.java.lang.String
getArtifactId()
Returns the artifactId for this publication.MavenArtifactSet
getArtifacts()
Returns the complete set of artifacts for this publication.java.lang.String
getGroupId()
Returns the groupId for this publication.MavenPom
getPom()
The POM that will be published.java.lang.String
getVersion()
Returns the version for this publication.void
pom(Action<? super MavenPom> configure)
Configures the POM that will be published.void
setArtifactId(java.lang.String artifactId)
Sets the artifactId for this publication.void
setArtifacts(java.lang.Iterable<?> sources)
Clears any previously added artifacts fromgetArtifacts()
and creates artifacts from the specified sources.void
setGroupId(java.lang.String groupId)
Sets the groupId for this publication.void
setVersion(java.lang.String version)
Sets the version for this publication.void
suppressAllPomMetadataWarnings()
Silences all the compatibility warnings for the Maven publication.void
suppressPomMetadataWarningsFor(java.lang.String variantName)
Silences the compatibility warnings for the Maven publication for the specified variant.void
versionMapping(Action<? super VersionMappingStrategy> configureAction)
Configures the version mapping strategy.-
Methods inherited from interface org.gradle.api.publish.Publication
withBuildIdentifier, withoutBuildIdentifier
-
-
-
-
Method Detail
-
getPom
MavenPom getPom()
The POM that will be published.- Returns:
- The POM that will be published.
-
pom
void pom(Action<? super MavenPom> configure)
Configures the POM that will be published. The supplied action will be executed against thegetPom()
result. This method also accepts a closure argument, by type coercion.- Parameters:
configure
- The configuration action.
-
from
void from(SoftwareComponent component)
Provides the software component that should be published.- Any artifacts declared by the component will be included in the publication.
- The dependencies declared by the component will be included in the published meta-data.
plugins { id 'java' id 'maven-publish' } publishing { publications { maven(MavenPublication) { from components.java } } }
- Parameters:
component
- The software component to publish.
-
artifact
MavenArtifact artifact(java.lang.Object source)
Creates a customMavenArtifact
to be included in the publication. Theartifact
method can take a variety of input:- A
PublishArtifact
instance. Extension and classifier values are taken from the wrapped instance. - An
AbstractArchiveTask
instance. Extension and classifier values are taken from the wrapped instance. - Anything that can be resolved to a
File
via theProject.file(Object)
method. Extension and classifier values are interpolated from the file name. - A
Map
that contains a 'source' entry that can be resolved as any of the other input types, including file. This map can contain a 'classifier' and an 'extension' entry to further configure the constructed artifact.
plugins { id 'maven-publish' } task sourceJar(type: Jar) { archiveClassifier = "sources" } 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' } } }
- Parameters:
source
- The source of the artifact content.
- A
-
artifact
MavenArtifact artifact(java.lang.Object source, Action<? super MavenArtifact> config)
Creates anMavenArtifact
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 perartifact(Object)
. The createdMavenArtifact
is then configured using the supplied action, which can override the extension or classifier of the artifact. This method also accepts the configure action as a closure argument, by type coercion.plugins { id 'maven-publish' } task sourceJar(type: Jar) { archiveClassifier = "sources" } 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" } } } }
- Parameters:
source
- The source of the artifact.config
- An action to configure the values of the constructedMavenArtifact
.
-
setArtifacts
void setArtifacts(java.lang.Iterable<?> sources)
Clears any previously added artifacts fromgetArtifacts()
and creates artifacts from the specified sources. Each supplied source is interpreted as perartifact(Object)
. For example, to exclude the dependencies declared by a component and instead use a custom set of artifacts:plugins { id 'java' id 'maven-publish' } task sourceJar(type: Jar) { archiveClassifier = "sources" } publishing { publications { maven(MavenPublication) { from components.java artifacts = ["my-custom-jar.jar", sourceJar] } } }
- Parameters:
sources
- The set of artifacts for this publication.
-
getArtifacts
MavenArtifactSet getArtifacts()
Returns the complete set of artifacts for this publication.- Returns:
- the artifacts.
-
getGroupId
java.lang.String getGroupId()
Returns the groupId for this publication.
-
setGroupId
void setGroupId(java.lang.String groupId)
Sets the groupId for this publication.
-
getArtifactId
java.lang.String getArtifactId()
Returns the artifactId for this publication.
-
setArtifactId
void setArtifactId(java.lang.String artifactId)
Sets the artifactId for this publication.
-
getVersion
java.lang.String getVersion()
Returns the version for this publication.
-
setVersion
void setVersion(java.lang.String version)
Sets the version for this publication.
-
versionMapping
void versionMapping(Action<? super VersionMappingStrategy> configureAction)
Configures the version mapping strategy. For example, to use resolved versions for runtime dependencies:plugins { id 'java' id 'maven-publish' } publishing { publications { maven(MavenPublication) { from components.java versionMapping { usage('java-runtime'){ fromResolutionResult() } } } } }
- Parameters:
configureAction
- the configuration- Since:
- 5.2
-
suppressPomMetadataWarningsFor
void suppressPomMetadataWarningsFor(java.lang.String variantName)
Silences the compatibility warnings for the Maven publication for the specified variant. Warnings are emitted when Gradle features are used that cannot be mapped completely to Maven POM.- Parameters:
variantName
- the variant to silence warning for- Since:
- 6.0
-
suppressAllPomMetadataWarnings
void suppressAllPomMetadataWarnings()
Silences all the compatibility warnings for the Maven publication. Warnings are emitted when Gradle features are used that cannot be mapped completely to Maven POM.- Since:
- 6.0
-
-