File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -315,9 +315,30 @@ task testJar(type: JavaExec) {
315315 classpath = files(jar. archiveFile)
316316 javaLauncher = javaToolchains. launcherFor(java. toolchain)
317317
318+ // Capture standard output
319+ standardOutput = new ByteArrayOutputStream ()
320+
318321 doFirst {
319322 // println "Testing jar: ${jar.archiveFile.get().asFile.absolutePath}"
320323 }
324+
325+ doLast {
326+ // Get the version printed by the jar
327+ def printedVersion = standardOutput. toString(). trim()
328+
329+ // Get the expected version from git state
330+ def expectedVersion = generateVersion()
331+
332+ // Compare versions
333+ if (printedVersion != expectedVersion) {
334+ throw new GradleException (
335+ " Version mismatch! Jar printed version '${ printedVersion} ' " +
336+ " but expected version from git state is '${ expectedVersion} '"
337+ )
338+ }
339+
340+ logger. lifecycle(" ✓ Jar version validation passed: ${ printedVersion} " )
341+ }
321342}
322343
323344// Run validation before compilation
You can’t perform that action at this time.
0 commit comments