@@ -12,7 +12,10 @@ import org.gradle.api.Action
1212import org.gradle.api.GradleException
1313import org.gradle.api.Plugin
1414import org.gradle.api.Project
15+ import org.gradle.api.distribution.Distribution
16+ import org.gradle.api.file.CopySpec
1517import org.gradle.api.plugins.ApplicationPlugin
18+ import org.gradle.api.provider.Provider
1619import org.gradle.api.tasks.JavaExec
1720import org.gradle.api.tasks.Sync
1821import org.gradle.api.tasks.TaskContainer
@@ -87,21 +90,13 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
8790 }
8891
8992 protected open fun Project.configureDistribution () {
90- distributions.register(DISTRIBUTION_NAME ) {
91- it.contents { shadowDist ->
92- shadowDist.from(file(" src/dist" ))
93- shadowDist.into(" lib" ) { lib ->
94- lib.from(tasks.shadowJar)
95- // Reflects the value of the `Class-Path` attribute in the JAR manifest.
96- lib.from(configurations.shadow)
97- }
98- // Defaults to bin dir.
99- shadowDist.into(applicationExtension.executableDir) { bin ->
100- bin.from(tasks.startShadowScripts)
101- bin.filePermissions { permissions -> permissions.unix(UNIX_SCRIPT_PERMISSIONS ) }
102- }
103- shadowDist.with (applicationExtension.applicationDistribution)
93+ registerShadowDistributionCommon { dist ->
94+ // Defaults to bin dir.
95+ dist.into(applicationExtension.executableDir) { bin ->
96+ bin.from(tasks.startShadowScripts)
97+ bin.filePermissions { permissions -> permissions.unix(UNIX_SCRIPT_PERMISSIONS ) }
10498 }
99+ dist.with (applicationExtension.applicationDistribution)
105100 }
106101 }
107102
@@ -115,7 +110,7 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
115110 /* *
116111 * Reflects the number of 755.
117112 */
118- private const val UNIX_SCRIPT_PERMISSIONS = " rwxr-xr-x"
113+ internal const val UNIX_SCRIPT_PERMISSIONS = " rwxr-xr-x"
119114
120115 public const val DISTRIBUTION_NAME : String = SHADOW
121116
@@ -152,5 +147,21 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
152147 action.execute(task)
153148 }
154149 }
150+
151+ internal fun Project.registerShadowDistributionCommon (
152+ action : Action <CopySpec >,
153+ ): Provider <Distribution > {
154+ return distributions.register(DISTRIBUTION_NAME ) {
155+ it.contents { shadowDist ->
156+ shadowDist.from(file(" src/dist" ))
157+ shadowDist.into(" lib" ) { lib ->
158+ lib.from(tasks.shadowJar)
159+ // Reflects the value of the `Class-Path` attribute in the JAR manifest.
160+ lib.from(configurations.shadow)
161+ }
162+ action.execute(shadowDist)
163+ }
164+ }
165+ }
155166 }
156167}
0 commit comments