Class MvnPublisher

All Implemented Interfaces:
Generator, ResourceProvider

public class MvnPublisher extends AbstractGenerator

A Generator for maven deployments in response to requests for MvnPublication It supports publishing releases using the Publish Portal API and publishing snapshots using the "traditional" maven approach (uploading the files, 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 credentials for the maven repository and 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.

  • Constructor Details

    • MvnPublisher

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

    • uploadUri

      public MvnPublisher uploadUri(URI uri)
      Sets the upload URI.
      Parameters:
      uri - the repository URI
      Returns:
      the maven publication generator
    • uploadUri

      public URI uploadUri()
      Returns the upload URI. Defaults to https://central.sonatype.com/api/v1/publisher/upload.
      Returns:
      the uri
    • snapshotRepository

      Sets the Maven snapshot repository URI.
      Parameters:
      uri - the snapshot repository URI
      Returns:
      the maven publication generator
    • snapshotRepository

      Returns the snapshot repository. Defaults to https://central.sonatype.com/repository/maven-snapshots/.
      Returns:
      the uri
    • credentials

      public MvnPublisher credentials(String user, String pass)
      Sets the Maven repository credentials. If not specified, the publisher looks for properties mvnrepo.user and mvnrepo.password in the properties provided by the BuildContext.
      Parameters:
      user - the username
      pass - the password
      Returns:
      the maven publication generator
    • 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
    • publishAutomatically

      Publish the release automatically.
      Returns:
      the mvn publisher
    • 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> Stream<T> doProvide(ResourceRequest<T> requested)
      Description copied from class: AbstractProvider
      Invoked by AbstractProvider.provide(ResourceRequest) after checking if the invocation is allowed.
      Specified by:
      doProvide in class AbstractProvider
      Type Parameters:
      T - the generic type
      Parameters:
      requested - the requested
      Returns:
      the stream