@@ -12,7 +12,9 @@ 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
1516import org.gradle.api.plugins.ApplicationPlugin
17+ import org.gradle.api.provider.Provider
1618import org.gradle.api.tasks.JavaExec
1719import org.gradle.api.tasks.Sync
1820import org.gradle.api.tasks.TaskContainer
@@ -87,7 +89,7 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
8789 }
8890
8991 protected open fun Project.configureDistribution () {
90- distributions.register( DISTRIBUTION_NAME ) { dist ->
92+ registerShadowDistributionCommon { dist ->
9193 dist.distributionBaseName.convention(
9294 provider {
9395 // distributionBaseName defaults to `$project.name-$distribution.name`, applicationName defaults to project.name
@@ -96,12 +98,6 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
9698 },
9799 )
98100 dist.contents { distSpec ->
99- distSpec.from(file(" src/dist" ))
100- distSpec.into(" lib" ) { lib ->
101- lib.from(tasks.shadowJar)
102- // Reflects the value of the `Class-Path` attribute in the JAR manifest.
103- lib.from(configurations.shadow)
104- }
105101 // Defaults to bin dir.
106102 distSpec.into(provider(applicationExtension::getExecutableDir)) { bin ->
107103 bin.from(tasks.startShadowScripts)
@@ -122,7 +118,7 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
122118 /* *
123119 * Reflects the number of 755.
124120 */
125- private const val UNIX_SCRIPT_PERMISSIONS = " rwxr-xr-x"
121+ internal const val UNIX_SCRIPT_PERMISSIONS = " rwxr-xr-x"
126122
127123 public const val DISTRIBUTION_NAME : String = SHADOW
128124
@@ -159,5 +155,21 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
159155 action.execute(task)
160156 }
161157 }
158+
159+ internal fun Project.registerShadowDistributionCommon (
160+ action : Action <Distribution >,
161+ ): Provider <Distribution > {
162+ return distributions.register(DISTRIBUTION_NAME ) { dist ->
163+ dist.contents { distSpec ->
164+ distSpec.from(file(" src/dist" ))
165+ distSpec.into(" lib" ) { lib ->
166+ lib.from(tasks.shadowJar)
167+ // Reflects the value of the `Class-Path` attribute in the JAR manifest.
168+ lib.from(configurations.shadow)
169+ }
170+ }
171+ action.execute(dist)
172+ }
173+ }
162174 }
163175}
0 commit comments