JetBrains / lets-plot-kotlin

Grammar of Graphics for Kotlin
https://lets-plot.org/kotlin/
MIT License
419 stars 36 forks source link

How to use lets-plot-kotlin in modular JavaFX application? #69

Closed icuxika closed 3 years ago

icuxika commented 3 years ago

I have successfully used it in a non-module JavaFX project, but I don't know how to use it in a modular javafx project.

dependencies {
    implementation(kotlin("stdlib"))
    implementation(kotlin("reflect"))
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")

    implementation("org.openjfx:javafx-base:16:${platform}")
    implementation("org.openjfx:javafx-controls:16:${platform}")
    implementation("org.openjfx:javafx-graphics:16:${platform}")
    implementation("org.openjfx:javafx-fxml:16:${platform}")
    implementation("org.openjfx:javafx-swing:16:${platform}")
    implementation("org.openjfx:javafx-media:16:${platform}")
    implementation("org.openjfx:javafx-web:16:${platform}")
    implementation("com.jfoenix:jfoenix:9.0.10")

    implementation("org.jetbrains.lets-plot:lets-plot-jfx:2.0.2") {
        exclude(group = "org.jetbrains.lets-plot", module = "lets-plot-common")
        exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-html-jvm")
    }
    implementation("org.jetbrains.lets-plot:lets-plot-image-export:2.0.2") {
        exclude(group = "xml-apis", module = "xml-apis")
        exclude(group = "xml-apis", module = "xml-apis-ext")
    }
    implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.3") {
        exclude(group = "org.jetbrains.lets-plot", module = "lets-plot-common")
    }
//    implementation("org.jetbrains.lets-plot:lets-plot-common:2.0.2") {
//        exclude(group = "org.jetbrains.kotlin", module = "kotlin-reflect")
//        exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
//    }
    implementation("org.jetbrains.lets-plot:lets-plot-kotlin-api:2.0.1") {
        exclude(group = "org.jetbrains.lets-plot", module = "lets-plot-common")
    }
}

tasks.compileJava {
    options.compilerArgs.addAll(listOf("--module-path", classpath.asPath))
}

I configure my project with the code shown above,but gradle run gives me lots of output like javafx.controlsEmpty reads package jetbrains.datalore.plot from both lets.plot.jfx and lets.plot.image.export.

Actually, I have excluded xml-apis from lets-plot-image-export, which has reduced a lot of errors.

Now I don’t know how to continue to deal with this problem.

alshan commented 3 years ago

Try: ./gradlew :<project>:dependencies

or (for root): ./gradlew :dependencies

to see where are duplicates coming from and exclude them where necessary.

icuxika commented 3 years ago

@alshan Thank you for your reply. I used a gradle plugin extraJavaModuleInfo in my project. Then I can execute gradle run to run the program. But there are some problems when I try to package the applicaiton. So I temporarily adopted a non-modular way to complete the goal.

Modular project: KtFX-Lets-Plot(master) Non-modular proejct: KtFX-Lets-Plot(non-modular)