Skip to content

Commit

Permalink
Automated java module checking (#3411)
Browse files Browse the repository at this point in the history
Adds a task called `testModules` that calls `java --list-modules` on each JAR file built to check that its modules can be listed. We have had issues in the past that went unnoticed, and this is one of the easiest ways to do a sanity check that a JAR will work on the module path. See, for example, gh-3398 and gh-3412, which would have been caught by this check.
  • Loading branch information
marcingrzejszczak committed Sep 14, 2022
1 parent 54290b4 commit 50f07d9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@ subprojects {
}
}

task testModules(type: Exec) {
dependsOn jar
String executablePath = javaToolchains.launcherFor { languageVersion = javaLanguageVersion }.get().executablePath
commandLine "$executablePath", '-p', "$jar.archivePath", '--list-modules'
standardOutput = new ByteArrayOutputStream()
ignoreExitValue = true

doLast {
if (executionResult.get().getExitValue() != 0) {
throw new GradleException("Command finished with non-zero exit value ${executionResult.get().getExitValue()}:\n$standardOutput")
}
}
}

check.dependsOn("testModules")

if (!(project.name in ['micrometer-commons', 'micrometer-observation', 'micrometer-observation-conventions', 'micrometer-observation-test'])) {
apply plugin: 'me.champeau.gradle.japicmp'
apply plugin: 'de.undercouch.download'
Expand Down

0 comments on commit 50f07d9

Please sign in to comment.