Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ nexusReleasePlugin {

An explicit `githubRepo` always takes priority over auto-detection.

## Combined releases

The opt-in `se.alipsa.nexus-release-all` support plugin adds manifest planning, guarded preparation, combined bundling and one-upload deployment recovery. See [the task contract and workflow](combined-releases.md). Existing single-module releases remain available.

## Building the Plugin

```bash
Expand Down
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ gradlePlugin {
website.set("https://github.com/Alipsa/nexus-release-plugin")
vcsUrl.set("https://github.com/Alipsa/nexus-release-plugin")
plugins {
combinedRelease {
id = 'se.alipsa.nexus-release-all'
implementationClass = 'se.alipsa.gradle.plugin.release.ReleaseAllSupportPlugin'
displayName = 'Combined Central Release Support'
description = 'Plans, bundles and submits multiple publications in one Central deployment'
tags.set(['publish', 'release', 'central'])
}
simplePlugin {
id = 'se.alipsa.nexus-release-plugin'
implementationClass = 'se.alipsa.gradle.plugin.release.NexusReleasePlugin'
Expand Down
98 changes: 98 additions & 0 deletions combined-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Combined release support

The opt-in `se.alipsa.nexus-release-all` support plugin registers root tasks without
registering single-publication tasks or changing `se.alipsa.nexus-release-plugin`.
The existing `bundle` and `release` tasks remain available.

Matrix provides the complete orchestration, prerequisites and command examples in
[its combined-release guide](https://github.com/Alipsa/matrix/blob/main/docs/releaseAll.md).
During development it resolves this checkout through a Gradle composite build; publishing
this plugin is a separate operation.

## Task contract

All file locations and credentials are configured explicitly through typed task properties.
The source repository must be clean and committed. Generated files belong in ignored outputs.

| Task | Inputs and behavior |
| --- | --- |
| `releaseAllPlan` | `sourceDirectory`, `configuredRevision`, `candidatesJson`, generated `candidatePoms`, static `bomPom`/`allPom`, `repositoryUrl`, `portalUrl`, `userName`, `password`, `portalFixture`; writes `manifestFile` and optional `reportFile`. Never invokes Maven or resolves Maven candidates. |
| `releaseAllSigningCheck` | `manifestFile`, `configuredSigningJson` mapping project paths to signatory availability, `strict`; reports unavailable Gradle signing or fails when strict. No signing operation. |
| `releaseAllGuard` | `sourceDirectory`, `manifestFile`, `versionsJson`; checks revision, clean tree, publication-POM hashes and Git index flags and effective publication versions before staging tasks run. |
| `releaseAllPrepareMaven` | `sourceDirectory`, `manifestFile`, `stagingDirectory`, separate `localRepository`, `mavenWorkDirectory`, `verifierFile`, `settingsHelperFile`, `stagingRepositoryId` (default `release-staging`), optional `userSettingsFile` (default `~/.m2/settings.xml`); runs the caller's verifier and Maven `install -Prelease`, never deploy. The settings helper takes source user-settings, staged repository, output-settings and repository ID; it must preserve signing settings without logging secrets. |
| `bundleAll` | `sourceDirectory`, `manifestFile`, `stagingDirectory`; writes `bundleFile` and `receiptFile`. Rechecks source, dependency POMs, metadata, artifact policy, nonempty signature files and staged checksums (signature cryptography is not verified). Generates MD5/SHA-1 for artifacts/signatures. |
| `releaseAll` | `sourceDirectory`, `manifestFile`, `bundleFile`, `receiptFile`, `recordFile`, `portalFixture`, repository/Portal URLs and credentials; `resumeId` defaults to an empty string for a new upload, or a saved deployment ID for status-only recovery. Rechecks availability and uploads once. |

The Matrix build configures these properties in `gradle/release-all.gradle`. For example,
a caller configures the bundle task after registering its own staging/preparation workflow:

```groovy
plugins { id 'se.alipsa.nexus-release-all' }

bundleAll {
sourceDirectory = layout.projectDirectory
manifestFile = layout.buildDirectory.file('releaseAll/manifest.json')
stagingDirectory = layout.buildDirectory.dir('releaseAll/staging')
bundleFile = layout.buildDirectory.file('releaseAll/bundle.zip')
receiptFile = layout.buildDirectory.file('releaseAll/bundle-receipt.json')
}
```

Run discovery in a separate invocation before configuring staging dependencies from the
saved manifest. Run source guards before staging, the caller's scoped verification before
preparation, then `bundleAll`, then `releaseAll`. Do not upload if any preceding phase fails.
The combined tasks support strict configuration-cache reuse; legacy verification tasks can
run with `--no-configuration-cache` independently.

## Manifest and publication policy

Publication descriptors preserve exact configured coordinates, expected filenames, source
project/publication or Maven POM, dependency origins, and published dependency/management
expectations. Include production compile and runtime project edges even if omitted by POMs.
Eligibility edges include candidate group/artifact pairs and groups covered by the optional
`releaseAllPlan.releaseNamespaces` list (exact namespaces and their subgroups). Third-party
dependencies remain in POM expectations but are not availability probes; test/system edges
are also excluded from eligibility. Candidate JSON requires a nonempty `files` list; omitted
`dependencies` defaults to an empty list.
All explicit non-test/system versions in published dependencies and dependency management,
including third-party dependencies and imported BOMs, must be concrete release versions.
SNAPSHOTs, version ranges, dynamic versions and unresolved expressions exclude the candidate;
these exclusions cascade to dependents. Third-party availability is still not probed.
Rejecting third-party ranges and dynamic versions is a deliberate combined-release policy
change; use concrete pins even if the repository accepts ranges in published POMs.
Dependencies whose versions come from an imported BOM can remain unspecified in the source
POM, but their flattened published versions must be concrete non-SNAPSHOT versions.
Invalid eligibility-edge versions also exclude the dependent candidate rather than aborting
planning. Unresolved source POM expressions fail static inspection before selection.
Only exact non-SNAPSHOT versions whose dependencies are released or in the final bundle are
selected. Exclusions cascade; a selected module's mismatched BOM pin blocks the new BOM.
An unselected module can retain an already-released BOM pin with a warning.

Normal JAR components require main, sources and Javadoc JARs plus POM. POM components require
only a POM. An explicitly configured `sourcesAndJavadocRequired: false` policy preserves an
aggregate JAR's existing main-JAR/POM publication set. All expected files need nonempty
signatures. No Gradle metadata, repository bookkeeping or unrelated components are copied.
Source guards hash publication POMs and require a clean, unchanged Git revision with no
assume-unchanged or skip-worktree index flags. Maven preparation requires a POSIX filesystem
and bash, groovy and mvn; Windows users must use WSL. Repository and Portal URLs default to
Maven Central and the Central Portal API.
The ZIP size limit defaults to 1,000,000,000 bytes.

Publication checks use exact repository POMs and authenticated Portal
`GET /publisher/published?namespace=groupId&name=artifactId&version=version` under the configured
Portal API base. Errors never mean absence. Confirmed, sanitized namespace/absence fixtures
are required for production absence-based discovery and new uploads; mock fixtures are only
used in tests. Availability checks retry transient failures at most three times by default.

## Interrupted deployments

The record is written as `SUBMITTING` before HTTP and stores the ID immediately on success.
Definite HTTP 401/403/422 rejections are archived beside the active record as
`*.rejected-<uuid>.json`, allowing a corrected new invocation. Other upload exceptions persist
`UPLOAD_ERROR` with diagnostics; invalid ID responses retain the raw response in `SUBMITTING`.
Never automatically retry an unknown upload outcome. Resume only the saved ID, without
source checks, builds or signing. Polling defaults to 60 attempts at 10-second intervals;
Transient I/O errors are recorded and polling continues within that bound. Availability probes use HEAD.
Central propagation remains separate from Portal publication. A failed record reports all
component coordinates. Archive an `AVAILABLE` record before a new deployment; manually
reconcile every unresolved record rather than deleting it to retry.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package se.alipsa.gradle.plugin.release

import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.*
import org.gradle.work.DisableCachingByDefault

/** Configuration-cache compatible aggregation without implicit build or upload dependencies. */
@DisableCachingByDefault(because = 'Release requires source guards')
abstract class BundleAllTask extends DefaultTask {
@InputFile @PathSensitive(PathSensitivity.NONE)
abstract RegularFileProperty getManifestFile()
@InputDirectory @PathSensitive(PathSensitivity.RELATIVE)
abstract DirectoryProperty getStagingDirectory()
@Internal
abstract DirectoryProperty getSourceDirectory()
@OutputFile
abstract RegularFileProperty getBundleFile()

@OutputFile
abstract RegularFileProperty getReceiptFile()

BundleAllTask() { outputs.upToDateWhen { false } }

/** Validates the source and all manifest artifacts and creates the combined ZIP. */
@TaskAction
void bundle() {
Map manifest = ReleaseManifest.read(manifestFile.get().asFile)
ReleaseManifest.guard(sourceDirectory.get().asFile, manifest)
CombinedBundle.create(stagingDirectory.get().asFile, bundleFile.get().asFile, manifest.selected as List<Map>)
ReleaseManifest.write(receiptFile.get().asFile, [bundleHash: ReleaseChecksums.checksum(bundleFile.get().asFile, 'SHA-256'), manifestHash: ReleaseChecksums.checksum(manifestFile.get().asFile, 'SHA-256')])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
import org.gradle.work.DisableCachingByDefault

import java.security.DigestOutputStream
import java.security.MessageDigest
import java.nio.charset.StandardCharsets
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
Expand Down Expand Up @@ -170,12 +168,7 @@ abstract class BundleTask extends DefaultTask {
}

private static String checksumFor(File file, String algo) {
def digest = MessageDigest.getInstance(algo)
file.withInputStream { is ->
new DigestOutputStream(OutputStream.nullOutputStream(), digest)
.withCloseable { dos -> is.transferTo(dos) }
}
digest.digest().encodeHex().toString()
ReleaseChecksums.checksum(file, algo)
}

private static String checksumExtension(String algo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class BundleValidator {
}

String pomText = zip.getInputStream(pomEntry).getText('UTF-8')
validatePomMetadata(pomText, expectedPomPath, errors)
}

/** Checks Central metadata for both single-publication and combined archives. */
static void validatePomMetadata(String pomText, String expectedPomPath, List<String> errors) {
GPathResult pom
try {
pom = new XmlSlurper(false, false).parseText(pomText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CentralPortalClient extends WsClient {
body = new JsonSlurper().parseText(result.get(BODY) as String) as Map
} catch (Exception e) {
String responseBody = result.get(BODY) as String
throw new GradleException("Failed to parse deployment status response for deployment ID ${deploymentId}: ${e.message}. Body: ${responseBody}")
throw new IOException("Failed to parse deployment status response for deployment ID ${deploymentId}: ${e.message}. Body: ${responseBody}", e)
}
return body as Map<String, Object>
}
Expand All @@ -97,14 +97,14 @@ class CentralPortalClient extends WsClient {
String body = e.body?.trim()
switch (e.statusCode) {
case 401:
return new GradleException("Authentication failed - check sonatypeUsername/sonatypePassword")
return new GradleException("Authentication failed - check sonatypeUsername/sonatypePassword", e)
case 403:
return new GradleException("Forbidden - is the namespace verified in your Central Portal account?")
return new GradleException("Forbidden - is the namespace verified in your Central Portal account?", e)
case 422:
return new GradleException("Rejected by Central Portal - see body for details: ${body}")
return new GradleException("Rejected by Central Portal - see body for details: ${body}", e)
default:
if (e.statusCode >= 500) {
return new GradleException("Central Portal returned ${e.statusCode} - try again later")
return new GradleException("Central Portal returned ${e.statusCode} - try again later", e)
}
return new GradleException("Upload failed with HTTP ${e.statusCode}: ${body}", e)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package se.alipsa.gradle.plugin.release

import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream

/** Builds one validated allow-listed Maven-layout archive. */
class CombinedBundle {
static final long MAX_BYTES = 1_000_000_000L

/** Validates all components before writing any ZIP entry. */
static void create(File staging, File target, List<Map> publications, long limit = MAX_BYTES) {
if (publications.empty) throw new IllegalArgumentException('Cannot bundle an empty selection')
Map<String, File> entries = [:]
Map<String, Map<String, String>> checksums = [:]
publications.each { Map publication ->
def coordinate = new ReleaseCoordinate(publication.groupId, publication.artifactId, publication.version)
coordinate.validate()
String prefix = "${coordinate.artifactId}-${coordinate.version}"
List<String> required = ["${prefix}.pom".toString()]
if (publication.packaging != 'pom') {
required.add("${prefix}.jar".toString())
if (publication.sourcesAndJavadocRequired != false) required.addAll(["${prefix}-sources.jar".toString(), "${prefix}-javadoc.jar".toString()])
}
if (!(publication.files as Set).containsAll(required)) throw new IllegalArgumentException('Manifest omits required publication artifacts')
publication.files.each { String name ->
if (!(name ==~ /[A-Za-z0-9_.+-]+/) || !name.startsWith(prefix) || !(name.endsWith('.jar') || name.endsWith('.pom'))) {
throw new IllegalArgumentException('Unsafe or unsupported artifact filename')
}
String path = "${coordinate.path()}/${name}"
[path, path + '.asc'].each { String entry ->
File source = new File(staging, entry)
if (!source.isFile() || source.length() == 0 || java.nio.file.Files.isSymbolicLink(source.toPath()) || !source.canonicalPath.startsWith(staging.canonicalPath + File.separator)) {
throw new IllegalArgumentException("Missing or unsafe release artifact: ${entry}")
}
if (entries.put(entry, source) != null) throw new IllegalArgumentException("Duplicate release path: ${entry}")
checksums[entry] = [:]
['MD5', 'SHA-1'].each { String algorithm ->
File checksum = new File(source.path + '.' + algorithm.toLowerCase().replace('-', ''))
String hash = ReleaseChecksums.checksum(source, algorithm)
checksums[entry][algorithm] = hash
if (checksum.exists() && checksum.text.trim().split(/\s+/)[0].toLowerCase(Locale.ROOT) != hash) throw new IllegalArgumentException("Incorrect checksum for ${entry}")
}
}
}
File pomFile = new File(staging, "${coordinate.path()}/${prefix}.pom")
ReleasePom.compare(pomFile, publication)
List<String> metadataErrors = []
BundleValidator.validatePomMetadata(pomFile.getText('UTF-8'), coordinate.key(), metadataErrors)
if (!metadataErrors.empty) throw new IllegalArgumentException(metadataErrors.join('; '))
}
target.parentFile.mkdirs()
File temporary = java.nio.file.Files.createTempFile(target.absoluteFile.parentFile.toPath(), target.name + '.', '.tmp').toFile()
try {
temporary.withOutputStream { output ->
OutputStream bounded = new FilterOutputStream(output) {
long bytesWritten = 0
@Override void write(int value) {
if (++bytesWritten > limit) throw new IllegalArgumentException('ZIP exceeds bundle limit')
output.write(value)
}
@Override void write(byte[] bytes, int offset, int length) {
bytesWritten += length
if (bytesWritten > limit) throw new IllegalArgumentException('ZIP exceeds bundle limit')
output.write(bytes, offset, length)
}
}
new ZipOutputStream(bounded).withCloseable { zip ->
entries.sort().each { String path, File source ->
zip.putNextEntry(new ZipEntry(path)); source.withInputStream { it.transferTo(zip) }; zip.closeEntry()
['MD5', 'SHA-1'].each { String algorithm ->
zip.putNextEntry(new ZipEntry(path + '.' + algorithm.toLowerCase().replace('-', '')))
zip.write(checksums[path][algorithm].getBytes('UTF-8')); zip.closeEntry()
}
}
}
}
if (temporary.length() > limit) throw new IllegalArgumentException('ZIP exceeds bundle limit')
java.nio.file.Files.move(temporary.toPath(), target.toPath(), java.nio.file.StandardCopyOption.ATOMIC_MOVE, java.nio.file.StandardCopyOption.REPLACE_EXISTING)
} finally { temporary.delete() }
}
}
Loading
Loading