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: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
245 changes: 244 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 "<base>-YYYYMMDD.HHMMSS-<build>".
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<String, String> 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<String, String> 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 = '''<project xmlns="http://maven.apache.org/POM/4.0.0">
<groupId>org.zeroj</groupId><artifactId>sample</artifactId><version>0.1.0</version>
<dependencies><dependency><groupId>org.julclang</groupId><artifactId>julc-stdlib</artifactId><version>0.1.0-pre21-SNAPSHOT</version></dependency></dependencies>
</project>'''
def badTimestampedPom = '''<project xmlns="http://maven.apache.org/POM/4.0.0">
<groupId>org.zeroj</groupId><artifactId>sample</artifactId><version>0.1.0</version>
<dependencies><dependency><groupId>org.julclang</groupId><artifactId>julc-stdlib</artifactId><version>0.1.0-20261120.174000-1</version></dependency></dependencies>
</project>'''
def badLowercaseSnapPom = '''<project xmlns="http://maven.apache.org/POM/4.0.0">
<groupId>org.zeroj</groupId><artifactId>sample</artifactId><version>0.1.0</version>
<dependencies><dependency><groupId>org.julclang</groupId><artifactId>julc-stdlib</artifactId><version>1.0-snapshot</version></dependency></dependencies>
</project>'''
def badNoHyphenSnapPom = '''<project xmlns="http://maven.apache.org/POM/4.0.0">
<groupId>org.zeroj</groupId><artifactId>sample</artifactId><version>0.1.0</version>
<dependencies><dependency><groupId>org.julclang</groupId><artifactId>julc-stdlib</artifactId><version>1.0SNAPSHOT</version></dependency></dependencies>
</project>'''
def badBomPropPom = '''<project xmlns="http://maven.apache.org/POM/4.0.0">
<groupId>org.zeroj</groupId><artifactId>sample-bom</artifactId><version>0.1.0</version>
<properties><julc.ver>0.1.0-SNAPSHOT</julc.ver></properties>
<dependencyManagement><dependencies><dependency><groupId>org.julclang</groupId><artifactId>julc-stdlib</artifactId><version>${julc.ver}</version></dependency></dependencies></dependencyManagement>
</project>'''
def badUnresolvedPropPom = '''<project xmlns="http://maven.apache.org/POM/4.0.0">
<groupId>org.zeroj</groupId><artifactId>sample-bom</artifactId><version>0.1.0</version>
<dependencyManagement><dependencies><dependency><groupId>org.julclang</groupId><artifactId>julc-stdlib</artifactId><version>${missing.ver}</version></dependency></dependencies></dependencyManagement>
</project>'''
def badParentPom = '''<project xmlns="http://maven.apache.org/POM/4.0.0">
<parent><groupId>org.example</groupId><artifactId>parent</artifactId><version>1.0-SNAPSHOT</version></parent>
<groupId>org.zeroj</groupId><artifactId>sample</artifactId><version>0.1.0</version>
</project>'''
def cleanPom = '''<project xmlns="http://maven.apache.org/POM/4.0.0">
<groupId>org.zeroj</groupId><artifactId>sample</artifactId><version>0.1.0-pre13</version>
<properties><julc.ver>0.1.0-pre22</julc.ver></properties>
<dependencies>
<dependency><groupId>org.julclang</groupId><artifactId>julc-stdlib</artifactId><version>${julc.ver}</version></dependency>
<dependency><groupId>org.example</groupId><artifactId>non-snapshot-qualifier</artifactId><version>1.0.0-snapshotter</version></dependency>
</dependencies>
</project>'''
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,
Expand Down
2 changes: 2 additions & 0 deletions www/src/content/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading