From ad57414f29078b6e8876172517e3dfc53624d6c3 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:28:01 +0300 Subject: [PATCH] Do not shade transitive dependencies (#1321) --- gradle-plugins/compose/build.gradle.kts | 34 ++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/gradle-plugins/compose/build.gradle.kts b/gradle-plugins/compose/build.gradle.kts index 47997dbe2c..8d1d1d443b 100644 --- a/gradle-plugins/compose/build.gradle.kts +++ b/gradle-plugins/compose/build.gradle.kts @@ -1,5 +1,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem +import java.util.zip.ZipFile plugins { kotlin("jvm") @@ -38,7 +39,9 @@ sourceSets.main.configure { java.srcDir(buildConfigDir) } -val embeddedDependencies by configurations.creating +val embeddedDependencies by configurations.creating { + isTransitive = false +} dependencies { // By default, Gradle resolves plugins only via Gradle Plugin Portal. @@ -95,6 +98,35 @@ val javaHomeForTests: String? = when { val isWindows = getCurrentOperatingSystem().isWindows val gradleTestsPattern = "org.jetbrains.compose.gradle.*" + +// check we don't accidentally including unexpected classes (e.g. from embedded dependencies) +val checkJar by tasks.registering { + dependsOn(jar) + + 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}") + } + }) + } + } + } +} + +tasks.check { + dependsOn(checkJar) +} + tasks.test { dependsOn(jar) classpath = project.files(jar.map { it.archiveFile }) + classpath