SciProgCentre / plotly.kt

An interactive Kotlin wrapper for plotly visualization tools
https://sciprogcentre.github.io/plotly.kt/
Apache License 2.0
150 stars 21 forks source link

Common dependency is empty / doesn't work? #8

Closed natanfudge closed 5 years ago

natanfudge commented 5 years ago

Hey, I made a new Kotlin Multi Platform project with the following build.gradle:

plugins {
    id 'org.jetbrains.kotlin.multiplatform' version '1.3.40'
}
repositories {
    mavenCentral()
    maven { url "https://dl.bintray.com/mipt-npm/scientifik/"}
}
group 'com.example'
version '0.0.1'

apply plugin: 'maven-publish'

kotlin {
    jvm()
    js {
        browser {
        }
        nodejs {
        }
    }
    // For ARM, should be changed to iosArm32 or iosArm64
    // For Linux, should be changed to e.g. linuxX64
    // For MacOS, should be changed to e.g. macosX64
    // For Windows, should be changed to e.g. mingwX64
    mingwX64("mingw")
    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
                implementation "scientifik:plotlykt-core:0.1.1"
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        jvmMain {
            dependencies {
                implementation kotlin('stdlib-jdk8')
            }
        }
        jvmTest {
            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
            }
        }
        jsMain {
            dependencies {
                implementation kotlin('stdlib-js')
            }
        }
        jsTest {
            dependencies {
                implementation kotlin('test-js')
            }
        }
        mingwMain {
        }
        mingwTest {
        }
    }
}

Although trying to import scientifik.* does not compile. I tried again in a gradle-jvm project:

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.40'
}

group 'plot'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    maven { url "https://dl.bintray.com/mipt-npm/scientifik/"}
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    compile 'scientifik:plotlykt-core:0.1.1'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}

And still no luck. If I change scientifik:plotlykt-core:0.1.1 to scientifik:plotlykt-core-jvm:0.1.1 it does work seems to work, but build failes. Please explain how to use the library as a dependency.

altavir commented 5 years ago

Do you have this line in your settings.gradle?

Kotlin multiplatform relies on gradle metadata to resolve different artifacts from the same name. Basically, scientifik:plotlykt-core and scientifik:plotlykt-core-jvm are two different projects, and you need to add a specific dependency for each of your platforms. If you have gradle metadata enabled, then your kotlin plugin could find appropriate platform artifact from the root dependency (scientifik:plotlykt-core). I've tested it and it seemed to be working with gradle metadata enabled: https://github.com/mipt-npm/plotly.kt/blob/dev/examples/build.gradle.kts.

natanfudge commented 5 years ago

I do have that line. I updated the build.gradle with the common, jvm, and js dependencies of the library, still doesn't work. Try to see if you have the same issue with this project: https://github.com/natanfudge/plotlyktmpptest

altavir commented 5 years ago

You have multiple problems in the build. The major one is that you seem to have old gradle wrapper, 4.11 does not seem to properly support metadata feature (try to use 5+). Second, you do not have all repositories. It should look like this:

repositories {
    jcenter()
    maven{ url = "https://dl.bintray.com/mipt-npm/dataforge"}
    maven{ url = "https://dl.bintray.com/mipt-npm/scientifik"}
    maven{ url = "https://kotlin.bintray.com/kotlinx"}
//    maven{ url = "https://dl.bintray.com/kotlin/ktor/"}
}

And finally, you should comment native targets. Currently, we do not support them. If you want native target, we can try to add it, but then please add a separate feature request.

Thanks for this issue, I will update README with proper build instructions.

altavir commented 5 years ago

I found that all but gradle version is already in readme in dev branch: https://github.com/mipt-npm/plotly.kt/tree/dev. I will merge it later.