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 { doLast {
val file = jar.get().archiveFile.get().asFile val file = jar.get().archiveFile.get().asFile
ZipFile(file).use { zip -> ZipFile(file).use { zip ->
val nonJbComposeClasses = zip.entries().asIterator().asSequence().filter { checkJarContainsExpectedPackages(zip)
!it.isDirectory }
&& it.name.endsWith(".class") }
&& !it.name.startsWith("org/jetbrains/compose") }
}.toList()
if (nonJbComposeClasses.any()) { // we want to avoid accidentally including unexpected jars/packages, e.g kotlin-stdlib etc
error(buildString { fun checkJarContainsExpectedPackages(jar: ZipFile) {
appendLine("Some classes from $file are not from 'org.jetbrains.compose' package:") val expectedPackages = arrayOf(
for (entry in nonJbComposeClasses) { "org/jetbrains/compose",
appendLine(" * ${entry.name}") "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 { tasks.check {

Loading…
Cancel
Save