Skip to content

fix: Use nisse-gradle-plugin#2464

Merged
maxandersen merged 7 commits into
jbangdev:mainfrom
cstamas:nisse-gradle-plugin
May 17, 2026
Merged

fix: Use nisse-gradle-plugin#2464
maxandersen merged 7 commits into
jbangdev:mainfrom
cstamas:nisse-gradle-plugin

Conversation

@cstamas
Copy link
Copy Markdown
Contributor

@cstamas cstamas commented May 15, 2026

Just to experiment.

To make it work, locally:

Summary by CodeRabbit

  • Chores

    • CI workflows updated to fetch full git history for checkout
    • Switched project versioning to a new JGit-based plugin and updated release tagging behavior
    • Configured plugin resolution to support the new versioning plugin
    • Packaging and build tasks adjusted for lazy version evaluation
    • Manifest generation enhanced with additional metadata and runtime version injection
    • Added a task to print the computed project version
  • Tests

    • Added tests validating build version and manifest version consistency

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b59a4b7e-1ccc-41ea-a5db-ee0a0fc10193

📥 Commits

Reviewing files that changed from the base of the PR and between 07e07e0 and acb82d8.

📒 Files selected for processing (1)
  • settings.gradle
🚧 Files skipped from review as they are similar to previous changes (1)
  • settings.gradle

📝 Walkthrough

Walkthrough

This PR migrates JBang's build versioning from the git-versioner plugin to the nisse JGit counting plugin. CI workflows are updated to fetch full git history, plugin infrastructure is configured in settings.gradle and build.gradle, version computation is set up with nisseConfig and afterEvaluate hooks, JAR manifests are updated with new attributes and lazy version injection, distribution tasks use lazy version providers, git tagging is replaced with a new tagVersion task, and version validation tests are added.

Changes

Versioning System Migration: git-versioner to nisse JGit plugin

Layer / File(s) Summary
CI: Enable Full Git History Checkout
.github/workflows/main-build.yml, .github/workflows/step-ci-build.yml
All workflow jobs' actions/checkout steps now include fetch-depth: 0 to retrieve complete git history, enabling JGit-based version counting.
Plugin Infrastructure & Setup
settings.gradle, build.gradle
settings.gradle adds pluginManagement block with repository and nisse plugin resolution rules; build.gradle removes io.toolebox.git-versioner plugin and adds eu.maveniverse.gradle.plugins.nisse-gradle-plugin.
Version Configuration & Tasks
build.gradle
nisseConfig block configures JGit counting and snapshot behavior; afterEvaluate hook sets project.version from nisse output with validation; new printVersion task outputs computed version.
Manifest & Distribution Artifact Updates
build.gradle
jar and shadowJar tasks add Enable-Final-Field-Mutation manifest attribute and inject JBang-Version during doFirst; container, spec, chocolatey Copy tasks use lazy provider { project.version } for incremental input tracking.
Git Tag Release Task
build.gradle
New tagVersion task creates annotated git tags (v<version>), checks existing tags' targets, and pushes to origin, replacing previous tagging behavior.
Version Validation Tests
src/test/java/dev/jbang/TestBuildVersion.java
New test class validates BuildConfig.VERSION is non-null, non-empty, matches a dotted numeric pattern, and conditionally asserts JBang-Version in the built manifest when present.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🐰 From git-versioner's farewell, nisse takes the lead,
Full history in CI, precisely what we need,
JGit counts the versions, tagged with care,
Manifests enriched, the build now fair!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: Use nisse-gradle-plugin' directly and specifically describes the main change: switching from git-versioner to nisse-gradle-plugin for build versioning.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Note

Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

❌ Failed to create PR with unit tests: AGENT_CHAT: Failed to open pull request

@maxandersen maxandersen force-pushed the nisse-gradle-plugin branch from 3ca37d2 to 42c6442 Compare May 15, 2026 22:02
Comment thread gradle.properties Outdated
@cstamas
Copy link
Copy Markdown
Contributor Author

cstamas commented May 16, 2026

Plugin is used, but something is still off, CI built JBang reports jbang version 0.0.1-1 that is Nisse initial version.

@maxandersen maxandersen changed the title Use nisse-gradle-plugin fix: Use nisse-gradle-plugin May 16, 2026
@maxandersen maxandersen marked this pull request as ready for review May 16, 2026 12:46
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/test/java/dev/jbang/TestBuildVersion.java (2)

33-36: ⚡ Quick win

Consider validating consistency between BuildConfig.VERSION and JBang-Version.

Both the BuildConfig.VERSION and the manifest JBang-Version attribute should be set from the same nisse plugin output. Adding a consistency check would help catch configuration issues where they might diverge.

♻️ Proposed additional assertion
 		String jbangVersion = manifest.getMainAttributes().getValue("JBang-Version");
 		assertNotNull(jbangVersion, "JBang-Version should be present in META-INF/MANIFEST.MF");
 		assertFalse(jbangVersion.equals("unspecified"),
 				"JBang-Version in MANIFEST.MF should not be 'unspecified'");
+		assertEquals(BuildConfig.VERSION, jbangVersion,
+				"JBang-Version in MANIFEST.MF should match BuildConfig.VERSION");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/java/dev/jbang/TestBuildVersion.java` around lines 33 - 36, Add an
assertion in TestBuildVersion that the manifest JBang-Version matches the
compiled BuildConfig.VERSION to ensure they come from the same nisse plugin
output; locate the existing jbangVersion variable (from
manifest.getMainAttributes().getValue("JBang-Version")) and add an
assertEquals(BuildConfig.VERSION, jbangVersion, "BuildConfig.VERSION must match
JBang-Version in MANIFEST.MF"), ensuring you keep the existing null/unspecified
checks.

28-30: ⚡ Quick win

Consider using JUnit Assumptions for better test semantics.

The early return makes this test silently pass when the manifest file doesn't exist. Using JUnit's Assumptions.assumeTrue() would mark the test as skipped rather than passed, providing clearer test reporting about what was actually validated.

♻️ Proposed refactor using Assumptions
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
 	`@Test`
 	void manifestContainsVersion() throws IOException {
 		java.nio.file.Path manifestPath = java.nio.file.Paths.get("build/tmp/jar/MANIFEST.MF");
-		if (!java.nio.file.Files.exists(manifestPath)) {
-			return;
-		}
+		assumeTrue(java.nio.file.Files.exists(manifestPath), 
+				"Manifest file not yet generated - run jar task first");
 		try (InputStream is = java.nio.file.Files.newInputStream(manifestPath)) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/test/java/dev/jbang/TestBuildVersion.java` around lines 28 - 30, Replace
the silent early return in TestBuildVersion (the check using
java.nio.file.Files.exists(manifestPath)) with a JUnit assumption so the test is
skipped when the manifest is absent: use Assumptions.assumeTrue(...) (import
org.junit.jupiter.api.Assumptions) with a clear message referencing the
manifest, and keep the rest of the test logic unchanged so the presence of the
manifest is required for the assertions to run.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@build.gradle`:
- Around line 553-564: The tagVersion task always creates and pushes a git tag
(using tagName = 'v' + project.version) which fails on reruns; update task
tagVersion to first check for existence of tagName locally and remotely (e.g.,
via git tag -l or git ls-remote --tags origin) and only run the git tag and git
push commands when the tag does not already exist, ensuring the exec calls that
create/push the tag are skipped when tagName is present so the task becomes
idempotent for retries.
- Around line 247-253: The build should fail fast when the computed version is
the nisse fallback (e.g., 0.0.1-{count}) to avoid publishing with an invalid
baseline; add a validation step that examines the resolved project.version after
the nisseConfig.jgit settings (countingVersion, countingStartPatch,
appendSnapshot, countingPattern) and throws a GradleException if it matches the
fallback pattern (e.g., /^0\.0\.1-\d+$/) or if no semantic baseline tag was
found, and wire that validation task to run before publish/assemble tasks (or
alternatively set a proper versionHintPattern or create an initial semantic tag
like v0.1.0) so the build fails instead of silently publishing the fallback
version.

---

Nitpick comments:
In `@src/test/java/dev/jbang/TestBuildVersion.java`:
- Around line 33-36: Add an assertion in TestBuildVersion that the manifest
JBang-Version matches the compiled BuildConfig.VERSION to ensure they come from
the same nisse plugin output; locate the existing jbangVersion variable (from
manifest.getMainAttributes().getValue("JBang-Version")) and add an
assertEquals(BuildConfig.VERSION, jbangVersion, "BuildConfig.VERSION must match
JBang-Version in MANIFEST.MF"), ensuring you keep the existing null/unspecified
checks.
- Around line 28-30: Replace the silent early return in TestBuildVersion (the
check using java.nio.file.Files.exists(manifestPath)) with a JUnit assumption so
the test is skipped when the manifest is absent: use Assumptions.assumeTrue(...)
(import org.junit.jupiter.api.Assumptions) with a clear message referencing the
manifest, and keep the rest of the test logic unchanged so the presence of the
manifest is required for the assertions to run.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 207d9dae-5ab8-4f7f-890b-df3e01069f5b

📥 Commits

Reviewing files that changed from the base of the PR and between 221049f and a680c7e.

📒 Files selected for processing (5)
  • .github/workflows/main-build.yml
  • .github/workflows/step-ci-build.yml
  • build.gradle
  • settings.gradle
  • src/test/java/dev/jbang/TestBuildVersion.java

Comment thread build.gradle
Comment thread build.gradle
…test improvements

- afterEvaluate now throws GradleException if version matches 0.0.1-x fallback
- tagVersion checks if tag exists: skips if same SHA, fails if different SHA
- manifestContainsVersion uses assumeTrue instead of silent return
- Added consistency assertion between BuildConfig.VERSION and manifest JBang-Version
@maxandersen
Copy link
Copy Markdown
Collaborator

I pushed changes so jbang's build .gradle now deals with the tagging/ version setting that is not optimal but what's needed for now to enable use of worktrees with git. worth the extra maintainance.

@cstamas it would be handy if nisse could do this but also feels outofbounds for nisse. I found https://github.com/ajoberstar/gradle-git but it got split up and now at sourcehut which is a mess to browse/look at thus not going for that now :)

@maxandersen maxandersen merged commit 188167a into jbangdev:main May 17, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants