49949

Create fat jar from kotlin multiplatform project

<h3>Question</h3>

I recently switched from old 1.2 multiplatform into 1.3. Difference is, there's one one build.gradle file per multiplatform module (I got 5 of them) so a lot less configuration. However I can't seem to be able to configure creating runnable fat jar with all dependencies from jvm platform. I used to use standard "application" plugin in my jvm project and jar task, but that does not work anymore. I found there's "jvmJar" task and I modified it (set Main-class), but created jar doesn't contain dependencies and crashes on ClassNotFoundException. How do I do it?

This is what I have now:

jvm() { jvmJar { manifest { attributes 'Main-Class': 'eu.xx.Runner' } from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } } }
<h3>Answer1:</h3>

I did hit that bump and used this work around.

<h3>1. Restructure your project</h3>

Lets call your project Project.

create another submodule say subA, which will have the gradle notation Project:subA

now, subA has your multiplatform code in it (It is the gradle project with apply :kotlin-multiplafrom) in its build.gradle

<h3>2. Add Another submodule</h3>

create another submodule which targets only jvm say subB, which will have the gradle notation Project:subB

So, subB will have plugins: 'application' and 'org.jetbrains.kotlin.jvm'

<h3>3. Add your module as a gradle dependency (see my build.gradle)</h3> plugins { id 'org.jetbrains.kotlin.jvm' version '1.3.31' id "application" } apply plugin: "kotlinx-serialization" group 'tz.or.self' version '0.0.0' mainClassName = "com.example.MainKt" sourceCompatibility = 1.8 compileKotlin { kotlinOptions.jvmTarget = "1.8" } dependencies { implementation project(':subA') }

you can proceed and build subB as you would a regular java project or even use the existing plugins, it will work


<h3>Answer2:</h3>

Got it working with the multiplatform plugin in kotlin 1.3.61:

The following works for a main file in src/jvmMain/kotlin/com/example/Hello.kt

Hello.kt must also specify it's package as package com.example

I configured my jvm target in this way:

kotlin { targets { jvm() configure([jvm]) { withJava() jvmJar { manifest { attributes 'Main-Class': 'com.example.HelloKt' } from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } } } } }
<h3>Answer3:</h3>

Got it to work with a slightly modified version of what luca992 did:

kotlin { jvm() { withJava() jvmJar { manifest { attributes 'Main-Class': 'sample.MainKt' } from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } } } ... }

来源:https://stackoverflow.com/questions/57168853/create-fat-jar-from-kotlin-multiplatform-project

Recommend

  • Find the first character of input in a textbox
  • Minor Git Issue - Changing Default Editor [duplicate]
  • Boost link error when using “--layout=system” on VS2005
  • WPF DataGridTextColumn Can't type point for float data
  • Oracle 11g CREATE VIEW using CONNECT BY and multiple tables
  • How is strcpy implemented?
  • FizzBuzz Ruby one-liner
  • Customising event delegates in the jQuery validation plug-in
  • No persistence units parsed from {classpath*:META-INF/persistence.xml}
  • How to find MAX or MIN in Verilog coding?
  • Why is rtrim removing more characters, and giving weird output?
  • How to add a timer script into this math challenge program? [duplicate]
  • MQL4, Code layout for big EA
  • NServiceBus How To Publish Message From 2 Physical Locations Of 1 Logical Service
  • Post-receive hook to pull from bare repo
  • To compare count between two hive table
  • Select Checkbox !== Select Row Table
  • Proc sql: new and continue customers based on look back period
  • Counting the Words in a String [closed]
  • Google Maps V3 (PHP/MYSQL with custome infobox)
  • forever does not start on server reboot [duplicate]
  • JavaFX Embed Custom Font Not Working
  • insert into mysql database, if records already exists, then update [duplicate]
  • Override all shipping costs for a specific shipping class in Woocommerce
  • jQuery Ajax call to WCF service returning “Method not allowed (405)”
  • PHP: Need to close STDIN in order to read STDOUT?
  • Windows biometric framework sample umdf driver: This device cannot start. (Code 10)
  • Spotify cocoalibspotify offline status set to 1 but all tracks stuck at waiting
  • How do I use libcurl to printf a remote FTP directory listing?
  • Multiplying polynomials/simplifying like terms
  • Floating parent div grows to hypothetical width of floating child div
  • Android: Unable to detect vertical plane
  • Send array to next viewcontroller iOs xcode [duplicate]
  • Debug `Unexpected end of JSON input Error` on content script
  • Apple Mach-O Linker error (“duplicate symbol”)
  • Codeigniniter insert data through models and controller
  • Sign a Pdf using custom digital signature in Java
  • Angular FormGroup won't update it's value immediately after patchValue or setValue
  • PHP Permalinks.. how to change?
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?