Skip to content

Commit

Permalink
[KGP] Make kotlin.build.archivesTaskOutputAsFriendModule property public
Browse files Browse the repository at this point in the history
Add functional test
  • Loading branch information
mazhukinevgeniy authored and qodana-bot committed Jul 8, 2024
1 parent 623edef commit 5118405
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libraries/stdlib/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kotlin.internal.suppressGradlePluginErrors=PreHMPPFlagsError
kotlin.mpp.enableCompatibilityMetadataVariant=true
kotlin.internal.mpp.createDefaultMultiplatformPublications=false
kotlin.internal.archivesTaskOutputAsFriendModule=false
kotlin.build.archivesTaskOutputAsFriendModule=false
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ internal class PropertiesProvider private constructor(private val project: Proje
val KOTLIN_APPLE_COCOAPODS_EXECUTABLE = property("kotlin.apple.cocoapods.bin")
val KOTLIN_APPLE_ALLOW_EMBED_AND_SIGN_WITH_COCOAPODS = property("kotlin.apple.deprecated.allowUsingEmbedAndSignWithCocoaPodsDependencies")
val KOTLIN_SWIFT_EXPORT_ENABLED = property("kotlin.swift-export.enabled")
val KOTLIN_NATIVE_ENABLE_KLIBS_CROSSCOMPILATION = property("kotlin.native.enableKlibsCrossCompilation")
val KOTLIN_ARCHIVES_TASK_OUTPUT_AS_FRIEND_ENABLED = property("kotlin.build.archivesTaskOutputAsFriendModule")

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

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

@file:Suppress("FunctionName")

package org.jetbrains.kotlin.gradle.regressionTests

import org.gradle.api.internal.project.ProjectInternal
import org.jetbrains.kotlin.gradle.dependencyResolutionTests.mavenCentralCacheRedirector
import org.jetbrains.kotlin.gradle.dsl.kotlinJvmExtension
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_ARCHIVES_TASK_OUTPUT_AS_FRIEND_ENABLED
import org.jetbrains.kotlin.gradle.plugin.mpp.decoratedInstance
import org.jetbrains.kotlin.gradle.util.*
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class KT69330StableFriendPathsArchiveTaskDependencyTest {
@Test
fun `test KT-69330 - Task dependency is created so friendPaths are stable at compile time`() {
val project = setupProject()

assertTrue(hasTestJarDependencyInTest(project), "Expected that test jar is part of the generated friendPath")

project.tasks.getByName("compileTestKotlin").assertDependsOn(project.tasks.getByName("jar"))
}


@Test
fun `test KT-69330 - archivesTaskOutputAsFriendModule=false disables the generation of friendPaths with associated archive`() {
val project = setupProject()

project.propertiesExtension[KOTLIN_ARCHIVES_TASK_OUTPUT_AS_FRIEND_ENABLED] = "false"

assertFalse(hasTestJarDependencyInTest(project), "Expected that test jar is not a part of the generated friendPath")

project.tasks.getByName("compileTestKotlin").assertNotDependsOn(project.tasks.getByName("jar"))
}

private fun setupProject(): ProjectInternal {
val project = buildProject()
project.plugins.apply("java-library")
project.applyKotlinJvmPlugin()
project.repositories.mavenLocal()
project.repositories.mavenCentralCacheRedirector()
return project
}

private fun hasTestJarDependencyInTest(project: ProjectInternal): Boolean {
val testCompilationImpl = project.kotlinJvmExtension.target.compilations.getByName("test").decoratedInstance.compilation
return testCompilationImpl.friendPaths.any {
it.files.any { file ->
file.invariantSeparatorsPath.endsWith("build/libs/test.jar")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ fun Task.assertDependsOn(other: Task) {
}
}

fun Task.assertNotDependsOn(other: Task) {
if (isDependsOn(other)) {
fail("Expected ${this.path} not to depend on ${other.path}")
}
}

fun Task.assertNoCircularTaskDependencies() {
data class TaskAndDependants(
val task: Task,
Expand Down

0 comments on commit 5118405

Please sign in to comment.