@@ -5,8 +5,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
5
5
import com.google.devtools.ksp.gradle.KspAATask
6
6
import com.javiersc.kotlin.kopy.args.KopyFunctions
7
7
import common.*
8
- import java.time.ZonedDateTime
9
- import java.time.format.DateTimeFormatter
10
8
import java.util.jar.Attributes
11
9
import kotlinx.validation.*
12
10
import org.gradle.internal.os.OperatingSystem
@@ -98,21 +96,7 @@ tasks {
98
96
// withType<Kotlin2JsCompile>().configureEach {}
99
97
100
98
withType<Jar >().configureEach {
101
- manifest {
102
- attributes(
103
- // "Automatic-Module-Name" to project.group,
104
- " Enable-Native-Access" to " ALL-UNNAMED" ,
105
- " Built-By" to System .getProperty(" user.name" ),
106
- " Built-Jdk" to System .getProperty(" java.runtime.version" ),
107
- " Built-OS" to
108
- " ${System .getProperty(" os.name" )} ${System .getProperty(" os.arch" )} ${System .getProperty(" os.version" )} " ,
109
- " Build-Timestamp" to DateTimeFormatter .ISO_INSTANT .format(ZonedDateTime .now()),
110
- " Created-By" to " Gradle ${gradle.gradleVersion} " ,
111
- Attributes .Name .IMPLEMENTATION_TITLE .toString() to project.name,
112
- Attributes .Name .IMPLEMENTATION_VERSION .toString() to project.version,
113
- Attributes .Name .IMPLEMENTATION_VENDOR .toString() to project.group,
114
- )
115
- }
99
+ manifest { attributes(defaultJarManifest) }
116
100
duplicatesStrategy = DuplicatesStrategy .INCLUDE
117
101
}
118
102
@@ -137,32 +121,37 @@ tasks {
137
121
}
138
122
139
123
pluginManager.withPlugin(" com.gradleup.shadow" ) {
140
- // Register a shadowJar task for the default jvm target
141
- val shadowJvmJar by
142
- registering(ShadowJar ::class ) {
143
- val main by kotlin.jvm().compilations
144
- // allOutputs == classes + resources
145
- from(main.output.allOutputs)
146
- val runtimeDepConfig =
147
- project.configurations.getByName(main.runtimeDependencyConfigurationName)
148
- configurations = listOf (runtimeDepConfig)
149
- archiveClassifier = " all"
150
- mergeServiceFiles()
124
+ val shadowJar by
125
+ existing(ShadowJar ::class ) {
126
+ // https://gradleup.com/shadow/kmp-plugin/
151
127
manifest {
152
128
attributes[Attributes .Name .MAIN_CLASS .toString()] = libs.versions.app.mainclass
153
129
}
154
- duplicatesStrategy = DuplicatesStrategy .INCLUDE
155
130
}
156
131
157
132
val buildExecutable by
158
133
registering(ReallyExecJar ::class ) {
159
- jarFile = shadowJvmJar .flatMap { it.archiveFile }
134
+ jarFile = shadowJar .flatMap { it.archiveFile }
160
135
javaOpts = jvmRunArgs
161
136
execJarFile = layout.buildDirectory.dir(" libs" ).map { it.file(" ${project.name} -app" ) }
162
137
onlyIf { OperatingSystem .current().isUnix }
163
138
}
164
139
165
140
build { finalizedBy(buildExecutable) }
141
+
142
+ // Shows how to register a shadowJar task for the default jvm target
143
+ register<ShadowJar >(" shadowJvmJar" ) {
144
+ val main by kotlin.jvm().compilations
145
+ // allOutputs == classes + resources
146
+ from(main.output.allOutputs)
147
+ val runtimeDepConfig =
148
+ project.configurations.getByName(main.runtimeDependencyConfigurationName)
149
+ configurations = listOf (runtimeDepConfig)
150
+ archiveClassifier = " jvm-all"
151
+ mergeServiceFiles()
152
+ manifest { attributes[Attributes .Name .MAIN_CLASS .toString()] = libs.versions.app.mainclass }
153
+ duplicatesStrategy = DuplicatesStrategy .INCLUDE
154
+ }
166
155
}
167
156
168
157
pluginManager.withPlugin(" org.jetbrains.kotlinx.binary-compatibility-validator" ) {
@@ -174,7 +163,7 @@ tasks {
174
163
}
175
164
176
165
withType<KotlinApiBuildTask >().configureEach {
177
- // inputJar = named<Jar>("shadowJvmJar ").flatMap { it.archiveFile }
166
+ // inputJar = named<Jar>("shadowJar ").flatMap { it.archiveFile }
178
167
}
179
168
}
180
169
}
0 commit comments