[Gradle] Associate the textFixtures source set with main and test ones
#KT-34901 Fixed
This commit is contained in:
committed by
Space Team
parent
fcb7010726
commit
8ae0f61028
-5
@@ -7,13 +7,11 @@ package org.jetbrains.kotlin.gradle
|
|||||||
|
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import org.jetbrains.kotlin.gradle.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.junit.jupiter.api.Disabled
|
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
import kotlin.io.path.appendText
|
import kotlin.io.path.appendText
|
||||||
|
|
||||||
@DisplayName("Integration with the Gradle java-test-fixtures plugin")
|
@DisplayName("Integration with the Gradle java-test-fixtures plugin")
|
||||||
class TestFixturesIT : KGPBaseTest() {
|
class TestFixturesIT : KGPBaseTest() {
|
||||||
@Disabled
|
|
||||||
@DisplayName("Test fixtures can access internals of the main source set in Kotlin/JVM projects")
|
@DisplayName("Test fixtures can access internals of the main source set in Kotlin/JVM projects")
|
||||||
@JvmGradlePluginTests
|
@JvmGradlePluginTests
|
||||||
@GradleTest
|
@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")
|
@DisplayName("Test fixtures can access internals of the main JVM source set in Kotlin MPP projects")
|
||||||
@MppGradlePluginTests
|
@MppGradlePluginTests
|
||||||
@GradleTest
|
@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")
|
@DisplayName("Test code can access internals of the test fixtures source set in Kotlin/JVM projects")
|
||||||
@JvmGradlePluginTests
|
@JvmGradlePluginTests
|
||||||
@GradleTest
|
@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")
|
@DisplayName("JVM test code can access internals of the test fixtures source set in Kotlin MPP projects")
|
||||||
@MppGradlePluginTests
|
@MppGradlePluginTests
|
||||||
@GradleTest
|
@GradleTest
|
||||||
|
|||||||
+27
@@ -16,6 +16,7 @@ import org.gradle.api.publish.PublishingExtension
|
|||||||
import org.gradle.api.publish.maven.MavenPom
|
import org.gradle.api.publish.maven.MavenPom
|
||||||
import org.gradle.api.publish.maven.MavenPublication
|
import org.gradle.api.publish.maven.MavenPublication
|
||||||
import org.gradle.api.tasks.SourceSet
|
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.jvm.tasks.Jar
|
||||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleJavaTargetExtension
|
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"
|
const val COMPILER_CLASSPATH_CONFIGURATION_NAME = "kotlinCompilerClasspath"
|
||||||
internal const val BUILD_TOOLS_API_CLASSPATH_CONFIGURATION_NAME = "kotlinBuildToolsApiClasspath"
|
internal const val BUILD_TOOLS_API_CLASSPATH_CONFIGURATION_NAME = "kotlinBuildToolsApiClasspath"
|
||||||
internal const val KLIB_COMMONIZER_CLASSPATH_CONFIGURATION_NAME = "kotlinKlibCommonizerClasspath"
|
internal const val KLIB_COMMONIZER_CLASSPATH_CONFIGURATION_NAME = "kotlinKlibCommonizerClasspath"
|
||||||
|
private const val JAVA_TEST_FIXTURES_PLUGIN_ID = "java-test-fixtures"
|
||||||
|
|
||||||
internal abstract class AbstractKotlinPlugin(
|
internal abstract class AbstractKotlinPlugin(
|
||||||
val tasksProvider: KotlinTasksProvider,
|
val tasksProvider: KotlinTasksProvider,
|
||||||
@@ -211,6 +213,8 @@ internal abstract class AbstractKotlinPlugin(
|
|||||||
getByName(KotlinCompilation.TEST_COMPILATION_NAME).associateWith(getByName(KotlinCompilation.MAIN_COMPILATION_NAME))
|
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,
|
// 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
|
// 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):
|
// 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(
|
private fun configureAttributes(
|
||||||
kotlinTarget: KotlinWithJavaTarget<*, *>
|
kotlinTarget: KotlinWithJavaTarget<*, *>
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user