@@ -12,6 +12,7 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
1212import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
1313import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.shadowJar
1414import com.gradle.publish.PublishPlugin
15+ import org.apache.tools.zip.ZipFile
1516import org.gradle.api.Plugin
1617import org.gradle.api.Project
1718import 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