Skip to content

Commit 5118405

Browse files
mazhukinevgeniySpace Team
authored and
Space Team
committed
[KGP] Make kotlin.build.archivesTaskOutputAsFriendModule property public
Add functional test
1 parent 623edef commit 5118405

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

libraries/stdlib/gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
kotlin.internal.suppressGradlePluginErrors=PreHMPPFlagsError
22
kotlin.mpp.enableCompatibilityMetadataVariant=true
33
kotlin.internal.mpp.createDefaultMultiplatformPublications=false
4-
kotlin.internal.archivesTaskOutputAsFriendModule=false
4+
kotlin.build.archivesTaskOutputAsFriendModule=false

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ internal class PropertiesProvider private constructor(private val project: Proje
709709
val KOTLIN_APPLE_COCOAPODS_EXECUTABLE = property("kotlin.apple.cocoapods.bin")
710710
val KOTLIN_APPLE_ALLOW_EMBED_AND_SIGN_WITH_COCOAPODS = property("kotlin.apple.deprecated.allowUsingEmbedAndSignWithCocoaPodsDependencies")
711711
val KOTLIN_SWIFT_EXPORT_ENABLED = property("kotlin.swift-export.enabled")
712+
val KOTLIN_NATIVE_ENABLE_KLIBS_CROSSCOMPILATION = property("kotlin.native.enableKlibsCrossCompilation")
713+
val KOTLIN_ARCHIVES_TASK_OUTPUT_AS_FRIEND_ENABLED = property("kotlin.build.archivesTaskOutputAsFriendModule")
712714

713715
/**
714716
* Internal properties: builds get big non-suppressible warning when such properties are used
@@ -728,7 +730,6 @@ internal class PropertiesProvider private constructor(private val project: Proje
728730
property("$KOTLIN_INTERNAL_NAMESPACE.incremental.enableUnsafeOptimizationsForMultiplatform")
729731
val KOTLIN_KLIBS_KT64115_WORKAROUND_ENABLED = property("$KOTLIN_INTERNAL_NAMESPACE.klibs.enableWorkaroundForKT64115")
730732
val KOTLIN_COLLECT_FUS_METRICS_ENABLED = property("$KOTLIN_INTERNAL_NAMESPACE.collectFUSMetrics")
731-
val KOTLIN_ARCHIVES_TASK_OUTPUT_AS_FRIEND_ENABLED = property("$KOTLIN_INTERNAL_NAMESPACE.archivesTaskOutputAsFriendModule")
732733
}
733734

734735
companion object {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
@file:Suppress("FunctionName")
7+
8+
package org.jetbrains.kotlin.gradle.regressionTests
9+
10+
import org.gradle.api.internal.project.ProjectInternal
11+
import org.jetbrains.kotlin.gradle.dependencyResolutionTests.mavenCentralCacheRedirector
12+
import org.jetbrains.kotlin.gradle.dsl.kotlinJvmExtension
13+
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_ARCHIVES_TASK_OUTPUT_AS_FRIEND_ENABLED
14+
import org.jetbrains.kotlin.gradle.plugin.mpp.decoratedInstance
15+
import org.jetbrains.kotlin.gradle.util.*
16+
import kotlin.test.Test
17+
import kotlin.test.assertFalse
18+
import kotlin.test.assertTrue
19+
20+
class KT69330StableFriendPathsArchiveTaskDependencyTest {
21+
@Test
22+
fun `test KT-69330 - Task dependency is created so friendPaths are stable at compile time`() {
23+
val project = setupProject()
24+
25+
assertTrue(hasTestJarDependencyInTest(project), "Expected that test jar is part of the generated friendPath")
26+
27+
project.tasks.getByName("compileTestKotlin").assertDependsOn(project.tasks.getByName("jar"))
28+
}
29+
30+
31+
@Test
32+
fun `test KT-69330 - archivesTaskOutputAsFriendModule=false disables the generation of friendPaths with associated archive`() {
33+
val project = setupProject()
34+
35+
project.propertiesExtension[KOTLIN_ARCHIVES_TASK_OUTPUT_AS_FRIEND_ENABLED] = "false"
36+
37+
assertFalse(hasTestJarDependencyInTest(project), "Expected that test jar is not a part of the generated friendPath")
38+
39+
project.tasks.getByName("compileTestKotlin").assertNotDependsOn(project.tasks.getByName("jar"))
40+
}
41+
42+
private fun setupProject(): ProjectInternal {
43+
val project = buildProject()
44+
project.plugins.apply("java-library")
45+
project.applyKotlinJvmPlugin()
46+
project.repositories.mavenLocal()
47+
project.repositories.mavenCentralCacheRedirector()
48+
return project
49+
}
50+
51+
private fun hasTestJarDependencyInTest(project: ProjectInternal): Boolean {
52+
val testCompilationImpl = project.kotlinJvmExtension.target.compilations.getByName("test").decoratedInstance.compilation
53+
return testCompilationImpl.friendPaths.any {
54+
it.files.any { file ->
55+
file.invariantSeparatorsPath.endsWith("build/libs/test.jar")
56+
}
57+
}
58+
}
59+
}

libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/util/assertions.kt

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ fun Task.assertDependsOn(other: Task) {
2323
}
2424
}
2525

26+
fun Task.assertNotDependsOn(other: Task) {
27+
if (isDependsOn(other)) {
28+
fail("Expected ${this.path} not to depend on ${other.path}")
29+
}
30+
}
31+
2632
fun Task.assertNoCircularTaskDependencies() {
2733
data class TaskAndDependants(
2834
val task: Task,

0 commit comments

Comments
 (0)