edvin / tornadofx

Lightweight JavaFX Framework for Kotlin
Apache License 2.0
3.68k stars 272 forks source link

Kotlin Gradle languages support #709

Open jagiellonczyk14 opened 6 years ago

jagiellonczyk14 commented 6 years ago

Hi I am creating app with gradle. On intelij it works perfectly , hovewer after creating jar files letters like śćż and others that are coded in UTF 8 are not displayed correctly, alhough theoretically kotlin is automatically on UTF 8, what can I do? Below is my build gradle buildscript { ext.kotlin_version = '1.2.21'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'

    }
}

group 'kotlinGradleNucHelp'
version '1.0'

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'org.junit.platform.gradle.plugin'

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {

    }
}
sourceCompatibility = 1.8

repositories {
    jcenter()
    mavenLocal()
    mavenCentral()
    maven { url "https://dl.bintray.com/kotlin/exposed" }
    maven { url "http://repo.maven.apache.org/maven2" }
    maven { url "http://dl.bintray.com/jetbrains/spek" }
}
jar {
    from {
        (configurations.runtime).collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    manifest {
        attributes 'Main-Class': 'MyMiniFramework.app.main.MyApp'
    }
}
junitPlatform {
    filters {
        engines {
            include 'spek'
        }
    }
}
dependencies {

    compile group: 'com.h2database', name: 'h2', version: '1.4.196'
    compile 'org.jetbrains.exposed:exposed:0.10.1'
    compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.3'
    compile 'com.github.salomonbrys.kotson:kotson:2.5.0'
    compile 'com.jfoenix:jfoenix:8.0.1'
    compile'org.controlsfx:controlsfx:8.40.10'
    compile'org.docx4j:docx4j:3.0.0'
    compile 'no.tornado:tornadofx:1.7.14'
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
    compile group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.10.0'
    compile 'com.squareup:kotlinpoet:0.7.0'
    compile "org.jetbrains.spek:spek-api:1.1.5"
    testCompile 'com.nhaarman:mockito-kotlin:1.5.0'
    testCompile(group: "org.testfx", name: "testfx-core", version: "4.0.8-alpha")
    testCompile(group: "org.testfx", name: "testfx-junit", version: "4.0.8-alpha")
    testCompile 'org.jetbrains.spek:spek-api:1.1.5'
    testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.5'
    testCompile 'junit:junit:4.12'

}

jar {
    jar.baseName = 'Facit'
//    manifest {
//        attributes(
//                'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
//                'Main-Class': 'MyMiniFramework.app.MyApp'
//        )
//    }
    from(configurations.compile.collect { entry -> zipTree(entry) }) {
        exclude 'META-INF/MANIFEST.MF'
        exclude 'META-INF/*.SF'
        exclude 'META-INF/*.DSA'
        exclude 'META-INF/*.RSA'
    }
}
test {
    project.buildDir = 'C:\\Users\\jagie\\Desktop'
    systemProperty "file.encoding", "utf-8"

}
    compileKotlin {
        kotlinOptions.jvmTarget = "1.8"

    }
    compileTestKotlin {
        kotlinOptions.jvmTarget = "1.8"

    }

P.S I all of my strings are stored in JSON and retrieved by gson and kotson libraries, still before packaging it works perfectly.

kastork commented 6 years ago

This isn't an answer, but a suggestion for tracking down an answer.

    from {
        (configurations.runtime).collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }

With so many dependencies, you might be clobbering one library's transitive dependency with another's. That is, for the transitive dependencies, the class loading order you get when you run in IDEA might be different from what you get in this "uber" jar file you're making. You might consider replacing that manual process with the shadow plugin and see if you get different results.

Plugin repo: https://github.com/johnrengelman/shadow

The plugin has fairly robust transitive dependency filtering capabilities, but as the author points out, the specifics of what you filter is still up to you. Pertinent part of docs: http://imperceptiblethoughts.com/shadow/#filtering_dependencies

buildscript {
    ext.shadow_version = '2.0.3'

    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.github.jengelman.gradle.plugins:shadow:$shadow_version"
    }
}

apply plugin: 'com.github.johnrengelman.shadow'