is there any way to setup Gradle Shadow with a Kotlin multiplatform project? I am using the "new" version of a multiplatform project, where I have all my source set definitions/dependencies in just one file. Here is my build file:
buildscript {
ext.ktor_version = "1.0.0-beta-3"
repositories {
maven { url "https://plugins.gradle.org/m2/"}
}
dependencies {
classpath "com.github.jengelman.gradle.plugins:shadow:4.0.2"
}
}
plugins {
id 'kotlin-multiplatform' version '1.3.0'
id 'com.github.johnrengelman.shadow' version '4.0.2'
id 'application'
}
version = '1.0'
group = '[redacted]'
mainClassName = '[redacted]'
repositories {
maven { url "https://dl.bintray.com/kotlin/exposed" }
maven { url "https://dl.bintray.com/kotlin/ktor" }
mavenCentral()
jcenter()
}
kotlin {
targets {
fromPreset(presets.jvm, 'jvm')
fromPreset(presets.js, 'js')
}
sourceSets {
commonMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
}
}
commonTest {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-test-common'
implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
}
}
jvmMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
implementation 'org.jetbrains.exposed:exposed:0.11.2'
implementation "org.mindrot:jbcrypt:0.4"
implementation "org.slf4j:slf4j-simple:1.8.0-beta2"
implementation "io.ktor:ktor-server-netty:$ktor_version"
implementation "io.ktor:ktor-jackson:$ktor_version"
implementation "mysql:mysql-connector-java:8.0.13"
}
}
jvmTest {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-test'
implementation 'org.jetbrains.kotlin:kotlin-test-junit'
}
}
jsMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
}
}
jsTest {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-test-js'
}
}
}
}
shadowJar {
baseName = '[redacted]'
version = 1.0
}
Trying to use this, I have the sad outcome of a JAR file, with just the META-INF (304 bytes). I'm not sure where to begin, honestly, and this has kept me thinking and confused for hours. Anyone's help will be appreciated.
Skeleton of my project:
├── build.gradle
├── gradle.properties
├── settings.gradle
└── src
├── commonMain
│ └── kotlin
│ ├── PasswordValidator.kt
│ └── Responses.kt
└── jvmMain
└── kotlin
└── XXX
└── XXXXXX
└── ticketing
├── Auth.kt
├── Registration.kt
├── Server.kt
├── requests
│ ├── Auth.kt
│ ├── Register.kt
│ └── account
│ ├── Close.kt
│ ├── List.kt
│ ├── ModifyPassword.kt
│ ├── New.kt
│ └── SetAdmin.kt
└── services
├── AsyncHandler.kt
├── Exception.kt
├── RateLimiter.kt
└── Token.kt
Actually, you don't need Shadow. Just add the following code in kotlin > targets (build.gradle) block
configure([jvmJar]) {
manifest{
attributes 'Main-Class':'main.class.path.MainKt'
}
}
The generated Jar file in build/libs
will contain specified Main-Class
in manifest. All the required classes are also already there. Generated jar is ready to use (don't forget to specify external dependencies in the project where you are using jar - I managed to get it work on gradle java project).