Class MvnPublisher

All Implemented Interfaces:
Generator, Renamable, ResourceProvider

public class MvnPublisher extends AbstractGenerator

A Generator for Maven deployments in response to requests for MvnPublication or MvnInstallation. It supports publishing releases using the Publish Portal API and publishing snapshots (and local installations) using the "traditional" Maven approach (uploading the files individually, including the appropriate maven-metadata.xml files).

The publisher requests the PomFile from the project and uses the groupId, artfactId and version as specified in this file. It also requests the LibraryJarFile, the SourcesJarFile and the JavadocJarFile. The latter two are optional for snapshot releases.

Publishing requires a PGP/GPG secret key for signing the artifacts. They can be set by the respective methods. However, it is assumed that the credentials are usually made available as properties in the build context.

Except for local installs, the publisher requires at least one MvnPublishingDestination to publish to. If none is set, the publisher adds an instance of PortalPublisherDestination for releases and an instance of MvnDeployDestination with id "central" for snapshots.

  • Constructor Details

    • MvnPublisher

      public MvnPublisher(Project project)
      Initializes a new Maven publication generator.
      Parameters:
      project - the project
  • Method Details

    • destinations

      Adds the given publishing destinations.
      Parameters:
      destinations - the destinations
      Returns:
      the Maven publisher
    • destination

      public MvnPublisher destination(String id, URI uri, MvnVersionType... types)
      Create and add a MvnPublishingDestination from the given arguments.
      Parameters:
      id - the id. May be used to lookup credentials, see MvnPublishingDestination
      uri - the location
      types - the supported version types
      Returns:
      the Maven publisher
    • signWith

      public MvnPublisher signWith(String secretKeyRing, String keyId, String password)

      Use the provided information to sign the artifacts. If no information is specified, the publisher will use the BuildContext to look up the properties signing.secretKeyRingFile, signing.secretKey and signing.password.

      The publisher retrieves the secret key from the key ring using the key ID. While this method makes signing in CI/CD pipelines more complex, it is considered best practice.

      Parameters:
      secretKeyRing - the secret key ring
      keyId - the key id
      password - the password
      Returns:
      the mvn publisher
    • keepSubArtifacts

      Keep generated sub artifacts (checksums, signatures).
      Returns:
      the mvn publication generator
    • artifactDirectory

      Returns the directory where additional artifacts are created. Defaults to sub directory publications/maven in the project's build directory (see Project.buildDirectory()).
      Returns:
      the directory
    • artifactDirectory

      public MvnPublisher artifactDirectory(Path directory)
      Sets the directory where additional artifacts are created. The Path is resolved against the project's build directory (see Project.buildDirectory()). If destination is null, the additional artifacts are created in the directory where the base artifact is found.
      Parameters:
      directory - the new directory
      Returns:
      the maven publication generator
    • artifactDirectory

      Sets the directory where additional artifacts are created. If the Supplier returns null, the additional artifacts are created in the directory where the base artifact is found.
      Parameters:
      directory - the new directory
      Returns:
      the maven publication generator
    • doProvide

      protected <T extends Resource> Collection<T> doProvide(ResourceRequest<T> requested)
      Description copied from class: AbstractProvider
      Invoked by ResourceProviderSpi.provide(ResourceRequest) after checking if the invocation is allowed.
      Specified by:
      doProvide in class AbstractProvider
      Type Parameters:
      T - the generic type
      Parameters:
      requested - the request for resources
      Returns:
      the stream