diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt index 5288932e..387c8a59 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt @@ -10,7 +10,6 @@ import com.google.inject.Inject import com.google.inject.Singleton import java.io.File import java.io.FileInputStream -import java.lang.NumberFormatException import javax.xml.bind.JAXBContext import javax.xml.bind.annotation.XmlElement import javax.xml.bind.annotation.XmlRootElement @@ -40,6 +39,9 @@ class KobaltSettingsXml { @XmlElement(name = "kobaltCompilerFlags") @JvmField var kobaltCompilerFlags: String? = null + + @XmlElement(name = "kobaltCompilerSeparateProcess") @JvmField + var kobaltCompilerSeparateProcess: Boolean = false } class ProxiesXml { @@ -83,6 +85,12 @@ class KobaltSettings @Inject constructor(val xmlFile: KobaltSettingsXml) { */ val localMavenRepo = KFiles.makeDir(xmlFile.localMavenRepo) + /** + * If true, the Kotlin compiler will always be launched in a separate JVM, even if the requested + * version is the same as the internal version. + */ + val kobaltCompilerSeparateProcess = xmlFile.kobaltCompilerSeparateProcess + val defaultRepos = xmlFile.defaultRepos?.repo val proxyConfigs = with(xmlFile.proxies?.proxy) { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 4016ea0f..b1a967d3 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -74,12 +74,12 @@ class KotlinCompiler @Inject constructor( // need to spawn a Kotlin compiler in a separate process. Otherwise, we can just invoke // the K2JVMCompiler class directly val actualVersion = kotlinConfig(project)?.version ?: settings.kobaltCompilerVersion - if (actualVersion == Constants.KOTLIN_COMPILER_VERSION) { - return invokeCompilerDirectly(projectName ?: "kobalt-" + Random().nextInt(), outputDir, - classpath, info.sourceFiles, info.friendPaths.toTypedArray()) + if (settings.kobaltCompilerSeparateProcess || actualVersion != Constants.KOTLIN_COMPILER_VERSION) { + return invokeCompilerInSeparateProcess(classpath, info, project) } else { - return invokeCompilerInSeparateProcess(classpath, info, project) + return invokeCompilerDirectly(projectName ?: "kobalt-" + Random().nextInt(), outputDir, + classpath, info.sourceFiles, info.friendPaths.toTypedArray()) } } @@ -93,7 +93,7 @@ class KotlinCompiler @Inject constructor( val compilerClasspath = compilerDep.jarFile.get().path + File.pathSeparator + compilerEmbeddableDependencies(null).map { it.jarFile.get().path } .joinToString(File.pathSeparator) - val xFlagsString = kotlinConfig(project)?.flags + val xFlagsString = kotlinConfig(project)?.args?.joinToString(" ") ?: settings.kobaltCompilerFlags ?: "" val xFlagsArray = xFlagsString.split(" ").toTypedArray() diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index 8447b98d..3d297f52 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -42,7 +42,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen // ICompilerFlagsContributor override fun compilerFlagsFor(project: Project, context: KobaltContext, currentFlags: List, suffixesBeingCompiled: List) : List { - val args = (configurationFor(project)?.compilerArgs ?: listOf()) + "-no-stdlib" + val args = (configurationFor(project)?.args ?: listOf()) + "-no-stdlib" val result = maybeCompilerArgs(compiler.sourceSuffixes, suffixesBeingCompiled, args) return result } @@ -145,14 +145,11 @@ fun kotlinProject(vararg projects: Project, init: Project.() -> Unit): Project { } class KotlinConfig(val project: Project) { - val compilerArgs = arrayListOf() - fun args(vararg options: String) = compilerArgs.addAll(options) + val args = arrayListOf() + fun args(vararg options: String) = args.addAll(options) /** The version of the Kotlin compiler */ var version: String? = null - - /** The flags to pass to the Kotlin compiler */ - var flags: String? = null } @Directive