Skip to content

Commit e19ab20

Browse files
committed
Register shadow distribution
1 parent 56d70e9 commit e19ab20

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ 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
1516
import org.gradle.api.plugins.ApplicationPlugin
17+
import org.gradle.api.provider.Provider
1618
import org.gradle.api.tasks.JavaExec
1719
import org.gradle.api.tasks.Sync
1820
import 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
}

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

Lines changed: 18 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,18 @@ public abstract class ShadowKmpPlugin : Plugin<Project> {
99103
}
100104
}
101105
}
106+
107+
private fun Project.configureDistribution() {
108+
registerShadowDistributionCommon { dist ->
109+
dist.contents { distSpec ->
110+
// Should use KotlinJvmBinaryDsl.applicationDistribution instead.
111+
distSpec.into("bin") { bin ->
112+
bin.from(tasks.startShadowScripts)
113+
bin.filePermissions { permissions -> permissions.unix(UNIX_SCRIPT_PERMISSIONS) }
114+
}
115+
// TODO: we can't access KotlinJvmBinaryDsl instance for now.
116+
// distSpec.with(KotlinJvmBinaryDsl.applicationDistribution)
117+
}
118+
}
119+
}
102120
}

0 commit comments

Comments
 (0)