Use separate configuration for resolving native compiler plugin artifacts
Kotlin/JVM and Kotlin/JS use shaded compiler, but Kotlin/Native uses non-shaded one. Serialization plugin was configured to use either shaded or non-shaded plugin version, because we used one configuration for resolving compiler plugins. This change introduces 'kotlinNativeCompilerPluginClasspath' configuration for resolving Kotlin/Native compiler plugins.
This commit is contained in:
committed by
Ilya Matveev
parent
affa881421
commit
de261df6f5
+1
@@ -67,6 +67,7 @@ interface KotlinGradleSubplugin<in KotlinCompile : AbstractCompile> {
|
|||||||
fun getCompilerPluginId(): String
|
fun getCompilerPluginId(): String
|
||||||
|
|
||||||
fun getPluginArtifact(): SubpluginArtifact
|
fun getPluginArtifact(): SubpluginArtifact
|
||||||
|
fun getNativeCompilerPluginArtifact(): SubpluginArtifact? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
open class SubpluginArtifact(val groupId: String, val artifactId: String, val version: String? = null)
|
open class SubpluginArtifact(val groupId: String, val artifactId: String, val version: String? = null)
|
||||||
|
|||||||
+1
@@ -40,6 +40,7 @@ import java.util.concurrent.Callable
|
|||||||
import java.util.jar.Manifest
|
import java.util.jar.Manifest
|
||||||
|
|
||||||
const val PLUGIN_CLASSPATH_CONFIGURATION_NAME = "kotlinCompilerPluginClasspath"
|
const val PLUGIN_CLASSPATH_CONFIGURATION_NAME = "kotlinCompilerPluginClasspath"
|
||||||
|
const val NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME = "kotlinNativeCompilerPluginClasspath"
|
||||||
internal const val COMPILER_CLASSPATH_CONFIGURATION_NAME = "kotlinCompilerClasspath"
|
internal const val COMPILER_CLASSPATH_CONFIGURATION_NAME = "kotlinCompilerClasspath"
|
||||||
val KOTLIN_DSL_NAME = "kotlin"
|
val KOTLIN_DSL_NAME = "kotlin"
|
||||||
val KOTLIN_JS_DSL_NAME = "kotlin2js"
|
val KOTLIN_JS_DSL_NAME = "kotlin2js"
|
||||||
|
|||||||
+3
@@ -55,6 +55,9 @@ abstract class KotlinBasePluginWrapper(
|
|||||||
// todo: Consider removing if org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser stops using parent last classloader
|
// todo: Consider removing if org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser stops using parent last classloader
|
||||||
isTransitive = false
|
isTransitive = false
|
||||||
}
|
}
|
||||||
|
project.configurations.maybeCreate(NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME).apply {
|
||||||
|
isTransitive = false
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: consider only set if if daemon or parallel compilation are enabled, though this way it should be safe too
|
// TODO: consider only set if if daemon or parallel compilation are enabled, though this way it should be safe too
|
||||||
System.setProperty(org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "true")
|
System.setProperty(org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "true")
|
||||||
|
|||||||
+1
-1
@@ -435,7 +435,7 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
SubpluginEnvironment
|
SubpluginEnvironment
|
||||||
.loadSubplugins(project, kotlinPluginVersion)
|
.loadSubplugins(project, kotlinPluginVersion)
|
||||||
.addSubpluginOptions<CommonCompilerArguments>(project, this, compilerPluginOptions)
|
.addSubpluginOptions<CommonCompilerArguments>(project, this, compilerPluginOptions)
|
||||||
compilerPluginClasspath = project.configurations.getByName(PLUGIN_CLASSPATH_CONFIGURATION_NAME)
|
compilerPluginClasspath = project.configurations.getByName(NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KotlinNativeCompile.registerOutputFiles(outputDirectory: File) {
|
private fun KotlinNativeCompile.registerOutputFiles(outputDirectory: File) {
|
||||||
|
|||||||
+14
-5
@@ -73,11 +73,13 @@ class SubpluginEnvironment(
|
|||||||
val pluginId = subplugin.getCompilerPluginId()
|
val pluginId = subplugin.getCompilerPluginId()
|
||||||
project.logger.kotlinDebug { "Loading subplugin $pluginId" }
|
project.logger.kotlinDebug { "Loading subplugin $pluginId" }
|
||||||
|
|
||||||
val artifact = subplugin.getPluginArtifact()
|
subplugin.getPluginArtifact().let { artifact ->
|
||||||
val artifactVersion = artifact.version ?: kotlinPluginVersion
|
project.addMavenDependency(PLUGIN_CLASSPATH_CONFIGURATION_NAME, artifact)
|
||||||
val mavenCoordinate = "${artifact.groupId}:${artifact.artifactId}:$artifactVersion"
|
}
|
||||||
project.logger.kotlinDebug { "Adding '$mavenCoordinate' to '$PLUGIN_CLASSPATH_CONFIGURATION_NAME' configuration" }
|
|
||||||
project.dependencies.add(PLUGIN_CLASSPATH_CONFIGURATION_NAME, mavenCoordinate)
|
subplugin.getNativeCompilerPluginArtifact()?.let { artifact ->
|
||||||
|
project.addMavenDependency(NATIVE_COMPILER_PLUGIN_CLASSPATH_CONFIGURATION_NAME, artifact)
|
||||||
|
}
|
||||||
|
|
||||||
val subpluginOptions =
|
val subpluginOptions =
|
||||||
subplugin.apply(project, kotlinTask, javaTask, variantData, androidProjectHandler, kotlinCompilation)
|
subplugin.apply(project, kotlinTask, javaTask, variantData, androidProjectHandler, kotlinCompilation)
|
||||||
@@ -92,4 +94,11 @@ class SubpluginEnvironment(
|
|||||||
|
|
||||||
return appliedSubplugins
|
return appliedSubplugins
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Project.addMavenDependency(configuration: String, artifact: SubpluginArtifact) {
|
||||||
|
val artifactVersion = artifact.version ?: kotlinPluginVersion
|
||||||
|
val mavenCoordinate = "${artifact.groupId}:${artifact.artifactId}:$artifactVersion"
|
||||||
|
project.logger.kotlinDebug { "Adding '$mavenCoordinate' to '$configuration' configuration" }
|
||||||
|
project.dependencies.add(configuration, mavenCoordinate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+6
-12
@@ -42,14 +42,8 @@ class SerializationKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile
|
|||||||
const val SERIALIZATION_ARTIFACT_UNSHADED_NAME = "kotlin-serialization-unshaded"
|
const val SERIALIZATION_ARTIFACT_UNSHADED_NAME = "kotlin-serialization-unshaded"
|
||||||
}
|
}
|
||||||
|
|
||||||
private var useUnshaded = false
|
override fun isApplicable(project: Project, task: AbstractCompile): Boolean =
|
||||||
|
SerializationGradleSubplugin.isEnabled(project)
|
||||||
override fun isApplicable(project: Project, task: AbstractCompile): Boolean {
|
|
||||||
if (!SerializationGradleSubplugin.isEnabled(project)) return false
|
|
||||||
// Kotlin/Native task is not an AbstractKotlinCompile and uses unshaded compiler
|
|
||||||
if (task !is AbstractKotlinCompile<*>) useUnshaded = true
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun apply(
|
override fun apply(
|
||||||
project: Project,
|
project: Project,
|
||||||
@@ -62,11 +56,11 @@ class SerializationKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile
|
|||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getPluginArtifact(): SubpluginArtifact =
|
||||||
|
SubpluginArtifact(SERIALIZATION_GROUP_NAME, SERIALIZATION_ARTIFACT_NAME)
|
||||||
|
|
||||||
override fun getPluginArtifact(): SubpluginArtifact {
|
override fun getNativeCompilerPluginArtifact(): SubpluginArtifact? =
|
||||||
val artifact = if (useUnshaded) SERIALIZATION_ARTIFACT_UNSHADED_NAME else SERIALIZATION_ARTIFACT_NAME
|
SubpluginArtifact(SERIALIZATION_GROUP_NAME, SERIALIZATION_ARTIFACT_UNSHADED_NAME)
|
||||||
return SubpluginArtifact(SERIALIZATION_GROUP_NAME, artifact)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getCompilerPluginId() = "org.jetbrains.kotlinx.serialization"
|
override fun getCompilerPluginId() = "org.jetbrains.kotlinx.serialization"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user