Skip to content

Commit

Permalink
This commit resolves the warning when compileOnly dependencies are us…
Browse files Browse the repository at this point in the history
…ed for Native targets. It adds kotlin-stdlib dependency as an implementation dependency, though it marks it's version as prefered to avoid resolution in the user project.
  • Loading branch information
mvicsokolova committed Jan 9, 2024
1 parent 6a066e2 commit e6206c5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
6 changes: 5 additions & 1 deletion atomicfu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ kotlin {
sourceSets {
commonMain {
dependencies {
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib'
implementation('org.jetbrains.kotlin:kotlin-stdlib') {
version {
prefer "$kotlin_version"
}
}
}
}
commonTest {
Expand Down
1 change: 1 addition & 0 deletions integration-testing/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ val functionalTest by tasks.registering(Test::class) {
testClassesDirs = sourceSets["functionalTest"].output.classesDirs
classpath = sourceSets["functionalTest"].runtimeClasspath

systemProperties["kotlinVersion"] = kotlin_version
systemProperties["atomicfuVersion"] = atomicfu_snapshot_version

dependsOn(":atomicfu-gradle-plugin:publishToMavenLocal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,29 @@ class PluginOrderBugTest {
val buildResult = pluginOrderBugProject.cleanAndBuild()
assertTrue(buildResult.isSuccessful, buildResult.output)
}


/**
* Ensures that the version of atomicfu compiler plugin in the project's classpath equals the version of KGP used in the project.
*/
@Test
fun testResolvedCompilerPluginDependency() {
val buildDependencies = pluginOrderBugProject.buildEnvironment()
val classpath = pluginOrderBugProject.getProjectClasspath()
val kpg = classpath.firstOrNull { it.startsWith("org.jetbrains.kotlin:kotlin-gradle-plugin") }
?: error("kotlin-gradle-plugin is not found in the classpath of the project ${pluginOrderBugProject.projectName}")
val kgpVersion = kpg.substringAfterLast(":")
assertTrue(classpath.contains("org.jetbrains.kotlin:atomicfu:$kgpVersion"))
assertTrue(classpath.contains("org.jetbrains.kotlin:atomicfu:${pluginOrderBugProject.getKotlinVersion()}"))
}

/**
* kotlin-stdlib is an implementation dependency of :atomicfu module,
* because compileOnly dependencies are not applicable for Native targets (#376).
*
* This test ensures that kotlin-stdlib of the Kotlin version used to build kotlinx-atomicfu library is not "required" in the user's project.
* The user project should use kotlin-stdlib version that is present in it's classpath.
*/
@Test
fun testTransitiveKotlinStdlibDependency() {
val dependencies = pluginOrderBugProject.dependencies()
assertFalse(dependencies.output.contains("org.jetbrains.kotlin:kotlin-stdlib:{strictly $libraryKotlinVersion}"),
"Strict requirement for 'org.jetbrains.kotlin:kotlin-stdlib:{strictly $libraryKotlinVersion}' was found in the project ${pluginOrderBugProject.projectName} dependencies, " +
"while Kotlin version used in the project is ${pluginOrderBugProject.getKotlinVersion()}"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package kotlinx.atomicfu.gradle.plugin.test.framework.runner

import kotlinx.atomicfu.gradle.plugin.test.framework.checker.getProjectClasspath

internal fun GradleBuild.cleanAndBuild(): BuildResult = runGradle(listOf("clean", "build"))

internal fun GradleBuild.dependencies(): BuildResult =
Expand All @@ -20,3 +22,10 @@ internal fun GradleBuild.publishToLocalRepository(): BuildResult =
runGradle(listOf("clean", "publish")).also {
require(it.isSuccessful) { "${this.projectName}:publish task FAILED: ${it.output} " }
}

internal fun GradleBuild.getKotlinVersion(): String {
val classpath = getProjectClasspath()
val kpg = classpath.firstOrNull { it.startsWith("org.jetbrains.kotlin:kotlin-gradle-plugin") }
?: error("kotlin-gradle-plugin is not found in the classpath of the project $projectName")
return kpg.substringAfterLast(":")
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal const val LOCAL_REPOSITORY_URL_PROPERTY = "localRepositoryUrl"
internal const val DUMMY_VERSION = "DUMMY_VERSION"
internal const val LOCAL_REPO_DIR_PREFIX = "build/.m2/"

internal val libraryKotlinVersion = System.getProperty("kotlinVersion")
internal val atomicfuVersion = System.getProperty("atomicfuVersion")

internal val gradleWrapperDir = File("..")
Expand Down

0 comments on commit e6206c5

Please sign in to comment.