@@ -38,10 +38,7 @@ public abstract class ShadowJavaPlugin @Inject constructor(
3838
3939 protected open fun Project.configureShadowJar () {
4040 val jarTask = tasks.jar
41- val taskProvider = tasks.register(SHADOW_JAR_TASK_NAME , ShadowJar ::class .java) { task ->
42- task.group = ShadowBasePlugin .GROUP_NAME
43- task.description = " Create a combined JAR of project and runtime dependencies"
44- task.archiveClassifier.set(" all" )
41+ val taskProvider = registerShadowJarCommon { task ->
4542 @Suppress(" EagerGradleConfiguration" )
4643 task.manifest.inheritFrom(jarTask.get().manifest)
4744 val attrProvider = jarTask.map { it.manifest.attributes[classPathAttributeKey]?.toString().orEmpty() }
@@ -54,15 +51,6 @@ public abstract class ShadowJavaPlugin @Inject constructor(
5451 }
5552 task.from(sourceSets.named(" main" ).map { it.output })
5653 task.configurations.convention(provider { listOf (runtimeConfiguration) })
57- task.exclude(
58- " META-INF/INDEX.LIST" ,
59- " META-INF/*.SF" ,
60- " META-INF/*.DSA" ,
61- " META-INF/*.RSA" ,
62- // module-info.class in Multi-Release folders.
63- " META-INF/versions/**/module-info.class" ,
64- " module-info.class" ,
65- )
6654 }
6755 artifacts.add(configurations.shadow.name, taskProvider)
6856 }
@@ -132,5 +120,25 @@ public abstract class ShadowJavaPlugin @Inject constructor(
132120
133121 public inline val ConfigurationContainer .shadowRuntimeElements: NamedDomainObjectProvider <Configuration >
134122 get() = named(SHADOW_RUNTIME_ELEMENTS_CONFIGURATION_NAME )
123+
124+ public inline fun Project.registerShadowJarCommon (
125+ crossinline action : (ShadowJar ) -> Unit ,
126+ ): TaskProvider <ShadowJar > {
127+ return tasks.register(SHADOW_JAR_TASK_NAME , ShadowJar ::class .java) { task ->
128+ task.group = ShadowBasePlugin .GROUP_NAME
129+ task.description = " Create a combined JAR of project and runtime dependencies"
130+ task.archiveClassifier.set(" all" )
131+ task.exclude(
132+ " META-INF/INDEX.LIST" ,
133+ " META-INF/*.SF" ,
134+ " META-INF/*.DSA" ,
135+ " META-INF/*.RSA" ,
136+ // module-info.class in Multi-Release folders.
137+ " META-INF/versions/**/module-info.class" ,
138+ " module-info.class" ,
139+ )
140+ action(task)
141+ }
142+ }
135143 }
136144}
0 commit comments