Skip to content

Commit

Permalink
MPP plugin: add expectedBy deps to "api" configuration
Browse files Browse the repository at this point in the history
Currently, KotlinPlatformJvmPlugin and KotlinPlatformJsPlugin are
adding expectedBy deps to "compile" configuration which is deprecated
by Gradle. This PR fixes that by replacing "compile" with "api" which
is what we are doing in KotlinPlatformAndroidPlugin.

This PR also makes integration tests running with warning-mode=fail by
default and fixes most of the integration tests. For the remaining tests
to be fixed, we make them run with warning-mode=summary and will fix
them incrementally in following PRs.
  • Loading branch information
bingranl authored and h0tk3y committed Nov 25, 2020
1 parent 4bf63a9 commit 52c22d8
Show file tree
Hide file tree
Showing 47 changed files with 141 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ abstract class BaseGradleIT {
return wrapper
}

fun mightUpdateSettingsScript(wrapperVersion: String, settingsScript: File) {
// enableFeaturePreview("GRADLE_METADATA") is no longer needed when building with Gradle 5.4 or above
if (GradleVersion.version(wrapperVersion) > GradleVersion.version("5.3")) {
settingsScript.apply {
if(exists()) {
modify {
it.replace("enableFeaturePreview('GRADLE_METADATA')", "//")
it.replace("enableFeaturePreview(\"GRADLE_METADATA\")", "//")
}
}
}
}
}

private fun createNewWrapperDir(version: String): File =
createTempDir("GradleWrapper-$version-")
.apply {
Expand Down Expand Up @@ -215,7 +229,7 @@ abstract class BaseGradleIT {
val jsCompilerType: KotlinJsCompilerType? = null,
val configurationCache: Boolean = false,
val configurationCacheProblems: ConfigurationCacheProblems = ConfigurationCacheProblems.FAIL,
val warningMode: WarningMode = WarningMode.Summary
val warningMode: WarningMode = WarningMode.Fail
)

enum class ConfigurationCacheProblems {
Expand Down Expand Up @@ -321,6 +335,9 @@ abstract class BaseGradleIT {

val env = createEnvironmentVariablesMap(options)
val wrapperDir = prepareWrapper(wrapperVersion, env)

mightUpdateSettingsScript(wrapperVersion, gradleSettingsScript())

val cmd = createBuildCommand(wrapperDir, params, options)

println("<=== Test build: ${this.projectName} $cmd ===>")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class BuildCacheRelocationIT : BaseGradleIT() {
override fun defaultBuildOptions(): BuildOptions =
super.defaultBuildOptions().copy(
withBuildCache = true,
androidGradlePluginVersion = AGPVersion.v3_6_0,
androidHome = KotlinTestUtils.findAndroidSdk()
)

Expand Down Expand Up @@ -65,7 +64,10 @@ class BuildCacheRelocationIT : BaseGradleIT() {
lateinit var firstOutputHashes: List<Pair<File, Int>>

workingDir = workingDirs[0]
firstProject.build(*testCase.taskToExecute) {
firstProject.build(
*testCase.taskToExecute,
options = defaultBuildOptions().copy(androidGradlePluginVersion = testCase.androidGradlePluginVersion)
) {
assertSuccessful()
firstOutputHashes = hashOutputFiles(outputRoots)
cacheableTaskNames.forEach { assertTaskPackedToCache(":$it") }
Expand All @@ -74,9 +76,10 @@ class BuildCacheRelocationIT : BaseGradleIT() {
workingDir = workingDirs[1]
val alternateBuildEnvOptions = if (withAnotherGradleHome) {
val alternateGradleHome = File(firstProject.projectDir.parentFile, "gradleUserHome")
defaultBuildOptions().copy(gradleUserHome = alternateGradleHome)
defaultBuildOptions().copy(
gradleUserHome = alternateGradleHome, androidGradlePluginVersion = testCase.androidGradlePluginVersion)
} else {
defaultBuildOptions()
defaultBuildOptions().copy(androidGradlePluginVersion = testCase.androidGradlePluginVersion)
}
secondProject.build(*testCase.taskToExecute, options = alternateBuildEnvOptions) {
assertSuccessful()
Expand All @@ -98,7 +101,8 @@ class BuildCacheRelocationIT : BaseGradleIT() {
val initProject: Project.() -> Unit = {},
val taskToExecute: Array<String>,
val withAnotherGradleHome: Boolean = false,
val gradleVersionRequired: GradleVersionRequired = DEFAULT_GRADLE_VERSION
val gradleVersionRequired: GradleVersionRequired = DEFAULT_GRADLE_VERSION,
val androidGradlePluginVersion: AGPVersion? = null
) {

override fun toString(): String = (projectDirectoryPrefix?.plus("/") ?: "") + projectName
Expand Down Expand Up @@ -157,7 +161,8 @@ class BuildCacheRelocationIT : BaseGradleIT() {
}
}
},
outputRootPaths = listOf("Lib", "Android", "Test").map { "$it/build" }
outputRootPaths = listOf("Lib", "Android", "Test").map { "$it/build" },
androidGradlePluginVersion = AGPVersion.v3_6_0
),
TestCase("android-dagger",
taskToExecute = arrayOf("assembleDebug"),
Expand All @@ -168,7 +173,8 @@ class BuildCacheRelocationIT : BaseGradleIT() {
}
},
outputRootPaths = listOf("app/build"),
initProject = { File(projectDir, "app/build.gradle").appendText("\nkapt.useBuildCache = true") }
initProject = { File(projectDir, "app/build.gradle").appendText("\nkapt.useBuildCache = true") },
androidGradlePluginVersion = AGPVersion.v3_6_0
),
TestCase("native-build-cache",
taskToExecute = arrayOf("build-cache-lib:publish", "build-cache-app:assemble"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.jetbrains.kotlin.gradle

import org.gradle.api.logging.configuration.WarningMode
import org.jetbrains.kotlin.gradle.util.AGPVersion
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Test
Expand All @@ -18,7 +19,8 @@ class ConfigurationCacheForAndroidIT : AbstractConfigurationCacheIT() {
androidHome = KotlinTestUtils.findAndroidSdk(),
androidGradlePluginVersion = androidGradlePluginVersion,
configurationCache = true,
configurationCacheProblems = ConfigurationCacheProblems.FAIL
configurationCacheProblems = ConfigurationCacheProblems.FAIL,
warningMode = WarningMode.Summary
)

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle

import com.google.gson.Gson
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.configuration.WarningMode
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.targets.js.ir.KLIB_TYPE
import org.jetbrains.kotlin.gradle.targets.js.npm.*
Expand All @@ -22,6 +23,11 @@ import kotlin.test.assertEquals
import kotlin.test.assertTrue

class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {

override fun defaultBuildOptions(): BuildOptions {
return super.defaultBuildOptions().copy(warningMode = WarningMode.Summary)
}

@Test
fun generateDts() {
val project = Project("kotlin2JsIrDtsGeneration")
Expand Down Expand Up @@ -116,6 +122,11 @@ class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {
}

class Kotlin2JsGradlePluginIT : AbstractKotlin2JsGradlePluginIT(false) {

override fun defaultBuildOptions(): BuildOptions {
return super.defaultBuildOptions().copy(warningMode = WarningMode.Summary)
}

@Test
fun testKotlinJsBuiltins() {
val project = Project("kotlinBuiltins")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.jetbrains.kotlin.gradle

import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.configuration.WarningMode
import org.jetbrains.kotlin.gradle.plugin.MULTIPLE_KOTLIN_PLUGINS_LOADED_WARNING
import org.jetbrains.kotlin.gradle.plugin.MULTIPLE_KOTLIN_PLUGINS_SPECIFIC_PROJECTS_WARNING
import org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
Expand All @@ -35,6 +36,10 @@ import kotlin.test.assertTrue

class KotlinGradleIT : BaseGradleIT() {

override fun defaultBuildOptions(): BuildOptions {
return super.defaultBuildOptions().copy(warningMode = WarningMode.Summary)
}

@Test
fun testCrossCompile() {
val project = Project("kotlinJavaProject")
Expand Down Expand Up @@ -774,12 +779,12 @@ class KotlinGradleIT : BaseGradleIT() {
with(Project("simpleProject")) {
setupWorkingDir()
// Add a dependency with an explicit lower Kotlin version that has a kotlin-stdlib transitive dependency:
gradleBuildScript().appendText("\ndependencies { compile 'org.jetbrains.kotlin:kotlin-reflect:1.2.71' }")
gradleBuildScript().appendText("\ndependencies { implementation 'org.jetbrains.kotlin:kotlin-reflect:1.2.71' }")
testResolveAllConfigurations {
assertSuccessful()
assertContains(">> :compile --> kotlin-reflect-1.2.71.jar")
assertContains(">> :compileClasspath --> kotlin-reflect-1.2.71.jar")
// Check that the default newer Kotlin version still wins for 'kotlin-stdlib':
assertContains(">> :compile --> kotlin-stdlib-${defaultBuildOptions().kotlinVersion}.jar")
assertContains(">> :compileClasspath --> kotlin-stdlib-${defaultBuildOptions().kotlinVersion}.jar")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class MultiplatformGradleIT : BaseGradleIT() {
${'\n'}
task printCompileConfiguration(type: DefaultTask) {
doFirst {
configurations.compile.resolvedConfiguration.resolvedArtifacts.each {
configurations.getByName("api").dependencies.each {
println("Dependency: '" + it.name + "'")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.gradle

import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.checkNativeCommandLineArguments
import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.containsSequentially
import org.gradle.api.logging.configuration.WarningMode
import org.jetbrains.kotlin.gradle.native.MPPNativeTargets
import org.jetbrains.kotlin.gradle.native.configureMemoryInGradleProperties
import org.jetbrains.kotlin.gradle.native.transformNativeTestProject
Expand Down Expand Up @@ -43,6 +44,10 @@ class NewMultiplatformIT : BaseGradleIT() {
private fun Project.targetClassesDir(targetName: String, sourceSetName: String = "main") =
classesDir(sourceSet = "$targetName/$sourceSetName")

override fun defaultBuildOptions(): BuildOptions {
return super.defaultBuildOptions().copy(warningMode = WarningMode.Summary)
}

@Test
fun testLibAndApp() = doTestLibAndApp(
"sample-lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.jetbrains.kotlin.gradle

import org.gradle.api.logging.configuration.WarningMode
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.util.*
import org.junit.Test
Expand All @@ -13,6 +14,10 @@ import kotlin.test.assertTrue
class VariantAwareDependenciesIT : BaseGradleIT() {
private val gradleVersion = GradleVersionRequired.FOR_MPP_SUPPORT

override fun defaultBuildOptions(): BuildOptions {
return super.defaultBuildOptions().copy(warningMode = WarningMode.Summary)
}

@Test
fun testJvmKtAppResolvesMppLib() {
val outerProject = Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.jetbrains.kotlin.gradle.native

import com.intellij.testFramework.TestDataFile
import org.gradle.api.logging.configuration.WarningMode
import org.jdom.input.SAXBuilder
import org.jetbrains.kotlin.gradle.BaseGradleIT
import org.jetbrains.kotlin.gradle.GradleVersionRequired
Expand Down Expand Up @@ -93,6 +94,10 @@ class GeneralNativeIT : BaseGradleIT() {
override val defaultGradleVersion: GradleVersionRequired
get() = GradleVersionRequired.FOR_MPP_SUPPORT

override fun defaultBuildOptions(): BuildOptions {
return super.defaultBuildOptions().copy(warningMode = WarningMode.Summary)
}

@Test
fun testParallelExecutionSmoke(): Unit = with(transformNativeTestProjectWithPluginDsl("native-parallel")) {
// Check that the K/N compiler can be started in-process in parallel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ repositories {
}

dependencies {
compile 'com.google.guava:guava:12.0'
testCompile 'org.testng:testng:6.8'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.google.guava:guava:12.0'
testImplementation 'org.testng:testng:6.8'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ repositories {
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ repositories {
}

dependencies {
compile 'com.google.guava:guava:12.0'
testCompile 'org.testng:testng:6.8'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.google.guava:guava:12.0'
testImplementation 'org.testng:testng:6.8'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repositories {
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

compileJava {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ repositories {
}

dependencies {
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

compileKotlin.compilerJarFile = project.file("compiler.jar")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apply plugin: 'kotlin'

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apply plugin: 'kotlin'

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile project(':lib-project')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation project(':lib-project')
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ repositories {
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-js:$kotlin_version"
}

task jarSources(type: Jar) {
from sourceSets.main.allSource
classifier = 'source'
}
artifacts {
compile jarSources
implementation jarSources
}

compileKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/main/module.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ repositories {
}

dependencies {
testCompile 'org.testng:testng:6.8'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testImplementation 'org.testng:testng:6.8'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ apply plugin: 'java'
apply plugin: 'kotlin'

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile project(':libB')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation project(':libB')
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repositories {
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

compileKotlin.javaPackagePrefix = "my.pack.name"
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repositories {
}

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

compileKotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ apply plugin: "kotlin"
apply plugin: "kotlin-kapt"

dependencies {
compile project(":lib")
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation project(":lib")
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

compile "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
implementation "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
kapt "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"

// actually unused, but kapt skips AP when annotation processing classpath is empty (see checkOptions)
Expand Down
Loading

0 comments on commit 52c22d8

Please sign in to comment.