https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
g

GarouDan

04/25/2019, 2:42 PM
Hi, I’ve asked this question in the gradle slack, but it looks like this is more pertinent to this channel. I’m trying to use the
<https://github.com/johnrengelman/shadow>
plugin, to create fatJars. I’ve already done the integration in my project but I’m seeing only a
knows task
. (I’m using gradle
5.3.1
) My current configuration is:
Copy code
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
...
plugins {
    kotlin("multiplatform")

    id("com.github.johnrengelman.shadow") version "5.0.0"
}
...
tasks.withType<ShadowJar> {
    baseName = "app"
    classifier = ""
    version = ""
}
With
./gradlew tasks
I can se only a
knows
task
Copy code
Shadow tasks
------------
knows - Do you know who knows?
and if I run
./gradlew shadowJar
I receive an error like:
Copy code
* What went wrong:
Task 'shadowJar' not found in root project 'my_project'.
Does someone have a working example with a kotlin mpp project and fatJars? It looks like the
shadowJar
task is created only in the presence of the
JavaPlugin
and because I’m using Kotlin it is not being created. Thanks in advance!
r

ribesg

04/25/2019, 2:47 PM
I guess you can just create the task yourself
g

GarouDan

04/25/2019, 4:01 PM
It looks like this could be a little difficult. It looks like I would need to convert this task to
.kts
and handle with the internal implementations of this plugin. https://github.com/johnrengelman/shadow/blob/5.0.0/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy#L41-L66
d

Dominaezzz

04/25/2019, 4:29 PM
You don't have to to that.
Just change
withType
to
create
.
Add a name too lol.
g

GarouDan

04/25/2019, 4:35 PM
I tried something like:
Copy code
tasks.create("shadowJar", ShadowJar::class.java) {
	baseName = "my_project"
	classifier = ""
	version = ""
}
and after running the
shadowJar
a file named
my_project.jar
was created. But when I tried to run
java -jar my_project.jar
I’ve received
no main manifest attribute, in my_project.jar
So I think it is still not a fat jar yet =/ If you have any clues, please kindly let me know
Inside the jar I only have:
Copy code
META-INF/
META-INF/MANIFEST.MF
and inside the manifest:
Copy code
Manifest-Version: 1.0
g

GarouDan

04/25/2019, 6:45 PM
I tried this approach and the main class was pointed but the dependencies weren’t being loaded. I was able to put this to work with something like:
Copy code
tasks.withType<ShadowJar> {
	manifest {
		attributes.put("Main-Class", "com.example.ExampleKt")
	}

	val target = kotlin.targets.jvm("myTarget")
	from(target.compilations["main"].output)
	val runtimeClasspath = target.compilations["main"].compileDependencyFiles as Configuration
	configurations = mutableListOf(runtimeClasspath)
}
I still need to check some other options, but finally something working 😉
2 Views