Pill: Import Java toolchain configuration correctly

Before, all project modules used 'inheritedJdk'. However, some Kotlin
modules now require JDK 8, while others depend on new API in JDK 11.
This commit is contained in:
Yan Zhulanow
2022-03-03 17:11:13 +09:00
parent 6b00b51e6d
commit 736c6c4d29
3 changed files with 16 additions and 1 deletions
@@ -19,6 +19,7 @@ import org.gradle.api.internal.file.copy.CopySpecInternal
import org.gradle.api.internal.file.copy.SingleParentCopySpec
import org.gradle.api.provider.Property
import org.gradle.jvm.tasks.Jar
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.findByType
import org.gradle.language.jvm.tasks.ProcessResources
@@ -122,6 +123,8 @@ class ModelParser(private val variant: Variant, private val modulePrefix: String
val embeddedDependencies = project.configurations.findByName(EMBEDDED_CONFIGURATION_NAME)
?.let { parseDependencies(it) } ?: emptyList()
val javaLanguageVersion = getJavaLanguageVersion(project)
val sourceSets = parseSourceSets(project).sortedBy { it.forTests }
for (sourceSet in sourceSets) {
val sourceRoots = mutableListOf<PSourceRoot>()
@@ -158,6 +161,7 @@ class ModelParser(private val variant: Variant, private val modulePrefix: String
moduleFile = getModuleFile(name),
contentRoots = contentRoots,
orderRoots = orderRoots,
javaLanguageVersion = javaLanguageVersion,
kotlinOptions = sourceSet.kotlinOptions,
moduleForProductionSources = productionModule,
embeddedDependencies = embeddedDependencies
@@ -177,6 +181,7 @@ class ModelParser(private val variant: Variant, private val modulePrefix: String
moduleFile = mainModuleFileRelativePath,
contentRoots = listOf(PContentRoot(project.projectDir, listOf(), getExcludedDirs(project, excludedProjects))),
orderRoots = emptyList(),
javaLanguageVersion = null,
kotlinOptions = null,
moduleForProductionSources = null,
embeddedDependencies = emptyList()
@@ -185,6 +190,12 @@ class ModelParser(private val variant: Variant, private val modulePrefix: String
return modules
}
private fun getJavaLanguageVersion(project: Project): Int? {
val javaPluginExtension = project.extensions.findByType<JavaPluginExtension>() ?: return null
val javaToolchainService = project.extensions.findByType<JavaToolchainService>() ?: return null
return javaToolchainService.launcherFor(javaPluginExtension.toolchain).orNull?.metadata?.languageVersion?.asInt()
}
private fun getExcludedDirs(project: Project, excludedProjects: List<Project>): List<File> {
fun getJavaExcludedDirs() = project.plugins.findPlugin(IdeaPlugin::class.java)
?.model?.module?.excludeDirs?.toList() ?: emptyList()
@@ -16,6 +16,7 @@ data class PModule(
val moduleFile: File,
val contentRoots: List<PContentRoot>,
val orderRoots: List<POrderRoot>,
val javaLanguageVersion: Int?,
val kotlinOptions: PSourceRootKotlinOptions?,
val moduleForProductionSources: PModule? = null,
val embeddedDependencies: List<PDependency>
+4 -1
View File
@@ -130,7 +130,10 @@ private fun renderModule(project: PProject, module: PModule) = PFile(
}
}
xml("orderEntry", "type" to "inheritedJdk")
when (val javaLanguageVersion = module.javaLanguageVersion) {
null -> xml("orderEntry", "type" to "inheritedJdk")
else -> xml("orderEntry", "type" to "jdk", "jdkName" to javaLanguageVersion.toString(), "jdkType" to "JavaSDK")
}
xml("orderEntry", "type" to "sourceFolder", "forTests" to "false")