Browse Source

Allow including kotlinx.serialization.* into Gradle plugin (#2020)

pull/2027/head
Alexey Tsvetkov 3 years ago committed by GitHub
parent
commit
7d92a265f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      gradle-plugins/compose/build.gradle.kts

40
gradle-plugins/compose/build.gradle.kts

@ -112,21 +112,35 @@ val checkJar by tasks.registering {
doLast {
val file = jar.get().archiveFile.get().asFile
ZipFile(file).use { zip ->
val nonJbComposeClasses = zip.entries().asIterator().asSequence().filter {
!it.isDirectory
&& it.name.endsWith(".class")
&& !it.name.startsWith("org/jetbrains/compose")
}.toList()
if (nonJbComposeClasses.any()) {
error(buildString {
appendLine("Some classes from $file are not from 'org.jetbrains.compose' package:")
for (entry in nonJbComposeClasses) {
appendLine(" * ${entry.name}")
}
})
}
checkJarContainsExpectedPackages(zip)
}
}
}
// we want to avoid accidentally including unexpected jars/packages, e.g kotlin-stdlib etc
fun checkJarContainsExpectedPackages(jar: ZipFile) {
val expectedPackages = arrayOf(
"org/jetbrains/compose",
"kotlinx/serialization"
)
val unexpectedClasses = arrayListOf<String>()
for (entry in jar.entries()) {
if (entry.isDirectory || !entry.name.endsWith(".class")) continue
if (expectedPackages.none { prefix -> entry.name.startsWith(prefix) }) {
unexpectedClasses.add(entry.name)
}
}
if (unexpectedClasses.any()) {
error(buildString {
appendLine("Some classes from ${jar.name} are not from 'org.jetbrains.compose' package:")
unexpectedClasses.forEach {
appendLine(" * $it")
}
})
}
}
tasks.check {

Loading…
Cancel
Save