Fix Gradle MPP integration tests

#KT-30056 Fixed
This commit is contained in:
Kirill Shmakov
2019-02-27 20:51:04 +03:00
parent 3756b6f54d
commit 262b3fde3d
27 changed files with 183 additions and 30 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle
@@ -1171,28 +1171,28 @@ class NewMultiplatformIT : BaseGradleIT() {
fun testPublishMultimoduleProjectWithMetadata() = doTestPublishMultimoduleProject(withMetadata = true)
private fun doTestPublishMultimoduleProject(withMetadata: Boolean) {
val libProject = Project("sample-lib", gradleVersion, "new-mpp-lib-and-app").apply {
val libProject = Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")
libProject.setupWorkingDir()
val externalLibProject = Project("sample-external-lib", gradleVersion, "new-mpp-lib-and-app").apply {
if (withMetadata) {
setupWorkingDir()
// Make another publication that will be consumed as a module with metadata, see a similar conditional block below:
projectDir.resolve("settings.gradle").writeText("rootProject.name = 'external'; enableFeaturePreview 'GRADLE_METADATA'")
// Publish it into local repository of adjacent lib:
gradleBuildScript().appendText(
"\n" + """
group = "com.external.dependency"
version = "1.2.3"
publishing {
repositories {
maven { url "file://${'$'}{rootProject.projectDir.absolutePath.replace('\\', '/')}/repo" }
maven { url "file://${'$'}{rootProject.projectDir.absolutePath.replace('\\', '/')}/../sample-lib/repo" }
}
}
""".trimIndent()
)
build("publish") {
assertSuccessful()
gradleBuildScript().appendText("\ngroup = 'com.example'; version = '1.0'")
}
}
}
val appProject = Project("sample-app", gradleVersion, "new-mpp-lib-and-app")
with(libProject) {
@@ -0,0 +1,90 @@
group = "com.external.dependency"
version = "1.2.3"
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin-multiplatform'
repositories {
mavenLocal()
jcenter()
maven { url "https://dl.bintray.com/kotlin/kotlinx.html/" }
}
kotlin {
// Check the new preset functions:
jvm('jvm6') { }
js('nodeJs')
targetFromPreset(presets.wasm32) { println targetName }
targetFromPreset(presets.jvm, 'jvm6') { println targetName } // access existing target
targets {
// Also check that the old DSL (fromPreset) works:
fromPreset(presets.linuxX64, 'linux64')
fromPreset(presets.mingwX64, 'mingw64')
fromPreset(presets.macosX64, 'macos64')
// Check the DSL constructs in the Groovy DSL:
fromPreset(presets.jvm, 'jvm6') {
println "Configuring $targetName"
compilations.main {
kotlinOptions {
println "jvmTarget = " + jvmTarget
}
defaultSourceSet {
println "Kotlin srcDirs: " + kotlin.srcDirs
}
}
}
all {
mavenPublication {
pom.withXml {
asNode().appendNode('name', 'Sample MPP library')
}
}
}
}
sourceSets {
commonMain {
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-common'
}
}
jvm6Main {
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.23.4'
}
}
nodeJsMain {
dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-js'
implementation 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.11'
}
}
}
}
kotlin.sourceSets.each { println it.kotlin.srcDirs }
apply plugin: 'maven-publish'
// Check that a compilation may be created after project evaluation, KT-28896:
afterEvaluate {
kotlin {
jvm('jvm6').compilations.create('benchmark') {
defaultSourceSet.dependsOn(sourceSets.jvm6Main)
assemble.dependsOn compileKotlinTask
}
}
}
@@ -0,0 +1,2 @@
enableFeaturePreview('GRADLE_METADATA')
rootProject.name = 'external'
@@ -0,0 +1,5 @@
package com.example.externalLib
fun <T> id(t: T): T = t
expect fun expectedFun(): Unit
@@ -0,0 +1,7 @@
package com.example.externalLib
fun x(): String = "x"
actual fun expectedFun() {
println(id(x()))
}
@@ -0,0 +1,5 @@
package com.example.externalLib
actual fun expectedFun(): Unit {
id(123)
}
@@ -0,0 +1,5 @@
package com.example.externalLib
actual fun expectedFun(): Unit {
id(123)
}
@@ -0,0 +1,5 @@
package com.example.externalLib
actual fun expectedFun(): Unit {
id(123)
}
@@ -0,0 +1,12 @@
package com.example.externalLib
import com.example.externalLib.id
import com.example.externalLib.expectedFun
fun idUsage() = id("123")
actual fun expectedFun() = Unit
fun main(args: Array<String>) {
expectedFun()
}
@@ -0,0 +1,5 @@
package com.example.externalLib
actual fun expectedFun(): Unit {
id(123)
}
@@ -20,15 +20,10 @@ kotlin {
commonMain {
dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib-common"
}
}
iosMain {
dependencies {
api(project(":exported"))
}
}
commonTest {
dependencies {
api "org.jetbrains.kotlin:kotlin-test-annotations-common"
@@ -16,4 +16,8 @@ kotlin {
}
iosArm64("ios")
macosX64("macos64")
linuxX64("linux64")
mingwX64("mingw64")
iosX64("iosSim")
}
@@ -1,5 +1,8 @@
package foo
import com.example.exported
fun main() {
println("foo.main")
}
val exp = exported()
println("foo.main: exp = $exp")
}
@@ -1,11 +1,9 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
import com.example.exported
import kotlin.test.*
@Test
fun foo() {
println("tests.foo")
val exp = exported()
assertTrue(exp % 7 == 0, "Not divisible by 7")
println("tests.foo: exp = $exp")
}
@@ -12,11 +12,6 @@ kotlin {
sourceSets["commonMain"].apply {
dependencies {
api("org.jetbrains.kotlin:kotlin-stdlib-common")
}
}
sourceSets.create("iosMain").apply {
dependencies {
api(project(":exported"))
}
}
@@ -15,5 +15,9 @@ kotlin {
}
}
iosArm64("ios")
iosArm64("ios")
macosX64("macos64")
linuxX64("linux64")
mingwX64("mingw64")
iosX64("iosSim")
}
@@ -1,5 +1,8 @@
package foo
import com.example.exported
fun main() {
println("foo.main")
val exp = exported()
println("foo.main: exp = $exp")
}
@@ -1,6 +1,10 @@
import kotlin.test.*
import com.example.exported
@Test
fun foo() {
println("tests.foo")
val exp = exported()
assertTrue(exp % 7 == 0, "Not divisible by 7")
println("tests.foo: exp = $exp")
}