Skip to content

Commit 7eab893

Browse files
committed
Add a verification that all 3rd party dependencies are relocated.
1 parent 1b092dd commit 7eab893

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

build-setup/src/main/kotlin/co/touchlab/skie/buildsetup/gradle/plugins/gradle/GradlePluginPlugin.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
1212
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
1313
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.shadowJar
1414
import com.gradle.publish.PublishPlugin
15+
import org.apache.tools.zip.ZipFile
1516
import org.gradle.api.Plugin
1617
import org.gradle.api.Project
1718
import org.gradle.api.attributes.Category
@@ -58,6 +59,10 @@ abstract class GradlePluginPlugin : Plugin<Project> {
5859
tasks.shadowJar.configure {
5960
archiveClassifier.set("")
6061

62+
doLast {
63+
verifyFatJarContent()
64+
}
65+
6166
dependencies {
6267
exclude {
6368
it.moduleGroup == "org.jetbrains.kotlin" && it.moduleName.startsWith("kotlin-stdlib")
@@ -93,3 +98,30 @@ abstract class GradlePluginPlugin : Plugin<Project> {
9398
}
9499
}
95100
}
101+
102+
private fun ShadowJar.verifyFatJarContent() {
103+
val allowedFiles = listOf(
104+
"about.html",
105+
"LICENSE",
106+
"vendors.json",
107+
)
108+
109+
val allowedDirectories = listOf(
110+
"co/touchlab/skie",
111+
"META-INF",
112+
"OSGI-INF",
113+
).map { "$it/" }
114+
115+
val jar = archiveFile.get().asFile
116+
117+
ZipFile(jar).use { zip ->
118+
zip.entries.toList().filter { !it.isDirectory }.forEach { entry ->
119+
val isAllowedFile = entry.name in allowedFiles
120+
val isInAllowedDirectory = allowedDirectories.any { entry.name.startsWith(it) }
121+
122+
check(isAllowedFile || isInAllowedDirectory) {
123+
"File ${entry.name} is not allowed in the fat jar."
124+
}
125+
}
126+
}
127+
}

0 commit comments

Comments
 (0)