Add jvm resource copy

This commit is contained in:
Alexander Nozik 2020-07-06 09:52:54 +03:00
parent 615b06eb8c
commit 589ac77c2b
5 changed files with 59 additions and 7 deletions

14
CHANGELOG.md Normal file
View File

@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.5.2]
### Added
- Copy resources for jvm modules and jvm source sets in mpp

View File

@ -8,7 +8,7 @@ plugins {
} }
group = "scientifik" group = "scientifik"
version = "0.5.1" version = "0.5.2"
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()

View File

@ -7,6 +7,7 @@ import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.testing.Test import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
@ -91,9 +92,15 @@ open class ScientifikJVMPlugin : Plugin<Project> {
} }
} }
} }
tasks.withType<Test>() {
tasks.apply {
withType<Test>() {
useJUnitPlatform() useJUnitPlatform()
} }
val processResources by getting(Copy::class)
processResources.copyJVMResources(configurations["runtimeClasspath"])
}
} }
} }

View File

@ -115,9 +115,16 @@ open class ScientifikMPPlugin : Plugin<Project> {
} }
tasks.apply { tasks.apply {
withType<Test>() {
useJUnitPlatform()
}
val jsProcessResources by getting(Copy::class) val jsProcessResources by getting(Copy::class)
jsProcessResources.copyJSResources(configurations["jsRuntimeClasspath"]) jsProcessResources.copyJSResources(configurations["jsRuntimeClasspath"])
val jvmProcessResources by getting(Copy::class)
jvmProcessResources.copyJVMResources(configurations["jvmRuntimeClasspath"])
val jsBrowserDistribution by getting { val jsBrowserDistribution by getting {
doLast { doLast {
val indexFile = project.jsDistDirectory.resolve("index.html") val indexFile = project.jsDistDirectory.resolve("index.html")
@ -127,10 +134,6 @@ open class ScientifikMPPlugin : Plugin<Project> {
} }
group = "distribution" group = "distribution"
} }
withType<Test>() {
useJUnitPlatform()
}
} }
} }

View File

@ -58,6 +58,34 @@ internal fun Copy.copyJSResources(configuration: Configuration): Unit = project.
} }
} }
internal fun Copy.copyJVMResources(configuration: Configuration): Unit = project.afterEvaluate {
val projectDeps = configuration
.allDependencies
.filterIsInstance<ProjectDependency>()
.map { it.dependencyProject }
val destination = destinationDir
projectDeps.forEach { dep ->
dep.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
dep.tasks.findByName("jvmProcessResources")?.let { task ->
val sourceDir = (task as Copy).destinationDir
inputs.files(sourceDir)
dependsOn(task)
from(sourceDir)
}
}
dep.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
dep.tasks.findByName("processResources")?.let { task ->
val sourceDir = (task as Copy).destinationDir
inputs.files(sourceDir)
dependsOn(task)
from(sourceDir)
}
}
}
}
val Project.jsDistDirectory: File val Project.jsDistDirectory: File
get() { get() {