I'm trying to make a "compose allowlist" that will...
# plugin-development
j
I'm trying to make a "compose allowlist" that will fail to compile a module if it is trying to use Compose without being on the allowlist. My fear is that this is being applied to 1,200 modules... Is this Kosher? Am I creating 1,200 HashSets? Is there a better way?
Copy code
val composeAllowList = Providers.of(
    setOf(
        ":foo:ui",
        ":bar:ui",
        ":etc:ui", // 40 such entries in here
    )
)

fun Project.composeAllowList() {
    val modulePath = path

    tasks.withType(KotlinCompile::class.java).configureEach {
        inputs.property("composeAllowList", composeAllowList)

        doFirst {
            // We check to see if the Compose Compiler plugin has been added to the compiler args.
            val usingComposeCompiler =
                kotlinOptions.freeCompilerArgs.any { it.contains("androidx.compose.compiler") }
            if (usingComposeCompiler) {
                val composeAllowlist = inputs.properties["composeAllowList"] as Set<String>

                val moduleInComposeAllowlist = composeAllowlist.contains(modulePath)
                // If the module is using Jetpack Compose but isn"t in the allowlist...💥
                if (!moduleInComposeAllowlist && !modulePath.endsWith("twig")) {
                    throw GradleException("Module $modulePath is not in the allowlist for Compose!")
                }
            }
        }
    }
}