Skip to content

Commit 3180b86

Browse files
authored
Merge pull request #37 from braintrustdata/ark/test-jar-validation
fail testJar task if jar version does not match expectations
2 parents 1dcef01 + 89bb5a4 commit 3180b86

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)