@@ -88,6 +88,9 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
88
88
89
89
var languageVersion: String? = null
90
90
91
+ /* * Use the new experimental K2 compiler */
92
+ var useK2: Boolean by default { false }
93
+
91
94
/* * Additional string arguments to the Kotlin compiler */
92
95
var kotlincArguments: List <String > = emptyList()
93
96
@@ -126,6 +129,7 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
126
129
args.allWarningsAsErrors = allWarningsAsErrors
127
130
args.reportOutputFiles = reportOutputFiles
128
131
args.reportPerf = reportPerformance
132
+ args.useK2 = useK2
129
133
130
134
if (languageVersion != null )
131
135
args.languageVersion = this .languageVersion
@@ -191,7 +195,16 @@ abstract class AbstractKotlinCompilation<A : CommonCompilerArguments> internal c
191
195
} else {
192
196
emptyList()
193
197
}
194
- args.pluginClasspaths = (args.pluginClasspaths ? : emptyArray()) + arrayOf(getResourcesPath())
198
+ args.pluginClasspaths = (args.pluginClasspaths ? : emptyArray()) +
199
+ /* * The resources path contains the MainComponentRegistrar and MainCommandLineProcessor which will
200
+ be found by the Kotlin compiler's service loader. We add it only when the user has actually given
201
+ us ComponentRegistrar instances to be loaded by the MainComponentRegistrar because the experimental
202
+ K2 compiler doesn't support plugins yet. This way, users of K2 can prevent MainComponentRegistrar
203
+ from being loaded and crashing K2 by setting both [compilerPlugins] and [commandLineProcessors] to
204
+ the emptyList. */
205
+ if (compilerPlugins.isNotEmpty() || commandLineProcessors.isNotEmpty())
206
+ arrayOf(getResourcesPath())
207
+ else emptyArray()
195
208
}
196
209
197
210
val compilerMessageCollector = PrintingMessageCollector (
0 commit comments