Browse Source

Merge pull request #39 from JetBrains/desktop-application-mpp-runtime-classpath

Include main jar into runtime classpath for Kotlin MPP target
pull/43/head
Nikolay Igotti 4 years ago committed by GitHub
parent
commit
400d63ece4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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)
app._fromFiles.forEach { files.from(it) }
dependsOn(*app._dependenciesTaskNames.toTypedArray())
when (val configSource = app._configurationSource) {
is ConfigurationSource.None -> {}
is ConfigurationSource.GradleSourceSet -> {
val sourceSet = configSource.sourceSet
dependsOn(sourceSet.jarTaskName)
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())
}
app._configurationSource?.let { configSource ->
dependsOn(configSource.jarTaskName)
files.from(configSource.runtimeClasspath)
launcherMainJar.set(app.mainJar.orElse(configSource.jarTask(project).flatMap { it.archiveFile }))
}
modules.set(provider { app.nativeDistributions.modules })
launcherMainClass.set(provider { app.mainClass })
launcherJvmArgs.set(provider { app.jvmArgs })
@ -184,27 +176,15 @@ private fun Project.configureRunTask(app: Application) {
cp.from(app._fromFiles)
dependsOn(*app._dependenciesTaskNames.toTypedArray())
when (val configSource = app._configurationSource) {
is ConfigurationSource.None -> {}
is ConfigurationSource.GradleSourceSet -> {
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())
}
app._configurationSource?.let { configSource ->
dependsOn(configSource.jarTaskName)
cp.from(configSource.runtimeClasspath)
}
classpath = cp
}
}
private fun KotlinTarget.runtimeFiles(): FileCollection =
(compilations.getByName("main") as KotlinCompilationToRunnableFiles).runtimeDependencyFiles
private fun Application.javaHomeOrDefault(): String =
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,
objects: ObjectFactory
) {
internal var _configurationSource: ConfigurationSource = ConfigurationSource.None
internal var _configurationSource: ConfigurationSource? = null
internal val _fromFiles = objects.fileCollection()
internal val _dependenciesTaskNames = ArrayList<String>()
@ -28,7 +28,7 @@ open class Application @Inject constructor(
_configurationSource = ConfigurationSource.KotlinMppTarget(from)
}
fun disableDefaultConfiguration() {
_configurationSource = ConfigurationSource.None
_configurationSource = null
}
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
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
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
internal sealed class ConfigurationSource {
object None : ConfigurationSource()
class GradleSourceSet(val sourceSet: SourceSet) : ConfigurationSource()
class KotlinMppTarget(val target: KotlinJvmTarget) : ConfigurationSource()
abstract val jarTaskName: String
abstract val runtimeClasspath: FileCollection
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