[Gradle] Associate the textFixtures source set with main and test ones

#KT-34901 Fixed
This commit is contained in:
Alexander.Likhachev
2023-06-29 15:52:55 +02:00
committed by Space Team
parent fcb7010726
commit 8ae0f61028
2 changed files with 27 additions and 5 deletions
@@ -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<*, *>
) {