Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

correct gradle configuration #31

Closed
simonegiacomelli opened this issue Mar 17, 2019 · 3 comments
Closed

correct gradle configuration #31

simonegiacomelli opened this issue Mar 17, 2019 · 3 comments

Comments

@simonegiacomelli
Copy link

simonegiacomelli commented Mar 17, 2019

This is not strictly related to klock; but this is the only library I care to use in a kotlin multiplatform project.

Please could you be more specific where to put:
implementation "com.soywiz:klock:$klockVersion" ?

I struggle to keep up with gradle changes in kotlin multiplatform project...

I'm using default multiplatform project created by intelliJ (JVM/JS).
This is an excerpt from my unique build.gradle:

plugins {
     id 'kotlin-multiplatform' version '1.3.21'
}
@soywiz
Copy link
Collaborator

soywiz commented Mar 17, 2019

Can you try the instructions provided in the README? If they work for you I will merge the PR, or adjust it until it is clear.

@simonegiacomelli
Copy link
Author

simonegiacomelli commented Mar 17, 2019

Thanks! Now it works.

In the beginning I thought that commonMainApi, jvmMainApi, jsMainApi were functions of gradle that were doing some magic instead of 'implementation' but It wasn't so.
So I just used 'implementation' instead of them.

I will paste here my working build.gradle (in the hope it can be helpful to others)

buildscript {
    repositories {
        jcenter()
    }
}

plugins {
    id 'kotlin-multiplatform' version '1.3.21'
}
repositories {
    jcenter()
    maven { url "http://dl.bintray.com/kotlin/ktor" }
    mavenCentral()
    maven { url "https://dl.bintray.com/soywiz/soywiz" }
}
def ktor_version = '1.0.1'
def logback_version = '1.2.3'
def klockVersion = "1.3.1"

kotlin {
    jvm()
    js() {
        compilations.all {
            kotlinOptions {
                languageVersion = "1.3"
                moduleKind = "umd"
                sourceMap = true
                metaInfo = true
            }
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
                implementation "com.soywiz:klock-metadata:$klockVersion"
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        jvmMain {
            dependencies {
                implementation kotlin('stdlib-jdk8')
                implementation "io.ktor:ktor-server-netty:$ktor_version"
                implementation "io.ktor:ktor-html-builder:$ktor_version"
                implementation "ch.qos.logback:logback-classic:$logback_version"
                implementation 'net.sf.biweekly:biweekly:0.6.3'
                implementation "com.soywiz:klock-jvm:$klockVersion"
            }
        }
        jvmTest {
            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
            }
        }
        jsMain {
            dependencies {
                implementation kotlin('stdlib-js')
                implementation "com.soywiz:klock-js:$klockVersion"
            }
        }
        jsTest {
            dependencies {
                implementation kotlin('test-js')
            }
        }
    }
}

def webFolder = new File(project.buildDir, "../src/jsMain/web")
def jsCompilations = kotlin.targets.js.compilations

task populateWebFolder(dependsOn: [jsMainClasses]) {
    doLast {
        copy {
            from jsCompilations.main.output
            from kotlin.sourceSets.jsMain.resources.srcDirs
            jsCompilations.test.runtimeDependencyFiles.each {
                if (it.exists() && !it.isDirectory()) {
                    from zipTree(it.absolutePath).matching { include '*.js' }
                }
            }
            into webFolder
        }
    }
}

jsJar.dependsOn(populateWebFolder)

task run(type: JavaExec, dependsOn: [jvmMainClasses, jsJar]) {
    main = "sample.SampleJvmKt"
    classpath { [
            kotlin.targets.jvm.compilations.main.output.allOutputs.files,
            configurations.jvmRuntimeClasspath,
    ] }
    args = []
}

@webfrea-k
Copy link

I have pretty much the same build.gradle as @simonegiacomelli . However, I also have the iOS source set, which is combined into iOSMain:

iOSMain.dependencies {
            implementation "io.ktor:ktor-client-ios:$ktor_version"
            implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
            implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
}
configure([ios_arm64Main, ios_x86_64Main]) {
            dependsOn iOSMain
        }

Adding Klock -iosx64 breaks iosarm64 build and vice-versa.
What would be the correct way to include Klock for iOS simulator (x64) and real device (arm64) in the example above?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants