buildscript { repositories { maven { url 'https://plugins.gradle.org/m2/' } mavenCentral() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin" classpath "org.jetbrains.kotlin:kotlin-serialization:$version_kotlin" classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$version_atomicfu" } } apply plugin: "kotlin-multiplatform" apply plugin: "kotlinx-atomicfu" apply plugin: 'kotlinx-serialization' apply plugin: 'com.android.library' apply plugin: 'jacoco' apply plugin: "maven-publish" android { compileSdkVersion rootProject.ext.version_android_compile_sdk buildTypes { release { consumerProguardFiles 'proguard-rules.pro' } } packagingOptions { resources { excludes += ['META-INF/INDEX.LIST', '**/*.kotlin_metadata', 'META-INF/*.kotlin_module', 'licenses/**.TXT'] } } defaultConfig { minSdkVersion 21 targetSdkVersion 31 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } compileOptions { sourceCompatibility = '1.8' targetCompatibility = '1.8' } testOptions { unitTests { returnDefaultValues = true } } lint { abortOnError false } namespace 'com.ustadmobile.port.sharedse' tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { kotlinOptions { jvmTarget = "1.8" } } } sourceCompatibility = '1.8' targetCompatibility = '1.8' group rootProject.group version rootProject.version kotlin { jvm { compilations.main.kotlinOptions { // Setup the Kotlin compiler options for the 'main' compilation: jvmTarget = "$version_kotlin_jvmTarget" } compilations.test.kotlinOptions { // Setup the Kotlin compiler options for the 'main' compilation: jvmTarget = "$version_kotlin_jvmTarget" } } //Unfortunately there isn't really an elegant way to create a sourceset for one module //The section below can be uncommented for development so that autocomplete works for JVM libraries // see https://youtrack.jetbrains.com/issue/KT-28194 // It should be commented out again before running jvmTest. /*jvm("commonJvm") { compilations.main.kotlinOptions { // Setup the Kotlin compiler options for the 'main' compilation: jvmTarget = "$version_kotlin_jvmTarget" } }*/ android() jvm { compilations.main.kotlinOptions { // Setup the Kotlin compiler options for the 'main' compilation: jvmTarget = "$version_kotlin_jvmTarget" } } sourceSets { commonMain { dependencies { implementation project(":core") implementation project(":lib-util") implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$version_kotlin" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version_coroutines" implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$version_kotlinx_serialization" implementation "io.ktor:ktor-client-core:$version_ktor" implementation "io.ktor:ktor-client-json:$version_ktor" implementation "io.ktor:ktor-io:$version_ktor" implementation "io.ktor:ktor-gson:$version_ktor" implementation "io.github.aakira:napier:$version_napier" implementation "org.kodein.di:kodein-di:$version_kodein_di" implementation "com.github.UstadMobile.door:door-runtime:$version_door" compileOnly project(':lib-database') compileOnly project(':lib-database-entities') compileOnly "com.github.UstadMobile.door:room-annotations:$version_door" implementation "com.ustadmobile.xmlpullparserkmp:xmlpullparserkmp:$version_xmlpullparserkmp" } } commonJvmMain { dependencies { implementation project(":lib-database-entities") compileOnly project(':lib-database') implementation "org.nanohttpd:nanohttpd:$version_nanohttpd" implementation "org.nanohttpd:nanohttpd-nanolets:$version_nanohttpd" implementation "com.squareup.okhttp3:okhttp:$version_okhttp" implementation "net.sf.kxml:kxml2:$version_kxml" implementation "com.google.code.gson:gson:$version_gson" implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$version_kotlinx_serialization" implementation "com.neovisionaries:nv-i18n:$version_nv_lang" implementation "io.ktor:ktor-client-okhttp:$version_ktor" implementation "io.ktor:ktor-client-cio:$version_ktor" implementation "io.ktor:ktor-client-gson:$version_ktor" implementation "io.ktor:ktor-io-jvm:$version_ktor" implementation "org.kodein.di:kodein-di:$version_kodein_di" implementation "com.ustadmobile.xmlpullparserkmp:xmlpullparserkmp:$version_xmlpullparserkmp" } } /* Normally we would add a sourceSet and then use dependsOn. Unfortunately this does not work when running unit tests in the IDE. */ androidMain { dependsOn commonJvmMain dependencies { implementation project(":lib-database-android") implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version_kotlin" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version_coroutines" implementation "androidx.lifecycle:lifecycle-livedata:$version_androidx_lifecycle" implementation "androidx.lifecycle:lifecycle-livedata-ktx:$version_androidx_lifecycle" implementation "androidx.work:work-runtime:$version_android_workmanager" implementation project(":lib-database-android") implementation "org.kodein.di:kodein-di-framework-android-x:$version_kodein_di" implementation "androidx.room:room-runtime:$version_android_room" implementation "com.google.android.material:material:$version_android_material" implementation "io.ktor:ktor-client-okhttp:$version_ktor" implementation "io.ktor:ktor-client-cio:$version_ktor" implementation "io.ktor:ktor-client-gson:$version_ktor" implementation "org.nanohttpd:nanohttpd:$version_nanohttpd" implementation "org.nanohttpd:nanohttpd-nanolets:$version_nanohttpd" //Begin SharedSE Android and JVM dependencies implementation "org.nanohttpd:nanohttpd:$version_nanohttpd" implementation "org.nanohttpd:nanohttpd-nanolets:$version_nanohttpd" implementation "com.squareup.okhttp3:okhttp:$version_okhttp" implementation "com.google.code.gson:gson:$version_gson" //end SharedSE Android and JVM dependencies } } jvmMain { dependsOn commonJvmMain dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version_kotlin" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version_coroutines" implementation "io.ktor:ktor-client-okhttp:$version_ktor" implementation "io.ktor:ktor-client-gson:$version_ktor" //Begin Android and JVM dependencies implementation "org.nanohttpd:nanohttpd:$version_nanohttpd" implementation "org.nanohttpd:nanohttpd-nanolets:$version_nanohttpd" implementation "com.squareup.okhttp3:okhttp:$version_okhttp" implementation "com.google.code.gson:gson:$version_gson" //end Android and JVM dependencies } } commonTest { dependencies { } } jvmTest { dependencies { implementation project(":lib-database-mpp") implementation project(":lib-database-entities") implementation project(":lib-database") implementation project(":lib-test-common") implementation "io.github.aakira:napier:$version_napier" implementation "com.soywiz.korlibs.klock:klock:$version_klock" implementation "junit:junit:$version_junit" implementation "io.ktor:ktor-server-netty:$version_ktor" implementation "com.squareup.okhttp3:mockwebserver:$version_mockwebserver" implementation "com.squareup.okhttp3:okhttp:$version_okhttp" implementation "io.github.aakira:napier-jvm:$version_napier" implementation "org.mockito.kotlin:mockito-kotlin:$version_kotlin_mockito" implementation "com.soywiz.korlibs.klock:klock-jvm:$version_klock" implementation "com.github.h-thurow:simple-jndi:$version_simple_jndi" implementation "org.apache.commons:commons-pool2:$version_apache_commons_pool2" implementation "org.xerial:sqlite-jdbc:$version_sqlite_jdbc" implementation "org.apache.commons:commons-dbcp2:$version_apache_commons_dbcp2" implementation "org.kodein.di:kodein-di-framework-ktor-server-jvm:$version_kodein_di" api project(":sharedse") api project(":lib-database-mpp") api project(":app-ktor-server") } } } } /* * This might be required to be able to run unit tests via the IDE. */ task copyTestResources(type: Copy) { outputs.upToDateWhen { project.file("build/local.env.properties").exists() } from project.file("src/commonTest/resources") into rootProject.file("build/classes/test/sharedse_jvmTest") doFirst { println("Dump sharedse local.env.properties") if (!project.file("build").exists()) project.file("build").mkdir() def outWriter = new FileWriter(project.file("build/local.env.properties")) System.getProperties().store(outWriter, "System properties for use with running unit tests in IDE") outWriter.flush() outWriter.close() } } tasks.whenTaskAdded { task -> if (task.name == "compileTestKotlinJvm") { println("Add task to jvmTest") task.dependsOn(copyTestResources) } } jvmTest.dependsOn(copyTestResources) jacoco { toolVersion = "$version_jacoco_tool" } /** * Create a Jacocco task for reporting test coverage - as per: * https://medium.com/@aldychris/kotlin-multiplatform-for-ios-and-android-mobile-application-96a753e175f7 */ //TODO: Fix this so we can have a coverage report for jvmTest //project.afterEvaluate { // def testTaskName = "jvmTest" // // // Create gradle task // task "jvmJacocoTestReport" (type:JacocoReport, dependsOn: "$testTaskName") { // group = "Reporting" // description = "Generate Jacoco coverage reports on the common module build." // // def excludes = [ // '**/*Test*.*' // ] // // classDirectories = fileTree( // dir: "${project.buildDir}/classes/kotlin/jvm/", // excludes: excludes // ) // // def coverageSourceDirs = [ // "src/commonMain/kotlin" // ] // // additionalSourceDirs = files(coverageSourceDirs) // sourceDirectories = files(coverageSourceDirs) // executionData = files("${project.buildDir}/jacoco/jvmTest.exec") // // reports { // xml.enabled = true // html.enabled = true // } // } //} publishing { publications { maven(MavenPublication) { groupId rootProject.group artifactId project.name version rootProject.version } } repositories { maven { url rootProject.ext.buildConfigProperties['repo.dir'] } } }