diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/TestFixturesIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/TestFixturesIT.kt index 43cd64ba366..e6d38c10edb 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/TestFixturesIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/TestFixturesIT.kt @@ -7,13 +7,11 @@ package org.jetbrains.kotlin.gradle import org.gradle.util.GradleVersion import org.jetbrains.kotlin.gradle.testbase.* -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.DisplayName import kotlin.io.path.appendText @DisplayName("Integration with the Gradle java-test-fixtures plugin") class TestFixturesIT : KGPBaseTest() { - @Disabled @DisplayName("Test fixtures can access internals of the main source set in Kotlin/JVM projects") @JvmGradlePluginTests @GradleTest @@ -31,7 +29,6 @@ class TestFixturesIT : KGPBaseTest() { } } - @Disabled @DisplayName("Test fixtures can access internals of the main JVM source set in Kotlin MPP projects") @MppGradlePluginTests @GradleTest @@ -49,7 +46,6 @@ class TestFixturesIT : KGPBaseTest() { } } - @Disabled @DisplayName("Test code can access internals of the test fixtures source set in Kotlin/JVM projects") @JvmGradlePluginTests @GradleTest @@ -74,7 +70,6 @@ class TestFixturesIT : KGPBaseTest() { } } - @Disabled @DisplayName("JVM test code can access internals of the test fixtures source set in Kotlin MPP projects") @MppGradlePluginTests @GradleTest diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/AbstractKotlinPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/AbstractKotlinPlugin.kt index ffa99e07fc5..f9fb671cd9f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/AbstractKotlinPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/AbstractKotlinPlugin.kt @@ -16,6 +16,7 @@ import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.maven.MavenPom import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.tasks.SourceSet +import org.gradle.internal.component.external.model.TestFixturesSupport.TEST_FIXTURES_FEATURE_NAME import org.gradle.jvm.tasks.Jar import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry import org.jetbrains.kotlin.gradle.dsl.KotlinSingleJavaTargetExtension @@ -37,6 +38,7 @@ const val NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME = "kotlinNativeCom const val COMPILER_CLASSPATH_CONFIGURATION_NAME = "kotlinCompilerClasspath" internal const val BUILD_TOOLS_API_CLASSPATH_CONFIGURATION_NAME = "kotlinBuildToolsApiClasspath" internal const val KLIB_COMMONIZER_CLASSPATH_CONFIGURATION_NAME = "kotlinKlibCommonizerClasspath" +private const val JAVA_TEST_FIXTURES_PLUGIN_ID = "java-test-fixtures" internal abstract class AbstractKotlinPlugin( val tasksProvider: KotlinTasksProvider, @@ -211,6 +213,8 @@ internal abstract class AbstractKotlinPlugin( getByName(KotlinCompilation.TEST_COMPILATION_NAME).associateWith(getByName(KotlinCompilation.MAIN_COMPILATION_NAME)) } + configureJavaTestFixturesSourceSets(kotlinTarget) + // Since the 'java' plugin (as opposed to 'java-library') doesn't known anything about the 'api' configurations, // add the API dependencies of the main compilation directly to the 'apiElements' configuration, so that the 'api' dependencies // are properly published with the 'compile' scope (KT-28355): @@ -224,6 +228,29 @@ internal abstract class AbstractKotlinPlugin( } } + private fun configureJavaTestFixturesSourceSets(kotlinTarget: KotlinTarget) { + val project = kotlinTarget.project + project.plugins.withId(JAVA_TEST_FIXTURES_PLUGIN_ID) { + kotlinTarget.compilations.run { + val testFixturesSourceSet = findByName(TEST_FIXTURES_FEATURE_NAME) + if (testFixturesSourceSet == null) { + project.logger.warn( + "The `$JAVA_TEST_FIXTURES_PLUGIN_ID` plugin has been detected, " + + "however the `$TEST_FIXTURES_FEATURE_NAME` source set cannot be found. " + + "`internal` declarations can be not available in the test fixtures.", + ) + return@withId + } + testFixturesSourceSet.associateWith(getByName(KotlinCompilation.MAIN_COMPILATION_NAME)) + getByName(KotlinCompilation.TEST_COMPILATION_NAME).associateWith(testFixturesSourceSet) + project.logger.debug( + "The `$JAVA_TEST_FIXTURES_PLUGIN_ID` plugin has been detected, and the `$TEST_FIXTURES_FEATURE_NAME` " + + "source set has been associated with the default source sets to provide `internal` declarations access" + ) + } + } + } + private fun configureAttributes( kotlinTarget: KotlinWithJavaTarget<*, *> ) {