Move to manual target configuration
This commit is contained in:
parent
54e862681f
commit
b4fb5c515a
@ -9,10 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
- MPP does not use JVM and JS(IR) targets anymore. They could be turned manually via `js()`, `jvm()` or `fullStack()`
|
||||
|
||||
### Deprecated
|
||||
|
||||
### Removed
|
||||
- FX plugins
|
||||
- Unnecessary library shortcuts (html and datetime)
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
plugins {
|
||||
alias(libs.plugins.changelog)
|
||||
alias(libs.plugins.dokka)
|
||||
`java-gradle-plugin`
|
||||
`kotlin-dsl`
|
||||
`maven-publish`
|
||||
signing
|
||||
`version-catalog`
|
||||
alias(libs.plugins.changelog)
|
||||
alias(libs.plugins.dokka)
|
||||
}
|
||||
|
||||
group = "space.kscience"
|
||||
@ -21,8 +21,6 @@ repositories {
|
||||
maven("https://repo.kotlin.link")
|
||||
}
|
||||
|
||||
java.targetCompatibility = JavaVersion.VERSION_11
|
||||
|
||||
kotlin.explicitApiWarning()
|
||||
|
||||
dependencies {
|
||||
@ -33,7 +31,7 @@ dependencies {
|
||||
implementation(libs.kotlin.jupyter.gradle)
|
||||
implementation(libs.kotlin.serialization)
|
||||
implementation(libs.kotlinx.html)
|
||||
implementation("org.tomlj:tomlj:1.0.0")
|
||||
implementation("org.tomlj:tomlj:1.1.0")
|
||||
// // nexus publishing plugin
|
||||
// implementation("io.github.gradle-nexus:publish-plugin:1.1.0")
|
||||
|
||||
@ -156,8 +154,8 @@ afterEvaluate {
|
||||
}
|
||||
|
||||
val spaceRepo = "https://maven.pkg.jetbrains.space/spc/p/sci/maven"
|
||||
val spaceUser: String? = project.findProperty("publishing.space.user") as? String
|
||||
val spaceToken: String? = project.findProperty("publishing.space.token") as? String
|
||||
val spaceUser: String? = findProperty("publishing.space.user") as? String
|
||||
val spaceToken: String? = findProperty("publishing.space.token") as? String
|
||||
|
||||
if (spaceUser != null && spaceToken != null) {
|
||||
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
|
||||
@ -205,8 +203,10 @@ afterEvaluate {
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
|
||||
kotlinOptions.jvmTarget = "11"
|
||||
kotlin{
|
||||
jvmToolchain{
|
||||
languageVersion.set(JavaLanguageVersion.of(11))
|
||||
}
|
||||
}
|
||||
|
||||
tasks.processResources.configure {
|
||||
|
@ -1,11 +1,11 @@
|
||||
[versions]
|
||||
tools = "0.13.4-kotlin-1.8.0"
|
||||
tools = "0.14.0-kotlin-1.8.0"
|
||||
kotlin = "1.8.0"
|
||||
atomicfu = "0.18.5"
|
||||
atomicfu = "0.19.0"
|
||||
binary-compatibility-validator = "0.12.1"
|
||||
changelog = "2.0.0"
|
||||
dokka = "1.7.20"
|
||||
kotlin-jupyter = "0.11.0-216"
|
||||
kotlin-jupyter = "0.11.0-225"
|
||||
kotlinx-benchmark = "0.4.7"
|
||||
kotlinx-cli = "0.3.5"
|
||||
kotlinx-coroutines = "1.6.4"
|
||||
@ -13,12 +13,13 @@ kotlinx-datetime = "0.4.0"
|
||||
kotlinx-html = "0.8.0"
|
||||
kotlinx-knit = "0.4.0"
|
||||
kotlinx-nodejs = "0.0.7"
|
||||
kotlinx-serialization = "1.4.1"
|
||||
ktor = "2.2.1"
|
||||
kotlinx-serialization = "1.5.0-RC"
|
||||
ktor = "2.2.3"
|
||||
xmlutil = "0.84.3"
|
||||
yamlkt = "0.12.0"
|
||||
jsBom = "1.0.0-pre.466"
|
||||
junit = "5.8.2"
|
||||
jsBom = "1.0.0-pre.491"
|
||||
junit = "5.9.2"
|
||||
compose = "1.3.0"
|
||||
|
||||
[libraries]
|
||||
atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" }
|
||||
@ -81,6 +82,7 @@ yamlkt = { module = "net.mamoe.yamlkt:yamlkt", version.ref = "yamlkt" }
|
||||
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
|
||||
|
||||
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
|
||||
compose = {id = "org.jetbrains.compose", version.ref = "compose"}
|
||||
|
||||
gradle-common = { id = "space.kscience.gradle.common", version.ref = "tools" }
|
||||
gradle-project = { id = "space.kscience.gradle.project", version.ref = "tools" }
|
||||
|
@ -1,37 +1,26 @@
|
||||
package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.DuplicatesStrategy
|
||||
import org.gradle.api.plugins.ApplicationPlugin
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.gradle.language.jvm.tasks.ProcessResources
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlinx.jupyter.api.plugin.tasks.JupyterApiResourcesTask
|
||||
import space.kscience.gradle.internal.defaultPlatform
|
||||
import space.kscience.gradle.internal.defaultKotlinJvmArgs
|
||||
import space.kscience.gradle.internal.fromJsDependencies
|
||||
import space.kscience.gradle.internal.useCommonDependency
|
||||
import space.kscience.gradle.internal.useFx
|
||||
|
||||
public enum class FXModule(public val artifact: String, public vararg val dependencies: FXModule) {
|
||||
BASE("javafx-base"),
|
||||
GRAPHICS("javafx-graphics", BASE),
|
||||
CONTROLS("javafx-controls", GRAPHICS, BASE),
|
||||
FXML("javafx-fxml", BASE),
|
||||
MEDIA("javafx-media", GRAPHICS, BASE),
|
||||
SWING("javafx-swing", GRAPHICS, BASE),
|
||||
WEB("javafx-web", CONTROLS, GRAPHICS, BASE)
|
||||
}
|
||||
|
||||
public enum class FXPlatform(public val id: String) {
|
||||
WINDOWS("win"),
|
||||
LINUX("linux"),
|
||||
MAC("mac")
|
||||
}
|
||||
|
||||
public enum class DependencyConfiguration {
|
||||
API,
|
||||
@ -45,6 +34,15 @@ public enum class DependencySourceSet(public val setName: String, public val suf
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if this project version has a development tag (`development` property to true, "dev" in the middle or "SNAPSHOT" in the end).
|
||||
*/
|
||||
public val Project.isInDevelopment: Boolean
|
||||
get() = findProperty("development") == true
|
||||
|| "dev" in version.toString()
|
||||
|| version.toString().endsWith("SNAPSHOT")
|
||||
|
||||
|
||||
public open class KScienceExtension(public val project: Project) {
|
||||
|
||||
/**
|
||||
@ -90,43 +88,6 @@ public open class KScienceExtension(public val project: Project) {
|
||||
SerializationTargets(sourceSet, configuration).block()
|
||||
}
|
||||
|
||||
/**
|
||||
* Add platform-specific JavaFX dependencies with given list of [FXModule]s
|
||||
*/
|
||||
@Deprecated("Use manual FX configuration")
|
||||
public fun useFx(
|
||||
vararg modules: FXModule,
|
||||
configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY,
|
||||
version: String = "11",
|
||||
platform: FXPlatform = defaultPlatform,
|
||||
): Unit = project.useFx(modules.toList(), configuration, version, platform)
|
||||
|
||||
/**
|
||||
* Add dependency on kotlinx-html library
|
||||
*/
|
||||
public fun useHtml(
|
||||
version: String = KScienceVersions.htmlVersion,
|
||||
sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
|
||||
configuration: DependencyConfiguration = DependencyConfiguration.API,
|
||||
): Unit = project.useCommonDependency(
|
||||
"org.jetbrains.kotlinx:kotlinx-html:$version",
|
||||
dependencySourceSet = sourceSet,
|
||||
dependencyConfiguration = configuration
|
||||
)
|
||||
|
||||
/**
|
||||
* Use kotlinx-datetime library with default version or [version]
|
||||
*/
|
||||
public fun useDateTime(
|
||||
version: String = KScienceVersions.dateTimeVersion,
|
||||
sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
|
||||
configuration: DependencyConfiguration = DependencyConfiguration.API,
|
||||
): Unit = project.useCommonDependency(
|
||||
"org.jetbrains.kotlinx:kotlinx-datetime:$version",
|
||||
dependencySourceSet = sourceSet,
|
||||
dependencyConfiguration = configuration
|
||||
)
|
||||
|
||||
/**
|
||||
* Apply jupyter plugin and add entry point for the jupyter library.
|
||||
* If left empty applies a plugin without declaring library producers
|
||||
@ -138,7 +99,9 @@ public open class KScienceExtension(public val project: Project) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply common dependencies for different kind of targets
|
||||
*/
|
||||
public fun dependencies(sourceSet: String? = null, dependencyBlock: KotlinDependencyHandler.() -> Unit) {
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
||||
project.configure<KotlinJvmProjectExtension> {
|
||||
@ -268,49 +231,105 @@ public class KScienceNativeConfiguration {
|
||||
|
||||
public open class KScienceMppExtension(project: Project) : KScienceExtension(project) {
|
||||
/**
|
||||
* Custom configuration for JVM target. If null - disable JVM target
|
||||
* Enable jvm target
|
||||
*/
|
||||
public fun jvm(block: KotlinJvmTarget.() -> Unit) {
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
project.configure<KotlinMultiplatformExtension> {
|
||||
jvm(block)
|
||||
jvm {
|
||||
compilations.all {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs
|
||||
}
|
||||
}
|
||||
block()
|
||||
}
|
||||
sourceSets {
|
||||
getByName("jvmMain") {
|
||||
dependencies {
|
||||
implementation(kotlin("test-junit5"))
|
||||
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
|
||||
}
|
||||
}
|
||||
getByName("jvmTest") {
|
||||
dependencies {
|
||||
implementation(kotlin("test-js"))
|
||||
}
|
||||
}
|
||||
}
|
||||
jvmToolchain {
|
||||
languageVersion.set(KScienceVersions.JVM_TARGET)
|
||||
}
|
||||
}
|
||||
project.tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Jvm target
|
||||
*/
|
||||
public fun noJvm() {
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
project.configure<KotlinMultiplatformExtension> {
|
||||
targets.removeIf { it is KotlinJvmTarget }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom configuration for JS target. If null - disable JS target
|
||||
* Enable JS-IR (browser) target.
|
||||
*/
|
||||
public fun js(block: KotlinJsTargetDsl.() -> Unit) {
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
project.configure<KotlinMultiplatformExtension> {
|
||||
js(block)
|
||||
js(IR) {
|
||||
browser()
|
||||
block()
|
||||
}
|
||||
}
|
||||
(project.tasks.findByName("jsProcessResources") as? Copy)?.apply {
|
||||
fromJsDependencies("jsRuntimeClasspath")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fun noJs() {
|
||||
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
project.configure<KotlinMultiplatformExtension> {
|
||||
targets.removeIf { it is KotlinJsTargetDsl }
|
||||
public fun jvmAndJs() {
|
||||
jvm {}
|
||||
js {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Jvm and Js source sets including copy of Js bundle into JVM resources
|
||||
*/
|
||||
public fun fullStack(
|
||||
bundleName: String = "js/bundle.js",
|
||||
jvmConfig: KotlinJvmTarget.() -> Unit = {},
|
||||
jsConfig: KotlinJsTargetDsl.() -> Unit = {},
|
||||
browserConfig: KotlinJsBrowserDsl.() -> Unit = {},
|
||||
) {
|
||||
js {
|
||||
binaries.executable()
|
||||
browser {
|
||||
webpackTask {
|
||||
outputFileName = bundleName
|
||||
}
|
||||
browserConfig()
|
||||
}
|
||||
jsConfig()
|
||||
}
|
||||
jvm {
|
||||
val processResourcesTaskName =
|
||||
compilations[org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.MAIN_COMPILATION_NAME]
|
||||
.processResourcesTaskName
|
||||
|
||||
val jsBrowserDistribution = project.tasks.getByName("jsBrowserDistribution")
|
||||
|
||||
project.tasks.getByName<ProcessResources>(processResourcesTaskName) {
|
||||
duplicatesStrategy = DuplicatesStrategy.WARN
|
||||
dependsOn(jsBrowserDistribution)
|
||||
from(jsBrowserDistribution)
|
||||
}
|
||||
jvmConfig()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable all supported native targets
|
||||
*/
|
||||
public fun native(block: KScienceNativeConfiguration.() -> Unit = {}): Unit = with(project) {
|
||||
val nativeConfiguration = KScienceNativeConfiguration().apply(block)
|
||||
pluginManager.withPlugin("space.kscience.gradle.mpp") {
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
configure<KotlinMultiplatformExtension> {
|
||||
sourceSets {
|
||||
val nativeTargets: List<KotlinNativeTarget> =
|
||||
|
@ -2,6 +2,14 @@ package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.jetbrains.dokka.gradle.DokkaPlugin
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
|
||||
import space.kscience.gradle.internal.applySettings
|
||||
import space.kscience.gradle.internal.fromJsDependencies
|
||||
|
||||
public open class KScienceJSPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project): Unit = project.run {
|
||||
@ -10,6 +18,39 @@ public open class KScienceJSPlugin : Plugin<Project> {
|
||||
} else {
|
||||
logger.info("Kotlin JS plugin is already present")
|
||||
}
|
||||
project.configureKScience()
|
||||
registerKScienceExtension(::KScienceExtension)
|
||||
|
||||
//logger.info("Applying KScience configuration for JS project")
|
||||
configure<KotlinJsProjectExtension> {
|
||||
js(IR) { browser { } }
|
||||
|
||||
sourceSets.all {
|
||||
languageSettings.applySettings()
|
||||
}
|
||||
|
||||
sourceSets["main"].apply {
|
||||
dependencies {
|
||||
api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}"))
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets["test"].apply {
|
||||
dependencies {
|
||||
implementation(kotlin("test-js"))
|
||||
}
|
||||
}
|
||||
|
||||
if (explicitApi == null) explicitApiWarning()
|
||||
}
|
||||
|
||||
(tasks.findByName("processResources") as? Copy)?.apply {
|
||||
fromJsDependencies("runtimeClasspath")
|
||||
}
|
||||
|
||||
|
||||
// apply dokka for all projects
|
||||
if (!plugins.hasPlugin("org.jetbrains.dokka")) {
|
||||
apply<DokkaPlugin>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,16 @@ package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.jetbrains.dokka.gradle.DokkaPlugin
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import space.kscience.gradle.internal.applySettings
|
||||
import space.kscience.gradle.internal.defaultKotlinJvmArgs
|
||||
|
||||
public open class KScienceJVMPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project): Unit = project.run {
|
||||
@ -10,6 +20,41 @@ public open class KScienceJVMPlugin : Plugin<Project> {
|
||||
} else {
|
||||
logger.info("Kotlin JVM plugin is already present")
|
||||
}
|
||||
project.configureKScience()
|
||||
registerKScienceExtension(::KScienceExtension)
|
||||
|
||||
//logger.info("Applying KScience configuration for JVM project")
|
||||
configure<KotlinJvmProjectExtension> {
|
||||
sourceSets.all {
|
||||
languageSettings.applySettings()
|
||||
}
|
||||
|
||||
sourceSets["test"].apply {
|
||||
dependencies {
|
||||
implementation(kotlin("test-junit5"))
|
||||
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
|
||||
}
|
||||
}
|
||||
|
||||
if (explicitApi == null) explicitApiWarning()
|
||||
jvmToolchain {
|
||||
languageVersion.set(KScienceVersions.JVM_TARGET)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
// apply dokka for all projects
|
||||
if (!plugins.hasPlugin("org.jetbrains.dokka")) {
|
||||
apply<DokkaPlugin>()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,14 @@ package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.hasPlugin
|
||||
import org.gradle.kotlin.dsl.invoke
|
||||
import org.jetbrains.dokka.gradle.DokkaPlugin
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
|
||||
import space.kscience.gradle.internal.applySettings
|
||||
|
||||
public open class KScienceMPPlugin : Plugin<Project> {
|
||||
override fun apply(project: Project): Unit = project.run {
|
||||
@ -13,6 +19,36 @@ public open class KScienceMPPlugin : Plugin<Project> {
|
||||
} else {
|
||||
logger.info("Kotlin MPP plugin is already present")
|
||||
}
|
||||
project.configureKScience()
|
||||
|
||||
registerKScienceExtension(::KScienceMppExtension)
|
||||
|
||||
configure<KotlinMultiplatformExtension> {
|
||||
|
||||
sourceSets {
|
||||
getByName("commonMain"){
|
||||
dependencies {
|
||||
api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}"))
|
||||
}
|
||||
}
|
||||
getByName("commonTest"){
|
||||
dependencies {
|
||||
implementation(kotlin("test-common"))
|
||||
implementation(kotlin("test-annotations-common"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.all {
|
||||
languageSettings.applySettings()
|
||||
}
|
||||
|
||||
if (explicitApi == null) explicitApiWarning()
|
||||
}
|
||||
|
||||
|
||||
// apply dokka for all projects
|
||||
if (!plugins.hasPlugin("org.jetbrains.dokka")) {
|
||||
apply<DokkaPlugin>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,11 +90,6 @@ public class KScienceReadmeExtension(public val project: Project) {
|
||||
|
||||
public val features: MutableList<Feature> = ArrayList()
|
||||
|
||||
@Deprecated("Use lambda builder instead.")
|
||||
public fun feature(id: String, description: String, ref: String? = null, name: String = id) {
|
||||
features += Feature(id, description, ref, name)
|
||||
}
|
||||
|
||||
public fun feature(id: String, ref: String? = null, name: String = id, description: () -> String) {
|
||||
features += Feature(id, description(), ref, name)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package space.kscience.gradle
|
||||
|
||||
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
||||
import org.tomlj.Toml
|
||||
|
||||
/**
|
||||
@ -24,7 +24,7 @@ public object KScienceVersions {
|
||||
public val jsBom: String get() = toml.getString("versions.jsBom")!!
|
||||
internal val junit: String get() = toml.getString("versions.junit")!!
|
||||
|
||||
public val JVM_TARGET: JavaVersion = JavaVersion.VERSION_11
|
||||
public val JVM_TARGET: JavaLanguageVersion = JavaLanguageVersion.of(11)
|
||||
|
||||
public object Serialization {
|
||||
public val xmlVersion: String get() = toml.getString("versions.xmlutil")!!
|
||||
|
@ -1,175 +0,0 @@
|
||||
package space.kscience.gradle
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaPluginExtension
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.kotlin.dsl.*
|
||||
import org.jetbrains.dokka.gradle.DokkaPlugin
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import space.kscience.gradle.internal.applyRepos
|
||||
import space.kscience.gradle.internal.applySettings
|
||||
import space.kscience.gradle.internal.fromJsDependencies
|
||||
|
||||
|
||||
private val defaultKotlinJvmArgs: List<String> =
|
||||
listOf("-Xjvm-default=all", "-Xlambdas=indy"/* "-Xjdk-release=${KScienceVersions.JVM_TARGET}"*/)
|
||||
|
||||
private fun resolveKotlinVersion(): KotlinVersion {
|
||||
val (major, minor, patch) = KScienceVersions.kotlinVersion.split(".", "-")
|
||||
return KotlinVersion(major.toInt(), minor.toInt(), patch.toInt())
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if this project version has a development tag (`development` property to true, "dev" in the middle or "SNAPSHOT" in the end).
|
||||
*/
|
||||
public val Project.isInDevelopment: Boolean
|
||||
get() = findProperty("development") == true
|
||||
|| "dev" in version.toString()
|
||||
|| version.toString().endsWith("SNAPSHOT")
|
||||
|
||||
/**
|
||||
* Configure KScience extensions
|
||||
*/
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
public fun Project.configureKScience(
|
||||
kotlinVersion: KotlinVersion = resolveKotlinVersion(),
|
||||
) {
|
||||
repositories.applyRepos()
|
||||
|
||||
//Configuration for K-JVM plugin
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
||||
val extension = registerKScienceExtension(::KScienceExtension)
|
||||
|
||||
//logger.info("Applying KScience configuration for JVM project")
|
||||
configure<KotlinJvmProjectExtension> {
|
||||
sourceSets.all {
|
||||
languageSettings.applySettings(kotlinVersion)
|
||||
}
|
||||
|
||||
sourceSets["test"].apply {
|
||||
dependencies {
|
||||
implementation(kotlin("test-junit5"))
|
||||
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
|
||||
}
|
||||
}
|
||||
|
||||
if (explicitApi == null) explicitApiWarning()
|
||||
}
|
||||
tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
jvmTarget = KScienceVersions.JVM_TARGET.toString()
|
||||
freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs
|
||||
}
|
||||
}
|
||||
|
||||
extensions.findByType<JavaPluginExtension>()?.apply {
|
||||
targetCompatibility = KScienceVersions.JVM_TARGET
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
}
|
||||
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
|
||||
val extension = registerKScienceExtension(::KScienceExtension)
|
||||
|
||||
//logger.info("Applying KScience configuration for JS project")
|
||||
configure<KotlinJsProjectExtension> {
|
||||
js(IR) { browser { } }
|
||||
|
||||
sourceSets.all {
|
||||
languageSettings.applySettings(kotlinVersion)
|
||||
}
|
||||
|
||||
sourceSets["main"].apply {
|
||||
dependencies {
|
||||
api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}"))
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets["test"].apply {
|
||||
dependencies {
|
||||
implementation(kotlin("test-js"))
|
||||
}
|
||||
}
|
||||
|
||||
if (explicitApi == null) explicitApiWarning()
|
||||
}
|
||||
|
||||
(tasks.findByName("processResources") as? Copy)?.apply {
|
||||
fromJsDependencies("runtimeClasspath")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
val extension = registerKScienceExtension(::KScienceMppExtension)
|
||||
|
||||
configure<KotlinMultiplatformExtension> {
|
||||
jvm {
|
||||
compilations.all {
|
||||
kotlinOptions {
|
||||
jvmTarget = KScienceVersions.JVM_TARGET.toString()
|
||||
freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
js(IR) { browser { } }
|
||||
|
||||
sourceSets {
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}"))
|
||||
}
|
||||
}
|
||||
val commonTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-common"))
|
||||
implementation(kotlin("test-annotations-common"))
|
||||
}
|
||||
}
|
||||
val jvmTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-junit5"))
|
||||
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
|
||||
}
|
||||
}
|
||||
val jsTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-js"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.all {
|
||||
languageSettings.applySettings(kotlinVersion)
|
||||
}
|
||||
|
||||
(tasks.findByName("jsProcessResources") as? Copy)?.apply {
|
||||
fromJsDependencies("jsRuntimeClasspath")
|
||||
}
|
||||
|
||||
extensions.findByType<JavaPluginExtension>()?.apply {
|
||||
targetCompatibility = KScienceVersions.JVM_TARGET
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
if (explicitApi == null) explicitApiWarning()
|
||||
}
|
||||
}
|
||||
|
||||
// apply dokka for all projects
|
||||
if (!plugins.hasPlugin("org.jetbrains.dokka")) {
|
||||
apply<DokkaPlugin>()
|
||||
}
|
||||
}
|
@ -2,17 +2,23 @@ package space.kscience.gradle.internal
|
||||
|
||||
import org.gradle.api.artifacts.ProjectDependency
|
||||
import org.gradle.api.artifacts.dsl.RepositoryHandler
|
||||
import org.gradle.api.file.DuplicatesStrategy
|
||||
import org.gradle.api.tasks.Copy
|
||||
import org.gradle.kotlin.dsl.get
|
||||
import org.gradle.kotlin.dsl.getByName
|
||||
import org.gradle.kotlin.dsl.maven
|
||||
import org.gradle.language.jvm.tasks.ProcessResources
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
|
||||
import space.kscience.gradle.KScienceVersions
|
||||
|
||||
|
||||
internal val defaultKotlinJvmArgs: List<String> =
|
||||
listOf("-Xjvm-default=all", "-Xlambdas=indy"/* "-Xjdk-release=${KScienceVersions.JVM_TARGET}"*/)
|
||||
|
||||
internal fun resolveKotlinVersion(): KotlinVersion {
|
||||
val (major, minor, patch) = KScienceVersions.kotlinVersion.split(".", "-")
|
||||
return KotlinVersion(major.toInt(), minor.toInt(), patch.toInt())
|
||||
}
|
||||
|
||||
internal fun LanguageSettingsBuilder.applySettings(
|
||||
kotlinVersion: KotlinVersion
|
||||
kotlinVersion: KotlinVersion = resolveKotlinVersion(),
|
||||
) {
|
||||
val versionString = "${kotlinVersion.major}.${kotlinVersion.minor}"
|
||||
languageVersion = versionString
|
||||
@ -52,52 +58,4 @@ internal fun Copy.fromJsDependencies(configurationName: String) = project.run {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun KotlinMultiplatformExtension.bundleJsBinaryAsResource(bundleName: String = "js/bundle.js") {
|
||||
js(IR) {
|
||||
binaries.executable()
|
||||
browser {
|
||||
webpackTask {
|
||||
outputFileName = bundleName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jvm {
|
||||
val processResourcesTaskName =
|
||||
compilations[org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.MAIN_COMPILATION_NAME]
|
||||
.processResourcesTaskName
|
||||
|
||||
val jsBrowserDistribution = project.tasks.getByName("jsBrowserDistribution")
|
||||
|
||||
project.tasks.getByName<ProcessResources>(processResourcesTaskName) {
|
||||
duplicatesStrategy = DuplicatesStrategy.WARN
|
||||
dependsOn(jsBrowserDistribution)
|
||||
from(jsBrowserDistribution)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
//internal fun Copy.copyJVMResources(configuration: Configuration): Unit = project.afterEvaluate {
|
||||
// val projectDeps = configuration.allDependencies
|
||||
// .filterIsInstance<ProjectDependency>()
|
||||
// .map { it.dependencyProject }
|
||||
//
|
||||
// projectDeps.forEach { dep ->
|
||||
// dep.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
// dep.tasks.findByName("jvmProcessResources")?.let { task ->
|
||||
// dependsOn(task)
|
||||
// from(task)
|
||||
// }
|
||||
// }
|
||||
// dep.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
||||
// dep.tasks.findByName("processResources")?.let { task ->
|
||||
// dependsOn(task)
|
||||
// from(task)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package space.kscience.gradle.internal
|
||||
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.findByType
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
|
||||
import space.kscience.gradle.DependencyConfiguration
|
||||
import space.kscience.gradle.FXModule
|
||||
import space.kscience.gradle.FXPlatform
|
||||
|
||||
internal val defaultPlatform: FXPlatform = when {
|
||||
Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS
|
||||
Os.isFamily(Os.FAMILY_MAC) -> FXPlatform.MAC
|
||||
Os.isFamily(Os.FAMILY_UNIX) -> FXPlatform.LINUX
|
||||
else -> error("Platform not recognized")
|
||||
}
|
||||
|
||||
private fun KotlinDependencyHandler.addFXDependencies(
|
||||
modules: List<FXModule>,
|
||||
configuration: DependencyConfiguration,
|
||||
version: String = "14",
|
||||
platform: FXPlatform = defaultPlatform
|
||||
) {
|
||||
modules.flatMap { it.dependencies.toList() + it }.distinct().forEach {
|
||||
val notation = "org.openjfx:${it.artifact}:$version:${platform.id}"
|
||||
when (configuration) {
|
||||
DependencyConfiguration.API -> api(notation)
|
||||
DependencyConfiguration.IMPLEMENTATION -> implementation(notation)
|
||||
DependencyConfiguration.COMPILE_ONLY -> compileOnly(notation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Project.useFx(
|
||||
modules: List<FXModule>,
|
||||
configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY,
|
||||
version: String = "14",
|
||||
platform: FXPlatform = defaultPlatform
|
||||
): Unit = afterEvaluate {
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
|
||||
extensions.findByType<KotlinMultiplatformExtension>()?.apply {
|
||||
sourceSets.findByName("jvmMain")?.apply {
|
||||
dependencies {
|
||||
addFXDependencies(modules, configuration = configuration, version = version, platform = platform)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
||||
extensions.findByType<KotlinJvmProjectExtension>()?.apply {
|
||||
sourceSets.findByName("main")?.apply {
|
||||
dependencies {
|
||||
addFXDependencies(modules, configuration = configuration, version = version, platform = platform)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user