[Gradle] Check JVM targets only if mixed Java/Kotlin sources are present

#KT-48408 Verification Pending
This commit is contained in:
Alexander Likhachev
2022-01-18 16:56:25 +03:00
committed by Space
parent b0d7c97ad2
commit 5199981d96
@@ -739,7 +739,7 @@ abstract class KotlinCompile @Inject constructor(
) {
sourceRoots as SourceRoots.ForJvm
validateKotlinAndJavaHasSameTargetCompatibility(args)
validateKotlinAndJavaHasSameTargetCompatibility(args, sourceRoots)
val messageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
val outputItemCollector = OutputItemsCollectorImpl()
@@ -781,8 +781,9 @@ abstract class KotlinCompile @Inject constructor(
)
}
private fun validateKotlinAndJavaHasSameTargetCompatibility(args: K2JVMCompilerArguments) {
if (!associatedJavaCompileTaskSources.isEmpty) {
private fun validateKotlinAndJavaHasSameTargetCompatibility(args: K2JVMCompilerArguments, sourceRoots: SourceRoots.ForJvm) {
val mixedSourcesArePresent = !associatedJavaCompileTaskSources.isEmpty && !sourceRoots.kotlinSourceFiles.isEmpty
if (mixedSourcesArePresent) {
associatedJavaCompileTaskTargetCompatibility.orNull?.let { targetCompatibility ->
val normalizedJavaTarget = when (targetCompatibility) {
"6" -> "1.6"