Skip to content

Commit faafe61

Browse files
committed
Register shadow distribution
1 parent d855d51 commit faafe61

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.kt

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import org.gradle.api.Action
1212
import org.gradle.api.GradleException
1313
import org.gradle.api.Plugin
1414
import org.gradle.api.Project
15+
import org.gradle.api.distribution.Distribution
16+
import org.gradle.api.file.CopySpec
1517
import org.gradle.api.plugins.ApplicationPlugin
18+
import org.gradle.api.provider.Provider
1619
import org.gradle.api.tasks.JavaExec
1720
import org.gradle.api.tasks.Sync
1821
import 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
}

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowKmpPlugin.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.github.jengelman.gradle.plugins.shadow
22

3+
import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.UNIX_SCRIPT_PERMISSIONS
34
import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.registerRunShadowCommon
5+
import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.registerShadowDistributionCommon
46
import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.registerStartShadowScriptsCommon
7+
import com.github.jengelman.gradle.plugins.shadow.ShadowApplicationPlugin.Companion.startShadowScripts
58
import com.github.jengelman.gradle.plugins.shadow.internal.isAtLeastKgpVersion
69
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.SHADOW_JAR_TASK_NAME
710
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.registerShadowJarCommon
@@ -49,6 +52,7 @@ public abstract class ShadowKmpPlugin : Plugin<Project> {
4952
(tasks.getByName("startScriptsFor$targetNameCap") as CreateStartScripts).let {
5053
addCreateScriptsTask(it)
5154
}
55+
configureDistribution()
5256
}
5357
}
5458

@@ -99,4 +103,16 @@ public abstract class ShadowKmpPlugin : Plugin<Project> {
99103
}
100104
}
101105
}
106+
107+
private fun Project.configureDistribution() {
108+
registerShadowDistributionCommon { dist ->
109+
// Should use KotlinJvmBinaryDsl.applicationDistribution instead.
110+
dist.into("bin") { bin ->
111+
bin.from(tasks.startShadowScripts)
112+
bin.filePermissions { permissions -> permissions.unix(UNIX_SCRIPT_PERMISSIONS) }
113+
}
114+
// TODO: we can't access KotlinJvmBinaryDsl instance for now.
115+
// dist.with(KotlinJvmBinaryDsl.applicationDistribution)
116+
}
117+
}
102118
}

0 commit comments

Comments
 (0)