Skip to content

Commit 7e4fdb1

Browse files
committed
Throw VerificationException on unsorted dependencies.
1 parent f0b4312 commit 7e4fdb1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sort-dependencies-gradle-plugin/src/main/kotlin/com/squareup/sort/CheckSortDependenciesTask.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ abstract class CheckSortDependenciesTask @Inject constructor(
3737
val version = version.get().removeSuffix("-SNAPSHOT").toDouble()
3838

3939
val result = execOps.exec { execSpec ->
40+
execSpec.setIgnoreExitValue(true)
4041
execSpec.commandLine = listOf(
4142
"java",
4243
"-cp", sortProgram.asPath,
@@ -69,5 +70,13 @@ abstract class CheckSortDependenciesTask @Inject constructor(
6970
outputDirectory.asFile.get().mkdirs()
7071
val outputPath : Path = Paths.get(outputDirectory.asFile.get().absolutePath, "result.txt")
7172
File(outputPath.toUri()).writeText(resultText)
73+
74+
if (result.exitValue == 2) {
75+
throw VerificationException("Dependencies are not correctly sorted.")
76+
} else if (result.exitValue == 3) {
77+
throw RuntimeException("There were parse errors.")
78+
} else if (result.exitValue > 0) {
79+
throw RuntimeException("The command failed with exit code ${result.exitValue}.")
80+
}
7281
}
7382
}

0 commit comments

Comments
 (0)