@@ -5,8 +5,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
55import com.google.devtools.ksp.gradle.KspAATask
66import com.javiersc.kotlin.kopy.args.KopyFunctions
77import common.*
8- import java.time.ZonedDateTime
9- import java.time.format.DateTimeFormatter
108import java.util.jar.Attributes
119import kotlinx.validation.*
1210import org.gradle.internal.os.OperatingSystem
@@ -98,21 +96,7 @@ tasks {
9896 // withType<Kotlin2JsCompile>().configureEach {}
9997
10098 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) }
116100 duplicatesStrategy = DuplicatesStrategy .INCLUDE
117101 }
118102
@@ -137,32 +121,37 @@ tasks {
137121 }
138122
139123 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/
151127 manifest {
152128 attributes[Attributes .Name .MAIN_CLASS .toString()] = libs.versions.app.mainclass
153129 }
154- duplicatesStrategy = DuplicatesStrategy .INCLUDE
155130 }
156131
157132 val buildExecutable by
158133 registering(ReallyExecJar ::class ) {
159- jarFile = shadowJvmJar .flatMap { it.archiveFile }
134+ jarFile = shadowJar .flatMap { it.archiveFile }
160135 javaOpts = jvmRunArgs
161136 execJarFile = layout.buildDirectory.dir(" libs" ).map { it.file(" ${project.name} -app" ) }
162137 onlyIf { OperatingSystem .current().isUnix }
163138 }
164139
165140 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+ }
166155 }
167156
168157 pluginManager.withPlugin(" org.jetbrains.kotlinx.binary-compatibility-validator" ) {
@@ -174,7 +163,7 @@ tasks {
174163 }
175164
176165 withType<KotlinApiBuildTask >().configureEach {
177- // inputJar = named<Jar>("shadowJvmJar ").flatMap { it.archiveFile }
166+ // inputJar = named<Jar>("shadowJar ").flatMap { it.archiveFile }
178167 }
179168 }
180169}
0 commit comments