Skip to content

Commit b223146

Browse files
committed
added dependencyUpdates task with nice DF output to track available dependency updates
1 parent 54359e9 commit b223146

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

build.gradle.kts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
12
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3+
import org.jetbrains.kotlinx.dataframe.AnyFrame
4+
import org.jetbrains.kotlinx.dataframe.DataFrame
5+
import org.jetbrains.kotlinx.dataframe.api.filter
6+
import org.jetbrains.kotlinx.dataframe.api.print
7+
import org.jetbrains.kotlinx.dataframe.api.select
8+
import org.jetbrains.kotlinx.dataframe.io.readJson
29
import org.jetbrains.kotlinx.publisher.apache2
310
import org.jetbrains.kotlinx.publisher.developer
411
import org.jetbrains.kotlinx.publisher.githubRepo
@@ -41,6 +48,64 @@ dependencies {
4148
api(project(":dataframe-jdbc"))
4249
}
4350

51+
private enum class Version : Comparable<Version> {
52+
SNAPSHOT, DEV, ALPHA, BETA, RC, STABLE;
53+
}
54+
55+
private fun String.findVersion(): Version {
56+
val version = this.lowercase()
57+
return when {
58+
"snapshot" in version -> Version.SNAPSHOT
59+
"dev" in version -> Version.DEV
60+
"alpha" in version -> Version.ALPHA
61+
"beta" in version -> Version.BETA
62+
"rc" in version -> Version.RC
63+
else -> Version.STABLE
64+
}
65+
}
66+
67+
// these names of outdated dependencies will not show up in the table output
68+
val dependencyUpdateExclusions = listOf(
69+
"klaxon", // 5.6 requires Java 11
70+
)
71+
72+
// run `./gradlew dependencyUpdates` to check for updates
73+
tasks.named<DependencyUpdatesTask>("dependencyUpdates").configure {
74+
checkForGradleUpdate = true
75+
outputFormatter = "json,html"
76+
revision = "milestone"
77+
78+
rejectVersionIf {
79+
val current = currentVersion.findVersion()
80+
val candidate = candidate.version.findVersion()
81+
candidate < current
82+
}
83+
84+
doLast {
85+
val outputFile = layout.buildDirectory
86+
.file("../$outputDir/$reportfileName.json")
87+
.get().asFile
88+
when (val outDatedDependencies = DataFrame.readJson(outputFile)["outdated"]["dependencies"][0]) {
89+
is AnyFrame -> {
90+
val df = outDatedDependencies.select {
91+
cols("group", "name", "version") and {
92+
"available"["milestone"] named "newVersion"
93+
}
94+
}.filter { "name"() !in dependencyUpdateExclusions }
95+
logger.warn("Outdated dependencies found:")
96+
df.print(
97+
rowsLimit = Int.MAX_VALUE,
98+
valueLimit = Int.MAX_VALUE,
99+
borders = true,
100+
title = true,
101+
alignLeft = true,
102+
)
103+
}
104+
else -> logger.info("No outdated dependencies found")
105+
}
106+
}
107+
}
108+
44109
allprojects {
45110
tasks.withType<KotlinCompile> {
46111
kotlinOptions {

0 commit comments

Comments
 (0)