diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd36d383..f564d8a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,8 +35,8 @@ jobs: - name: Build and test run: ./gradlew build -PskipSigning=true --stacktrace - - name: Assert the default graph has no assurance/benchmark/removed-provider edge - run: ./gradlew verifyDefaultModuleSurface verifyNoBuiltinProfileDefine --stacktrace + - name: Assert module boundaries and release POMs have no -SNAPSHOT dependencies + run: ./gradlew verifyDefaultModuleSurface verifyNoBuiltinProfileDefine verifyNoSnapshotDependenciesInReleasePoms -PskipSigning=true --stacktrace - name: Upload test reports if: always() diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0eed60f9..ef390b47 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -113,6 +113,10 @@ jobs: echo "Version $VERSION (final: $IS_FINAL), Maven Central: $MAVEN_CENTRAL_PUBLISH," \ "BloxBean repository: $BLOXBEAN_REPO_PUBLISH, GitHub release: ${GITHUB_RELEASE:-false}" + - name: Assert release POMs and classpaths contain no -SNAPSHOT dependencies + if: github.ref_type == 'tag' + run: ./gradlew verifyNoSnapshotDependenciesInReleasePoms -PrequireNoSnapshotDependencies=true -PskipSigning=true --stacktrace + # ================================================================ # Stage 1: Build libblst from source for every supported platform # (pinned tag in zeroj-blst/scripts/build-blst.sh) so released jars @@ -268,8 +272,8 @@ jobs: - name: Build and test run: ./gradlew build --stacktrace - - name: Assert the default graph has no assurance/benchmark/removed-provider edge - run: ./gradlew verifyDefaultModuleSurface verifyNoBuiltinProfileDefine --stacktrace + - name: Assert module boundaries and release POMs have no -SNAPSHOT dependencies + run: ./gradlew verifyDefaultModuleSurface verifyNoBuiltinProfileDefine verifyNoSnapshotDependenciesInReleasePoms -PrequireNoSnapshotDependencies=true --stacktrace # Learns the artifactIds this build owns; unsigned, its staged files are discarded. - name: Discover the Maven publications diff --git a/build.gradle b/build.gradle index a54bccff..a6b8a336 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,10 @@ plugins { allprojects { repositories { mavenCentral() - mavenLocal() + // Opt-in only: keep default builds and releases isolated from locally published ~/.m2 artifacts. + if (rootProject.providers.gradleProperty('useMavenLocal').map { it.equalsIgnoreCase('true') }.getOrElse(false)) { + mavenLocal() + } maven { url = uri("https://central.sonatype.com/repository/maven-snapshots") content { @@ -274,6 +277,246 @@ tasks.matching { dependsOn 'verifyMavenReleasePublicationScope' } +// === Release -SNAPSHOT dependency guard ========================================================= +// Fails any non-SNAPSHOT release (or any run with -PrequireNoSnapshotDependencies=true) if a +// published Maven POM, resolved compile/runtime/annotationProcessor classpath, or buildscript +// plugin classpath references a Maven snapshot artifact (including timestamped snapshots or +// property-interpolated / unresolved version expressions). +def verifyNoSnapshotDeps = tasks.register('verifyNoSnapshotDependenciesInReleasePoms') { + group = 'verification' + description = 'Asserts published release POMs and resolved release classpaths contain no -SNAPSHOT dependencies.' + + def forceCheck = providers.gradleProperty('requireNoSnapshotDependencies') + .map { it.equalsIgnoreCase('true') } + .getOrElse(false) + def deployedProjects = centralDeploymentProjects + + doLast { + // Matches org.apache.maven.artifact.ArtifactUtils.isSnapshot (Maven 3.9.9): + // case-insensitive terminal "SNAPSHOT" (with or without leading hyphen) or + // timestamped "-YYYYMMDD.HHMMSS-". + def snapSuffix = 'SNAPSHOT' + def timestampedSnapshotPattern = ~/^(.*)-([0-9]{8}\.[0-9]{6})-([0-9]+)$/ + def isMavenSnapshot = { String ver -> + ver != null && !ver.isEmpty() && ( + (ver.length() >= snapSuffix.length() + && ver.regionMatches(true, ver.length() - snapSuffix.length(), snapSuffix, 0, snapSuffix.length())) + || timestampedSnapshotPattern.matcher(ver).matches()) + } + + def resolvePomProperties = { String raw, Map props -> + if (raw == null) return null + String current = raw.trim() + // Bounded expansion to handle chained properties without looping on cycles. + for (int depth = 0; depth < 8 && current.contains('${'); depth++) { + String next = current.replaceAll(/\$\{([^}]+)\}/) { match, key -> + props.containsKey(key) ? java.util.regex.Matcher.quoteReplacement(props[key]) : java.util.regex.Matcher.quoteReplacement(match) + } + if (next == current) break + current = next + } + return current + } + + def findSnapshotVersionsInPom = { String xmlText, String sourceLabel -> + def hits = [] + def pom = new groovy.xml.XmlSlurper(false, false).parseText(xmlText) + Map props = new LinkedHashMap<>() + pom.properties.children().each { prop -> + props[prop.name()] = prop.text().trim() + } + String parentVer = pom.parent.size() > 0 ? pom.parent.version?.text()?.trim() : null + String projectVer = pom.version?.text()?.trim() + if (parentVer) { + props['project.parent.version'] = parentVer + props['parent.version'] = parentVer + } + String effectiveProjectVer = projectVer ?: parentVer + if (effectiveProjectVer) { + props['project.version'] = effectiveProjectVer + props['version'] = effectiveProjectVer + } + + def checkVersion = { String coord, String rawVer -> + if (rawVer == null || rawVer.isEmpty()) return + String resolved = resolvePomProperties(rawVer, props) + if (resolved.contains('${')) { + hits << "${sourceLabel}: ${coord} -> unresolved version expression '${rawVer}' (resolved: '${resolved}')" + } else if (isMavenSnapshot(resolved)) { + hits << "${sourceLabel}: ${coord} -> ${resolved}" + (resolved != rawVer ? " (from ${rawVer})" : '') + } + } + checkVersion('project', effectiveProjectVer) + if (pom.parent.size() > 0) { + def parentCoord = "${pom.parent.groupId.text().trim()}:${pom.parent.artifactId.text().trim()}" + checkVersion("parent ${parentCoord}", parentVer) + } + def inspectDeps = { depsNode, String section -> + depsNode.dependency.each { dep -> + def coord = "${dep.groupId.text().trim()}:${dep.artifactId.text().trim()}" + checkVersion("${section} ${coord}", dep.version?.text()?.trim()) + } + } + inspectDeps(pom.dependencies, 'dependency') + inspectDeps(pom.dependencyManagement.dependencies, 'dependencyManagement') + return hits + } + + // Self-check the POM scanner so a parser regression cannot turn this guard into a silent no-op. + def badDepPom = ''' + org.zerojsample0.1.0 + org.julclangjulc-stdlib0.1.0-pre21-SNAPSHOT + ''' + def badTimestampedPom = ''' + org.zerojsample0.1.0 + org.julclangjulc-stdlib0.1.0-20261120.174000-1 + ''' + def badLowercaseSnapPom = ''' + org.zerojsample0.1.0 + org.julclangjulc-stdlib1.0-snapshot + ''' + def badNoHyphenSnapPom = ''' + org.zerojsample0.1.0 + org.julclangjulc-stdlib1.0SNAPSHOT + ''' + def badBomPropPom = ''' + org.zerojsample-bom0.1.0 + 0.1.0-SNAPSHOT + org.julclangjulc-stdlib${julc.ver} + ''' + def badUnresolvedPropPom = ''' + org.zerojsample-bom0.1.0 + org.julclangjulc-stdlib${missing.ver} + ''' + def badParentPom = ''' + org.exampleparent1.0-SNAPSHOT + org.zerojsample0.1.0 + ''' + def cleanPom = ''' + org.zerojsample0.1.0-pre13 + 0.1.0-pre22 + + org.julclangjulc-stdlib${julc.ver} + org.examplenon-snapshot-qualifier1.0.0-snapshotter + + ''' + if (findSnapshotVersionsInPom(badDepPom, 'self-check').isEmpty() + || findSnapshotVersionsInPom(badTimestampedPom, 'self-check').isEmpty() + || findSnapshotVersionsInPom(badLowercaseSnapPom, 'self-check').isEmpty() + || findSnapshotVersionsInPom(badNoHyphenSnapPom, 'self-check').isEmpty() + || findSnapshotVersionsInPom(badBomPropPom, 'self-check').isEmpty() + || findSnapshotVersionsInPom(badUnresolvedPropPom, 'self-check').isEmpty() + || findSnapshotVersionsInPom(badParentPom, 'self-check').isEmpty() + || !findSnapshotVersionsInPom(cleanPom, 'self-check').isEmpty()) { + throw new GradleException('Release -SNAPSHOT POM guard self-check failed.') + } + + // Only skip automatically for the build's own intentional development snapshot mode + // (`*-SNAPSHOT`, matching subprojects version rewriting and snapshot.yml). Any other + // Maven-snapshot version (e.g. lowercase `-snapshot` or timestamped) is treated as a + // release by the rest of the build and must therefore run and fail this guard. + def rootVersion = rootProject.version.toString() + def isDevSnapshotProject = rootVersion.endsWith('-SNAPSHOT') + if (isDevSnapshotProject && !forceCheck) { + logger.lifecycle("Skipping release -SNAPSHOT dependency guard for development SNAPSHOT version ${rootVersion}.") + return + } + + def violations = [] + int pomCount = 0 + int configCount = 0 + + if (isMavenSnapshot(rootVersion)) { + violations << "rootProject version is SNAPSHOT: ${rootVersion}" + } + + def scanConfiguration = { Configuration cfg, String label -> + if (cfg != null && cfg.canBeResolved) { + configCount++ + def result = cfg.incoming.resolutionResult + result.allDependencies.each { dep -> + if (dep instanceof org.gradle.api.artifacts.result.UnresolvedDependencyResult) { + violations << "${label}: unresolved dependency ${dep.requested} (${dep.failure.message})" + } + } + result.allComponents.each { comp -> + def mv = comp.moduleVersion + if (mv != null && isMavenSnapshot(mv.version)) { + violations << "${label}: ${mv.group}:${mv.name}:${mv.version}" + } + } + } + } + + deployedProjects.each { candidate -> + def pomTasks = candidate.tasks.withType(GenerateMavenPom).toList() + if (pomTasks.isEmpty()) { + violations << "${candidate.path}: declares no GenerateMavenPom task" + } + pomTasks.each { pomTask -> + File pomFile = pomTask.destination + if (!pomFile.isFile()) { + violations << "${candidate.path}: expected generated POM missing at ${pomFile}" + } else { + pomCount++ + violations.addAll(findSnapshotVersionsInPom( + pomFile.getText('UTF-8'), + "${candidate.path} (${pomFile.name})")) + } + } + + ['compileClasspath', 'runtimeClasspath', 'annotationProcessor'].each { cfgName -> + scanConfiguration(candidate.configurations.findByName(cfgName), "${candidate.path} [${cfgName}]") + } + // Note: covers buildscript { dependencies { classpath ... } } plugins (e.g. julc-gradle-plugin). + // Plugins resolved via settings pluginManagement / plugins {} blocks live on the settings + // classpath rather than project.buildscript and are pinned directly in plugin blocks. + scanConfiguration(candidate.buildscript.configurations.findByName('classpath'), + "${candidate.path} [buildscript:classpath]") + } + + scanConfiguration(rootProject.buildscript.configurations.findByName('classpath'), + ': [buildscript:classpath]') + + if (pomCount < deployedProjects.size()) { + violations << "Scanned only ${pomCount} POMs across ${deployedProjects.size()} published projects" + } + + if (!violations.isEmpty()) { + throw new GradleException( + "Release publications must not depend on -SNAPSHOT artifacts:\n - " + + violations.unique().sort().join('\n - ')) + } + logger.lifecycle( + "Release -SNAPSHOT dependency guard passed: ${pomCount} published POMs and ${configCount} resolved classpaths clean.") + } +} + +gradle.projectsEvaluated { + verifyNoSnapshotDeps.configure { task -> + centralDeploymentProjects.each { candidate -> + task.dependsOn(candidate.tasks.withType(GenerateMavenPom)) + } + } +} + +tasks.named('check') { dependsOn verifyNoSnapshotDeps } +tasks.matching { + it.name in ['nmcpZipAggregation', 'nmcpPublishAggregationToCentralPortal'] +}.configureEach { + dependsOn verifyNoSnapshotDeps +} +allprojects { candidate -> + candidate.tasks.matching { it.name == 'publishAllPublicationsToStagingRepository' }.configureEach { + dependsOn verifyNoSnapshotDeps + } + candidate.tasks.withType(PublishToMavenRepository).configureEach { publishTask -> + if (publishTask.name.endsWith('ToStagingRepository') || publishTask.repository?.name == 'staging') { + publishTask.dependsOn verifyNoSnapshotDeps + } + } +} + // === ADR-0044 structural guard ================================================================= // Asserts that the default (stable) product graph never gains an edge to an assurance, benchmark, // incubator, or removed module, and that the boundaries the ADR keeps apart stay apart. Runs in CI, diff --git a/www/src/content/docs/reference/configuration.md b/www/src/content/docs/reference/configuration.md index 4f39e501..5eed054c 100644 --- a/www/src/content/docs/reference/configuration.md +++ b/www/src/content/docs/reference/configuration.md @@ -144,6 +144,8 @@ These only matter when you build the ZeroJ repository itself. Use the Gradle wra | `-PrequireSnarkjs` | Makes the snarkjs interop suites in `zeroj-integration-tests` **fail** instead of skip when snarkjs 0.7.6 is missing (sets `zeroj.assurance.requireSnarkjs=true`) | | `./gradlew :zeroj-integration-tests:e2eTest` | Runs `@Tag("e2e")` tests: Yaci DevKit on-chain flows and snarkjs proving. They skip gracefully when Yaci DevKit (`localhost:8080`) or snarkjs is absent. | | `./gradlew verifyDefaultModuleSurface` | Checks the stable module graph has no edge into assurance, benchmark or removed modules | +| `./gradlew verifyNoSnapshotDependenciesInReleasePoms` | Fails non-SNAPSHOT builds (or any run with `-PrequireNoSnapshotDependencies=true`) if any published POM or resolved classpath references a `-SNAPSHOT` dependency | +| `-PuseMavenLocal=true` | Opt-in local `~/.m2` repository lookup (off by default so builds and releases stay isolated from local Maven installs) | ```bash ./gradlew -PincludeAssurance :zeroj-bls12381-wasm:test :zeroj-bbs-wasm:test :zeroj-bbs:test