Browse Source

Include main jar into runtime classpath for Kotlin MPP target

pull/39/head
Alexey Tsvetkov 4 years ago
parent
commit
01fe61f9c7
  1. 38
      gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt
  2. 4
      gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/Application.kt
  3. 31
      gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt

38
gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/ApplicationPlugin.kt

@ -148,21 +148,13 @@ internal fun AbstractJPackageTask.configurePackagingTask(app: Application) {
launcherMainJar.set(app.mainJar.orNull) launcherMainJar.set(app.mainJar.orNull)
app._fromFiles.forEach { files.from(it) } app._fromFiles.forEach { files.from(it) }
dependsOn(*app._dependenciesTaskNames.toTypedArray()) dependsOn(*app._dependenciesTaskNames.toTypedArray())
when (val configSource = app._configurationSource) {
is ConfigurationSource.None -> {} app._configurationSource?.let { configSource ->
is ConfigurationSource.GradleSourceSet -> { dependsOn(configSource.jarTaskName)
val sourceSet = configSource.sourceSet files.from(configSource.runtimeClasspath)
dependsOn(sourceSet.jarTaskName) launcherMainJar.set(app.mainJar.orElse(configSource.jarTask(project).flatMap { it.archiveFile }))
launcherMainJar.set(app.mainJar.orElse(jarFromJarTaskByName(sourceSet.jarTaskName)))
files.from(sourceSet.runtimeClasspath)
}
is ConfigurationSource.KotlinMppTarget -> {
val target = configSource.target
dependsOn(target.artifactsTaskName)
launcherMainJar.set(app.mainJar.orElse(jarFromJarTaskByName(target.artifactsTaskName)))
files.from(target.runtimeFiles())
}
} }
modules.set(provider { app.nativeDistributions.modules }) modules.set(provider { app.nativeDistributions.modules })
launcherMainClass.set(provider { app.mainClass }) launcherMainClass.set(provider { app.mainClass })
launcherJvmArgs.set(provider { app.jvmArgs }) launcherJvmArgs.set(provider { app.jvmArgs })
@ -184,27 +176,15 @@ private fun Project.configureRunTask(app: Application) {
cp.from(app._fromFiles) cp.from(app._fromFiles)
dependsOn(*app._dependenciesTaskNames.toTypedArray()) dependsOn(*app._dependenciesTaskNames.toTypedArray())
when (val configSource = app._configurationSource) { app._configurationSource?.let { configSource ->
is ConfigurationSource.None -> {} dependsOn(configSource.jarTaskName)
is ConfigurationSource.GradleSourceSet -> { cp.from(configSource.runtimeClasspath)
val sourceSet = configSource.sourceSet
dependsOn(sourceSet.jarTaskName)
cp.from(sourceSet.runtimeClasspath)
}
is ConfigurationSource.KotlinMppTarget -> {
val target = configSource.target
dependsOn(target.artifactsTaskName)
cp.from(target.runtimeFiles())
}
} }
classpath = cp classpath = cp
} }
} }
private fun KotlinTarget.runtimeFiles(): FileCollection =
(compilations.getByName("main") as KotlinCompilationToRunnableFiles).runtimeDependencyFiles
private fun Application.javaHomeOrDefault(): String = private fun Application.javaHomeOrDefault(): String =
javaHome ?: System.getProperty("java.home") javaHome ?: System.getProperty("java.home")

4
gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/Application.kt

@ -15,7 +15,7 @@ open class Application @Inject constructor(
val name: String, val name: String,
objects: ObjectFactory objects: ObjectFactory
) { ) {
internal var _configurationSource: ConfigurationSource = ConfigurationSource.None internal var _configurationSource: ConfigurationSource? = null
internal val _fromFiles = objects.fileCollection() internal val _fromFiles = objects.fileCollection()
internal val _dependenciesTaskNames = ArrayList<String>() internal val _dependenciesTaskNames = ArrayList<String>()
@ -28,7 +28,7 @@ open class Application @Inject constructor(
_configurationSource = ConfigurationSource.KotlinMppTarget(from) _configurationSource = ConfigurationSource.KotlinMppTarget(from)
} }
fun disableDefaultConfiguration() { fun disableDefaultConfiguration() {
_configurationSource = ConfigurationSource.None _configurationSource = null
} }
fun fromFiles(vararg files: Any) { fun fromFiles(vararg files: Any) {

31
gradle-plugins/compose-desktop-application/src/main/kotlin/org/jetbrains/compose/desktop/application/dsl/ConfigurationSource.kt

@ -1,10 +1,35 @@
package org.jetbrains.compose.desktop.application.dsl package org.jetbrains.compose.desktop.application.dsl
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
internal sealed class ConfigurationSource { internal sealed class ConfigurationSource {
object None : ConfigurationSource() abstract val jarTaskName: String
class GradleSourceSet(val sourceSet: SourceSet) : ConfigurationSource() abstract val runtimeClasspath: FileCollection
class KotlinMppTarget(val target: KotlinJvmTarget) : ConfigurationSource() fun jarTask(project: Project): TaskProvider<Jar> =
project.tasks.named(jarTaskName, Jar::class.java)
class GradleSourceSet(val sourceSet: SourceSet) : ConfigurationSource() {
override val jarTaskName: String
get() = sourceSet.jarTaskName
override val runtimeClasspath: FileCollection
get() = sourceSet.runtimeClasspath
}
class KotlinMppTarget(val target: KotlinJvmTarget) : ConfigurationSource() {
override val jarTaskName: String
get() = target.artifactsTaskName
override val runtimeClasspath: FileCollection
get() = target.project.objects.fileCollection().apply {
from(jarTask(target.project).flatMap { it.archiveFile })
from(target.compilations.getByName("main").runtimeDependencyFiles)
}
}
} }
Loading…
Cancel
Save