Merge pull request #5 from mipt-npm/dev

Dev
This commit is contained in:
Alexander Nozik 2020-12-28 09:44:14 +03:00 committed by GitHub
commit 03977e4751
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 926 additions and 629 deletions

View File

@ -6,17 +6,59 @@ 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
### Added
### Changed
### Deprecated
### Removed
### Fixed
### Security
## [0.7.0]
### Added
- Changelog plugin automatically applied to `project`.
- Feature matrix and Readme generation task for a `project` plugin.
- Add `binary-compatibility-validator` to the `project` plugin.
- Separate `yamlKt` serialization target
- Moved all logic to a common plugin, leaving only proxies for platform plugins
### Changed
- Remove node plugin. Node binaries should be turned on manually.
- Use default webpack distribution path.
- `ru.mipt.npm.base` -> `ru.mipt.npm.project`.
- Move publishing out of general extension and apply it to project plugin instead.
- Platform plugins are now simple references to common plugin
- FX configuration moved to extension
- Moved internals to internals
### Deprecated
- Support of `kaml` and `snake-yaml` in favor of `yamlKt`
- Publish plugin
### Removed
- `useDokka` method. Documentation jar should be added manually if needed.
### Fixed
### Security
## [0.6.0]
### Added ### Added
- Migrate to kotlin 1.4.0 - Migrate to kotlin 1.4.0
- Separate Native (current platform) and nodeJs plugins - Separate Native (current platform) and nodeJs plugins.
- Add `application()` toggle in plugin configuration to produce binaries on JS and applicaion plugin on jvm. - Add `application()` toggle in plugin configuration to produce binaries on JS and applicaion plugin on jvm.
- Add `publish` to expose publishing configuration - Add `publish` to expose publishing configuration.
### Changed ### Changed
-Publishing in bintray now is automatic -Publishing in bintray now is automatic.
## [0.5.2] ## [0.5.2]
### Added ### Added
- Copy resources for jvm modules and jvm source sets in mpp - Copy resources for jvm modules and jvm source sets in mpp.

View File

@ -2,11 +2,11 @@ plugins {
`java-gradle-plugin` `java-gradle-plugin`
`kotlin-dsl` `kotlin-dsl`
`maven-publish` `maven-publish`
id("org.jetbrains.changelog") version "0.4.0" id("org.jetbrains.changelog") version "0.6.2"
} }
group = "ru.mipt.npm" group = "ru.mipt.npm"
version = "0.6.0" version = "0.7.1"
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
@ -16,7 +16,7 @@ repositories {
maven("https://dl.bintray.com/kotlin/kotlin-dev") maven("https://dl.bintray.com/kotlin/kotlin-dev")
} }
val kotlinVersion = "1.4.10" val kotlinVersion = "1.4.21"
java { java {
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
@ -26,18 +26,27 @@ java {
dependencies { dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.4") implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.15.0")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.0") implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.20")
implementation("org.jetbrains.dokka:dokka-base:1.4.0") implementation("org.jetbrains.dokka:dokka-base:1.4.20")
implementation("org.jetbrains.intellij.plugins:gradle-changelog-plugin:0.6.2")
implementation("org.jetbrains.kotlinx:binary-compatibility-validator:0.2.4")
} }
gradlePlugin { gradlePlugin {
plugins { plugins {
create("kscience.base"){ create("kscience.common"){
id = "ru.mipt.npm.base" id = "ru.mipt.npm.kscience"
description = "The basic plugin that does not do anything but loading classpath, versions and extensions" description = "The generalized kscience plugin that works in conjunction with any kotlin plugin"
implementationClass = "ru.mipt.npm.gradle.KScienceBasePlugin" implementationClass = "ru.mipt.npm.gradle.KScienceCommonPlugin"
} }
create("kscience.project"){
id = "ru.mipt.npm.project"
description = "The root plugin for multimodule project infrastructure"
implementationClass = "ru.mipt.npm.gradle.KScienceProjectPlugin"
}
create("kscience.publish") { create("kscience.publish") {
id = "ru.mipt.npm.publish" id = "ru.mipt.npm.publish"
description = "The publication plugin for bintray and github" description = "The publication plugin for bintray and github"
@ -70,7 +79,7 @@ gradlePlugin {
create("kscience.node") { create("kscience.node") {
id = "ru.mipt.npm.node" id = "ru.mipt.npm.node"
description = "NodeJS target for kotlin-mpp and kotlin-js" description = "Additional nodejs target to be use alongside mpp"
implementationClass = "ru.mipt.npm.gradle.KScienceNodePlugin" implementationClass = "ru.mipt.npm.gradle.KScienceNodePlugin"
} }
} }

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -1,13 +0,0 @@
package ru.mipt.npm.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
/**
* Apply extension and repositories
*/
open class KScienceBasePlugin : Plugin<Project> {
override fun apply(target: Project): Unit = target.run{
registerKScienceExtension()
}
}

View File

@ -0,0 +1,147 @@
package ru.mipt.npm.gradle
import org.gradle.api.Plugin
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.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import ru.mipt.npm.gradle.internal.applyRepos
import ru.mipt.npm.gradle.internal.applySettings
import ru.mipt.npm.gradle.internal.fromDependencies
open class KScienceCommonPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run {
//Common configuration
registerKScienceExtension()
repositories.applyRepos()
// apply dokka for all projects
if (!plugins.hasPlugin("org.jetbrains.dokka")) {
plugins.apply("org.jetbrains.dokka")
}
//Configuration for K-JVM plugin
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
//logger.info("Applying KScience configuration for JVM project")
configure<KotlinJvmProjectExtension> {
explicitApiWarning()
sourceSets["main"].apply {
languageSettings.applySettings()
}
sourceSets["test"].apply {
languageSettings.applySettings()
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:5.6.1")
}
}
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
//logger.info("Applying KScience configuration for JS project")
configure<KotlinJsProjectExtension> {
explicitApiWarning()
js(IR) {
browser()
}
sourceSets["main"].apply {
languageSettings.applySettings()
}
sourceSets["test"].apply {
languageSettings.applySettings()
dependencies {
implementation(kotlin("test-js"))
}
}
}
(tasks.findByName("processResources") as? Copy)?.apply {
fromDependencies("runtimeClasspath")
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> {
explicitApiWarning()
jvm {
compilations.all {
kotlinOptions {
// useIR = true
jvmTarget = KScienceVersions.JVM_TARGET.toString()
}
}
}
js(IR) {
browser()
}
sourceSets.invoke {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmMain by getting
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:5.6.1")
}
}
val jsMain by getting
val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}
}
afterEvaluate {
targets.all {
sourceSets.all {
languageSettings.applySettings()
}
}
}
(tasks.findByName("jsProcessResources") as? Copy)?.apply {
fromDependencies("jsRuntimeClasspath")
}
}
}
afterEvaluate {
extensions.findByType<JavaPluginExtension>()?.apply {
targetCompatibility = KScienceVersions.JVM_TARGET
}
tasks.apply {
withType<KotlinJvmCompile> {
kotlinOptions {
// useIR = true
jvmTarget = KScienceVersions.JVM_TARGET.toString()
}
}
withType<Test> {
useJUnitPlatform()
}
}
}
}
}

View File

@ -1,11 +1,44 @@
package ru.mipt.npm.gradle package ru.mipt.npm.gradle
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.* import org.gradle.api.plugins.ApplicationPlugin
import org.gradle.kotlin.dsl.findByType
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import ru.mipt.npm.gradle.internal.configurePublishing
import ru.mipt.npm.gradle.internal.defaultPlatform
import ru.mipt.npm.gradle.internal.useCommonDependency
import ru.mipt.npm.gradle.internal.useFx
enum class FXModule(val artifact: String, 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)
}
enum class FXPlatform(val id: String) {
WINDOWS("win"),
LINUX("linux"),
MAC("mac")
}
enum class DependencyConfiguration {
API,
IMPLEMENTATION,
COMPILE_ONLY
}
enum class DependencySourceSet(val setName: String, val suffix: String) {
MAIN("main", "Main"),
TEST("test", "Test")
}
class KScienceExtension(val project: Project) { class KScienceExtension(val project: Project) {
@ -59,9 +92,12 @@ class KScienceExtension(val project: Project) {
) )
} }
fun useDokka(): Unit = project.run { fun useFx(
plugins.apply("org.jetbrains.dokka") vararg modules: FXModule,
} configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY,
version: String = "14",
platform: FXPlatform = defaultPlatform
) = project.useFx(modules.toList(), configuration, version, platform)
/** /**
* Mark this module as an application module. JVM application should be enabled separately * Mark this module as an application module. JVM application should be enabled separately
@ -70,46 +106,29 @@ class KScienceExtension(val project: Project) {
project.extensions.findByType<KotlinProjectExtension>()?.apply { project.extensions.findByType<KotlinProjectExtension>()?.apply {
explicitApi = null explicitApi = null
} }
project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
project.plugins.apply("org.gradle.application") project.plugins.apply(ApplicationPlugin::class.java)
} }
project.extensions.findByType<KotlinJsProjectExtension>()?.apply { project.extensions.findByType<KotlinJsProjectExtension>()?.apply {
js { js {
binaries.executable() binaries.executable()
} }
} }
project.extensions.findByType<KotlinMultiplatformExtension>()?.apply { project.extensions.findByType<KotlinMultiplatformExtension>()?.apply {
js { js {
binaries.executable() binaries.executable()
} }
(targets.findByName("native") as? KotlinNativeTarget)?.apply { targets.filterIsInstance<KotlinNativeTarget>().forEach {
binaries.executable() it.binaries.executable()
} }
} }
} }
/** fun publish() {
* Activate publishing and configure it project.configurePublishing()
*/
fun publish(block: Publishing.() -> Unit = {}) = Publishing().apply(block)
inner class Publishing {
init {
if (project.plugins.findPlugin(KSciencePublishPlugin::class) == null) {
project.plugins.apply(KSciencePublishPlugin::class)
}
}
var githubOrg: String? by project.extra
var githubProject: String? by project.extra
var spaceRepo: String? by project.extra
var spaceUser: String? by project.extra
var spaceToken: String? by project.extra
var bintrayOrg: String? by project.extra
var bintrayUser: String? by project.extra
var bintrayApiKey: String? by project.extra
var bintrayRepo: String? by project.extra
} }
} }

View File

@ -2,62 +2,15 @@ package ru.mipt.npm.gradle
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project 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.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
open class KScienceJSPlugin : Plugin<Project> { open class KScienceJSPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.js") if (plugins.findPlugin("org.jetbrains.kotlin.js") == null) {
registerKScienceExtension() pluginManager.apply("org.jetbrains.kotlin.js")
} else {
repositories.applyRepos() logger.info("Kotlin JS plugin is already present")
configure<KotlinJsProjectExtension> {
explicitApiWarning()
js(IR) {
browser {
webpackTask {
outputFileName = "main.bundle.js"
}
distribution {
directory = project.jsDistDirectory
}
}
}
sourceSets["main"].apply {
languageSettings.applySettings()
dependencies {
api(kotlin("stdlib-js"))
}
}
sourceSets["test"].apply {
languageSettings.applySettings()
dependencies {
implementation(kotlin("test-js"))
}
}
}
tasks.apply {
val processResources by getting(Copy::class)
processResources.copyJSResources(configurations["runtimeClasspath"])
findByName("jsBrowserDistribution")?.apply {
doLast {
val indexFile = project.jsDistDirectory.resolve("index.html")
if (indexFile.exists()) {
println("Run JS distribution at: ${indexFile.canonicalPath}")
}
}
}
} }
plugins.apply(KScienceCommonPlugin::class)
} }
} }

View File

@ -2,86 +2,15 @@ package ru.mipt.npm.gradle
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension import org.gradle.kotlin.dsl.apply
import org.gradle.api.publish.PublishingExtension
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.testing.Test
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
open class KScienceJVMPlugin : Plugin<Project> { open class KScienceJVMPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.jvm") if (plugins.findPlugin("org.jetbrains.kotlin.jvm") == null) {
registerKScienceExtension() pluginManager.apply("org.jetbrains.kotlin.jvm")
} else {
repositories.applyRepos() logger.info("Kotlin JVM plugin is already present")
extensions.findByType<JavaPluginExtension>()?.apply {
targetCompatibility = KScienceVersions.JVM_TARGET
}
tasks.withType<KotlinCompile> {
kotlinOptions {
// useIR = true
jvmTarget = KScienceVersions.JVM_TARGET.toString()
}
}
configure<KotlinJvmProjectExtension> {
explicitApiWarning()
val sourceSet = sourceSets["main"].apply {
languageSettings.applySettings()
}
sourceSets["test"].apply {
languageSettings.applySettings()
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:5.6.1")
}
}
val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSet.kotlin.srcDirs.first())
}
pluginManager.withPlugin("maven-publish") {
configure<PublishingExtension> {
publications {
register("jvm", MavenPublication::class) {
from(components["java"])
artifact(sourcesJar.get())
}
}
}
// pluginManager.withPlugin("org.jetbrains.dokka") {
// logger.info("Adding dokka functionality to project ${project.name}")
// val dokkaHtml by tasks.getting(DokkaTask::class){
// dokkaSourceSets {
// configureEach {
// jdkVersion.set(11)
// }
// }
// }
// }
}
}
tasks.apply {
withType<Test>() {
useJUnitPlatform()
}
val processResources by getting(Copy::class)
processResources.copyJVMResources(configurations["runtimeClasspath"])
} }
plugins.apply(KScienceCommonPlugin::class)
} }
} }

View File

@ -2,116 +2,15 @@ package ru.mipt.npm.gradle
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.tasks.Copy import org.gradle.kotlin.dsl.apply
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
open class KScienceMPPlugin : Plugin<Project> { open class KScienceMPPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.multiplatform") if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) {
registerKScienceExtension() pluginManager.apply("org.jetbrains.kotlin.multiplatform")
repositories.applyRepos() } else {
logger.info("Kotlin MPP plugin is already present")
configure<KotlinMultiplatformExtension> {
explicitApiWarning()
jvm {
compilations.all {
kotlinOptions {
// useIR = true
jvmTarget = KScienceVersions.JVM_TARGET.toString()
}
}
}
js(IR) {
browser {
webpackTask {
outputFileName = "main.bundle.js"
}
distribution {
directory = project.jsDistDirectory
}
}
}
sourceSets.invoke {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmMain by getting
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:5.6.1")
}
}
val jsMain by getting
val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}
}
afterEvaluate {
targets.all {
sourceSets.all {
languageSettings.applySettings()
}
}
}
// pluginManager.withPlugin("org.jetbrains.dokka") {
// logger.info("Adding dokka functionality to project ${this@run.name}")
//
// val dokkaHtml by tasks.getting(DokkaTask::class) {
// dokkaSourceSets {
// register("commonMain") {
// displayName = "common"
// platform = "common"
// }
// register("jvmMain") {
// displayName = "jvm"
// platform = "jvm"
// }
// register("jsMain") {
// displayName = "js"
// platform = "js"
// }
// configureEach {
// jdkVersion = 11
// }
// }
// }
// }
tasks.apply {
withType<Test>() {
useJUnitPlatform()
}
val jsProcessResources by getting(Copy::class)
jsProcessResources.copyJSResources(configurations["jsRuntimeClasspath"])
val jvmProcessResources by getting(Copy::class)
jvmProcessResources.copyJVMResources(configurations["jvmRuntimeClasspath"])
findByName("jsBrowserDistribution")?.apply {
doLast {
val indexFile = project.jsDistDirectory.resolve("index.html")
if (indexFile.exists()) {
println("Run JS distribution at: ${indexFile.canonicalPath}")
}
}
}
}
} }
} plugins.apply(KScienceCommonPlugin::class)
}
} }

View File

@ -9,30 +9,71 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
class KScienceNativePlugin : Plugin<Project> { class KScienceNativePlugin : Plugin<Project> {
override fun apply(target: Project) = target.run { override fun apply(target: Project) = target.run {
//Apply multiplatform plugin is not applied, apply it //Apply multiplatform plugin is not applied, apply it
if (plugins.findPlugin(KScienceMPPlugin::class) == null) { if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) {
logger.info("Multiplatform KScience plugin is not resolved. Adding it automatically") logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically")
pluginManager.apply(KScienceMPPlugin::class) pluginManager.apply("org.jetbrains.kotlin.multiplatform")
}
if (plugins.findPlugin(KScienceCommonPlugin::class) == null) {
logger.info("KScience plugin is not resolved. Adding it automatically")
pluginManager.apply(KScienceCommonPlugin::class)
} }
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {
val hostOs = System.getProperty("os.name") val ideaActive = System.getProperty("idea.active") == "true"
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when { if (ideaActive) {
hostOs == "Mac OS X" -> macosX64("native") //development mode
hostOs == "Linux" -> linuxX64("native") val hostOs = System.getProperty("os.name")
isMingwX64 -> {
mingwX64("native") when {
linuxX64() hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
hostOs.startsWith("Windows") -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
} }
else -> throw GradleException("Host OS is not supported in Kotlin/Native.") } else {
} //deploy mode
linuxX64()
mingwX64()
macosX64()
sourceSets.invoke { sourceSets{
val nativeMain by getting val commonMain by getting
findByName("linuxX64Main")?.dependsOn(nativeMain) val nativeMain by creating{
val nativeTest by getting dependsOn(commonMain)
findByName("linuxX64Test")?.dependsOn(nativeTest) }
val commonTest by getting
val nativeTest by creating{
dependsOn(nativeMain)
dependsOn(commonTest)
}
val linuxX64Main by getting{
dependsOn(nativeMain)
}
val mingwX64Main by getting{
dependsOn(nativeMain)
}
val macosX64Main by getting{
dependsOn(nativeMain)
}
val linuxX64Test by getting{
dependsOn(nativeTest)
}
val mingwX64Test by getting{
dependsOn(nativeTest)
}
val macosX64Test by getting{
dependsOn(nativeTest)
}
}
} }
} }
} }

View File

@ -2,27 +2,45 @@ package ru.mipt.npm.gradle
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
/**
* Create a separate target for node
*/
class KScienceNodePlugin : Plugin<Project> { class KScienceNodePlugin : Plugin<Project> {
override fun apply(target: Project) = target.run{ override fun apply(target: Project) = target.run {
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { //Apply multiplatform plugin is not applied, apply it
configure<KotlinMultiplatformExtension> { if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) {
js { logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically")
nodejs() pluginManager.apply("org.jetbrains.kotlin.multiplatform")
}
if (plugins.findPlugin(KScienceCommonPlugin::class) == null) {
logger.info("KScience plugin is not resolved. Adding it automatically")
pluginManager.apply(KScienceCommonPlugin::class)
}
configure<KotlinMultiplatformExtension> {
js(name = "node", compiler = IR) {
nodejs()
}
sourceSets {
val commonMain by getting
val nodeMain by creating {
dependsOn(commonMain)
dependencies{
api("org.jetbrains.kotlinx:kotlinx-nodejs:${KScienceVersions.kotlinxNodeVersion}")
}
}
val commonTest by getting
val nodeTest by creating {
dependsOn(nodeMain)
dependsOn(commonTest)
} }
} }
} }
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
configure<KotlinJsProjectExtension> {
js {
nodejs()
}
}
}
} }
} }

View File

@ -0,0 +1,223 @@
package ru.mipt.npm.gradle
import groovy.text.SimpleTemplateEngine
import kotlinx.validation.BinaryCompatibilityValidatorPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
import org.jetbrains.changelog.ChangelogPlugin
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.DokkaTask
import java.io.File
import kotlin.collections.component1
import kotlin.collections.component2
class KSciencePublishingExtension(val project: Project) {
var githubOrg: String? by project.extra
var githubProject: String? by project.extra
var spaceRepo: String? by project.extra
var spaceUser: String? by project.extra
var spaceToken: String? by project.extra
var bintrayOrg: String? by project.extra
var bintrayUser: String? by project.extra
var bintrayApiKey: String? by project.extra
var bintrayRepo: String? by project.extra
}
enum class Maturity {
PROTOTYPE,
EXPERIMENTAL,
DEVELOPMENT,
PRODUCTION
}
class KScienceReadmeExtension(val project: Project) {
var description: String = ""
var maturity: Maturity = Maturity.EXPERIMENTAL
var readmeTemplate: File = project.file("docs/README-TEMPLATE.md")
data class Feature(val id: String, val ref: String, val description: String, val name: String = id)
val features = ArrayList<Feature>()
fun feature(id: String, ref: String, description: String, name: String = id) {
features.add(Feature(id, ref, description, name))
}
val properties: MutableMap<String, () -> Any?> = mutableMapOf(
"name" to { project.name },
"group" to { project.group },
"version" to { project.version },
"features" to { featuresString() }
)
private fun getActualizedProperties() = properties.mapValues { (_, value) ->
value.invoke()
}
fun property(key: String, value: Any?) {
properties[key] = {value}
}
fun propertyByTemplate(key: String, template: String) {
val actual = getActualizedProperties()
properties[key] = {SimpleTemplateEngine().createTemplate(template).make(actual).toString()}
}
internal val additionalFiles = ArrayList<File>()
fun propertyByTemplate(key: String, template: File) {
val actual = getActualizedProperties()
properties[key] = {SimpleTemplateEngine().createTemplate(template).make(actual).toString()}
additionalFiles.add(template)
}
/**
* Generate a markdown string listing features
*/
fun featuresString(itemPrefix: String = " - ", pathPrefix: String = "") = buildString {
features.forEach {
appendln("$itemPrefix[${it.id}]($pathPrefix${it.ref}) : ${it.description}")
}
}
/**
* Generate a readme string from the stub
*/
fun readmeString(): String? {
return if (readmeTemplate.exists()) {
val actual = getActualizedProperties()
SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString()
} else {
null
}
}
}
/**
* Apply extension and repositories
*/
open class KScienceProjectPlugin : Plugin<Project> {
override fun apply(target: Project): Unit = target.run {
apply<ChangelogPlugin>()
apply<DokkaPlugin>()
apply<BinaryCompatibilityValidatorPlugin>()
val rootReadmeExtension = KScienceReadmeExtension(this)
extensions.add("ksciencePublish", KSciencePublishingExtension(this))
extensions.add("readme", rootReadmeExtension)
//Add readme generators to individual subprojects
subprojects {
val readmeExtension = KScienceReadmeExtension(this)
extensions.add("readme", readmeExtension)
val generateReadme by tasks.creating {
group = "documentation"
description = "Generate a README file if stub is present"
if(readmeExtension.readmeTemplate.exists()) {
inputs.file(readmeExtension.readmeTemplate)
}
readmeExtension.additionalFiles.forEach {
if(it.exists()){
inputs.file(it)
}
}
val readmeFile = this@subprojects.file("README.md")
outputs.file(readmeFile)
doLast {
val readmeString = readmeExtension.readmeString()
if (readmeString != null) {
readmeFile.writeText(readmeString)
}
}
}
tasks.withType<DokkaTask>{
dependsOn(generateReadme)
}
}
val generateReadme by tasks.creating {
group = "documentation"
description = "Generate a README file and a feature matrix if stub is present"
subprojects {
tasks.findByName("generateReadme")?.let {
dependsOn(it)
}
}
if(rootReadmeExtension.readmeTemplate.exists()) {
inputs.file(rootReadmeExtension.readmeTemplate)
}
rootReadmeExtension.additionalFiles.forEach {
if(it.exists()){
inputs.file(it)
}
}
val readmeFile = project.file("README.md")
outputs.file(readmeFile)
doLast {
val projects = subprojects.associate {
it.name to it.extensions.findByType<KScienceReadmeExtension>()
}
if (rootReadmeExtension.readmeTemplate.exists()) {
val modulesString = buildString {
projects.entries.forEach { (name, ext) ->
appendln("<hr/>")
appendln("\n* ### [$name]($name)")
if (ext != null) {
appendln("> ${ext.description}")
appendln(">\n> **Maturity**: ${ext.maturity}")
val featureString = ext.featuresString(itemPrefix = "> - ", pathPrefix = "$name/")
if(featureString.isNotBlank()) {
appendln(">\n> **Features:**")
appendln(featureString)
}
}
}
appendln("<hr/>")
}
val rootReadmeProperties: Map<String, Any?> = mapOf(
"name" to project.name,
"group" to project.group,
"version" to project.version,
"modules" to modulesString
)
readmeFile.writeText(
SimpleTemplateEngine().createTemplate(rootReadmeExtension.readmeTemplate)
.make(rootReadmeProperties).toString()
)
}
}
}
tasks.withType<DokkaTask>{
dependsOn(generateReadme)
}
val patchChangelog by tasks.getting
val release by tasks.creating{
group = RELEASE_GROUP
description = "Publish development or production release based on version suffix"
dependsOn(generateReadme, patchChangelog)
tasks.findByName("publishAllPublicationsToBintrayRepository")?.let {
dependsOn(it)
}
}
}
companion object{
const val RELEASE_GROUP = "release"
}
}

View File

@ -2,129 +2,12 @@ package ru.mipt.npm.gradle
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension import ru.mipt.npm.gradle.internal.configurePublishing
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType
open class KSciencePublishPlugin : Plugin<Project> { open class KSciencePublishPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run{ override fun apply(project: Project): Unit = project.plugins.withId("ru.mipt.npm.kscience") {
plugins.apply("maven-publish") project.configurePublishing()
registerKScienceExtension()
afterEvaluate {
val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm"
val githubProject: String? by project
val vcs = findProperty("vcs") as? String
?: githubProject?.let { "https://github.com/$githubOrg/$it" }
if (vcs == null) {
project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.")
return@afterEvaluate
}
project.configure<PublishingExtension> {
// Process each publication we have in this project
publications.withType<MavenPublication>().forEach { publication ->
@Suppress("UnstableApiUsage")
publication.pom {
name.set(project.name)
description.set(project.description)
url.set(vcs)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT")
organizationUrl.set("http://npm.mipt.ru")
}
}
scm {
url.set(vcs)
tag.set(project.version.toString())
}
}
}
val githubUser: String? by project
val githubToken: String? by project
if (githubProject != null && githubUser != null && githubToken != null) {
project.logger.info("Adding github publishing to project [${project.name}]")
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/")
credentials {
username = githubUser
password = githubToken
}
}
}
}
val spaceRepo: String? by project
val spaceUser: String? by project
val spaceToken: String? by project
if (spaceRepo != null && spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories {
maven {
name = "space"
url = uri(spaceRepo!!)
credentials {
username = spaceUser
password = spaceToken
}
}
}
}
val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm"
val bintrayUser: String? by project
val bintrayApiKey: String? by project
val bintrayRepo = if (project.version.toString().contains("dev")) {
"dev"
} else {
findProperty("bintrayRepo") as? String
}
val projectName = project.name
if (bintrayRepo != null && bintrayUser != null && bintrayApiKey != null) {
project.logger.info("Adding bintray publishing to project [$projectName]")
repositories {
maven {
name = "bintray"
url = uri(
"https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=1;override=1"
)
credentials {
username = bintrayUser
password = bintrayApiKey
}
}
}
}
}
}
} }
} }

View File

@ -6,15 +6,19 @@ import org.gradle.api.JavaVersion
* Build constants * Build constants
*/ */
object KScienceVersions { object KScienceVersions {
const val coroutinesVersion = "1.3.9" const val kotlinVersion = "1.4.21"
const val serializationVersion = "1.0.0-RC" const val kotlinxNodeVersion = "0.0.7"
const val coroutinesVersion = "1.4.2"
const val serializationVersion = "1.0.1"
const val atomicVersion = "0.14.4" const val atomicVersion = "0.14.4"
val JVM_TARGET = JavaVersion.VERSION_11 val JVM_TARGET = JavaVersion.VERSION_11
object Serialization{ object Serialization{
const val xmlVersion = "0.80.0-RC"//to be fixed const val xmlVersion = "0.80.1"
@Deprecated("Use yamlKt instead")
const val yamlVersion = "0.21.0" const val yamlVersion = "0.21.0"
const val bsonVersion = "0.4.1-rc" const val bsonVersion = "0.4.4"
const val yamlKtVersion = "0.7.5"
} }
} }

View File

@ -3,11 +3,24 @@ package ru.mipt.npm.gradle
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.maven import org.gradle.kotlin.dsl.maven
import org.gradle.kotlin.dsl.repositories import org.gradle.kotlin.dsl.repositories
import ru.mipt.npm.gradle.internal.useCommonDependency
import ru.mipt.npm.gradle.internal.useDependency
class SerializationTargets( class SerializationTargets(
val sourceSet: DependencySourceSet, val sourceSet: DependencySourceSet,
val configuration: DependencyConfiguration val configuration: DependencyConfiguration
) { ) {
fun Project.json(
version: String = KScienceVersions.serializationVersion
) {
useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-serialization-json:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
fun Project.cbor( fun Project.cbor(
version: String = KScienceVersions.serializationVersion version: String = KScienceVersions.serializationVersion
) { ) {
@ -34,15 +47,14 @@ class SerializationTargets(
repositories { repositories {
maven("https://dl.bintray.com/pdvrieze/maven") maven("https://dl.bintray.com/pdvrieze/maven")
} }
useDependency( useCommonDependency(
"common" to "net.devrieze:xmlutil-serialization:$version", "net.devrieze:xmlutil-serialization:$version",
"jvm" to "net.devrieze:xmlutil-serialization:$version",
"js" to "net.devrieze:xmlutil-serialization:$version",
dependencySourceSet = sourceSet, dependencySourceSet = sourceSet,
dependencyConfiguration = configuration dependencyConfiguration = configuration
) )
} }
@Deprecated("Use multiplatform yamlKt instead")
fun Project.yaml( fun Project.yaml(
version: String = KScienceVersions.Serialization.yamlVersion version: String = KScienceVersions.Serialization.yamlVersion
) { ) {
@ -53,6 +65,16 @@ class SerializationTargets(
) )
} }
fun Project.yamlKt(
version: String = KScienceVersions.Serialization.yamlKtVersion
) {
useCommonDependency(
"net.mamoe.yamlkt:yamlkt:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
fun Project.bson( fun Project.bson(
version: String = KScienceVersions.Serialization.bsonVersion version: String = KScienceVersions.Serialization.bsonVersion
) { ) {

View File

@ -1,103 +0,0 @@
package ru.mipt.npm.gradle
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.maven
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
import java.io.File
internal fun LanguageSettingsBuilder.applySettings(): Unit {
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("kotlin.Experimental")
useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
useExperimentalAnnotation("kotlin.time.ExperimentalTime")
useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
}
internal fun RepositoryHandler.applyRepos(): Unit {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://dl.bintray.com/kotlin/kotlin-dev")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://kotlin.bintray.com/kotlin-js-wrappers/")
maven("https://dl.bintray.com/mipt-npm/kscience")
maven("https://dl.bintray.com/mipt-npm/dev")
maven("https://dl.bintray.com/mipt-npm/dataforge")
}
internal fun Copy.copyJSResources(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("jsProcessResources")?.let { task ->
val sourceDir = (task as Copy).destinationDir
inputs.files(sourceDir)
dependsOn(task)
from(sourceDir)
}
}
dep.pluginManager.withPlugin("org.jetbrains.kotlin.js") {
dep.tasks.findByName("processResources")?.let { task ->
val sourceDir = (task as Copy).destinationDir
inputs.files(sourceDir)
dependsOn(task)
from(sourceDir)
}
}
}
}
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
get() {
val distributionName = listOf(
name,
"js",
version.toString()
).joinToString("-")
return buildDir.resolve(
"distributions/$distributionName"
)
}

View File

@ -0,0 +1,78 @@
package ru.mipt.npm.gradle.internal
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.maven
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
internal fun LanguageSettingsBuilder.applySettings(): Unit {
progressiveMode = true
enableLanguageFeature("InlineClasses")
useExperimentalAnnotation("kotlin.Experimental")
useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")
useExperimentalAnnotation("kotlin.time.ExperimentalTime")
useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")
useExperimentalAnnotation("kotlin.js.ExperimentalJsExport")
}
internal fun RepositoryHandler.applyRepos(): Unit {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
maven("https://dl.bintray.com/kotlin/kotlin-dev")
maven("https://kotlin.bintray.com/kotlinx")
maven("https://kotlin.bintray.com/kotlin-js-wrappers/")
maven("https://dl.bintray.com/mipt-npm/kscience")
maven("https://dl.bintray.com/mipt-npm/dev")
maven("https://dl.bintray.com/mipt-npm/dataforge")
}
internal fun Copy.fromDependencies(configurationName: String) = project.afterEvaluate {
val configuration = configurations[configurationName]
?: error("Configuration with name $configurationName could not be resolved.")
val projectDeps = configuration.allDependencies.filterIsInstance<ProjectDependency>().map {
it.dependencyProject
}
projectDeps.forEach { dep ->
dep.afterEvaluate {
dep.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
dep.tasks.findByName("jsProcessResources")?.let { task ->
dependsOn(task)
from(task)
}
}
dep.pluginManager.withPlugin("org.jetbrains.kotlin.js") {
dep.tasks.findByName("processResources")?.let { task ->
dependsOn(task)
from(task)
}
}
}
}
}
//
//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)
// }
// }
// }
//}

View File

@ -1,21 +1,13 @@
package ru.mipt.npm.gradle package ru.mipt.npm.gradle.internal
import kotlinx.atomicfu.plugin.gradle.sourceSets
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.invoke import org.gradle.kotlin.dsl.invoke
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.KotlinMultiplatformExtension
import ru.mipt.npm.gradle.DependencyConfiguration
enum class DependencyConfiguration { import ru.mipt.npm.gradle.DependencySourceSet
API,
IMPLEMENTATION,
COMPILE_ONLY
}
enum class DependencySourceSet(val setName: String, val suffix: String) {
MAIN("main", "Main"),
TEST("test", "Test")
}
internal fun Project.useDependency( internal fun Project.useDependency(
vararg pairs: Pair<String, String>, vararg pairs: Pair<String, String>,
@ -23,7 +15,7 @@ internal fun Project.useDependency(
dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION
) { ) {
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
extensions.findByType<KotlinMultiplatformExtension>()?.apply { configure<KotlinMultiplatformExtension> {
sourceSets { sourceSets {
pairs.forEach { (target, dep) -> pairs.forEach { (target, dep) ->
val name = target + dependencySourceSet.suffix val name = target + dependencySourceSet.suffix
@ -43,14 +35,16 @@ internal fun Project.useDependency(
pairs.find { it.first == "jvm" }?.let { dep -> pairs.find { it.first == "jvm" }?.let { dep ->
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
sourceSets.findByName(dependencySourceSet.setName)?.apply { configure<KotlinJvmProjectExtension> {
dependencies.apply { sourceSets.findByName(dependencySourceSet.setName)?.apply {
val configurationName = when (dependencyConfiguration) { dependencies.apply {
DependencyConfiguration.API -> apiConfigurationName val configurationName = when (dependencyConfiguration) {
DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName DependencyConfiguration.API -> apiConfigurationName
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName
}
add(configurationName, dep.second)
} }
add(configurationName, dep.second)
} }
} }
} }
@ -58,14 +52,16 @@ internal fun Project.useDependency(
pairs.find { it.first == "js" }?.let { dep -> pairs.find { it.first == "js" }?.let { dep ->
pluginManager.withPlugin("org.jetbrains.kotlin.js") { pluginManager.withPlugin("org.jetbrains.kotlin.js") {
sourceSets.findByName(dependencySourceSet.setName)?.apply { configure<KotlinJsProjectExtension> {
dependencies.apply { sourceSets.findByName(dependencySourceSet.setName)?.apply {
val configurationName = when (dependencyConfiguration) { dependencies.apply {
DependencyConfiguration.API -> apiConfigurationName val configurationName = when (dependencyConfiguration) {
DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName DependencyConfiguration.API -> apiConfigurationName
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName
}
add(configurationName, dep.second)
} }
add(configurationName, dep.second)
} }
} }
} }
@ -76,9 +72,9 @@ internal fun Project.useCommonDependency(
dep: String, dep: String,
dependencySourceSet: DependencySourceSet = DependencySourceSet.MAIN, dependencySourceSet: DependencySourceSet = DependencySourceSet.MAIN,
dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION
): Unit = pluginManager.run{ ): Unit = pluginManager.run {
withPlugin("org.jetbrains.kotlin.multiplatform"){ withPlugin("org.jetbrains.kotlin.multiplatform") {
extensions.findByType<KotlinMultiplatformExtension>()?.apply { configure<KotlinMultiplatformExtension> {
sourceSets.findByName("common${dependencySourceSet.suffix}")?.apply { sourceSets.findByName("common${dependencySourceSet.suffix}")?.apply {
dependencies { dependencies {
when (dependencyConfiguration) { when (dependencyConfiguration) {
@ -90,27 +86,33 @@ internal fun Project.useCommonDependency(
} }
} }
} }
withPlugin("org.jetbrains.kotlin.jvm") { withPlugin("org.jetbrains.kotlin.jvm") {
sourceSets.findByName(dependencySourceSet.setName)?.apply { configure<KotlinJvmProjectExtension> {
dependencies.apply { sourceSets.findByName(dependencySourceSet.setName)?.apply {
val configurationName = when (dependencyConfiguration) { dependencies.apply {
DependencyConfiguration.API -> apiConfigurationName val configurationName = when (dependencyConfiguration) {
DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName DependencyConfiguration.API -> apiConfigurationName
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName
}
add(configurationName, dep)
} }
add(configurationName, dep)
} }
} }
} }
withPlugin("org.jetbrains.kotlin.js") { withPlugin("org.jetbrains.kotlin.js") {
sourceSets.findByName(dependencySourceSet.setName)?.apply { configure<KotlinJsProjectExtension> {
dependencies.apply { sourceSets.findByName(dependencySourceSet.setName)?.apply {
val configurationName = when (dependencyConfiguration) { dependencies.apply {
DependencyConfiguration.API -> apiConfigurationName val configurationName = when (dependencyConfiguration) {
DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName DependencyConfiguration.API -> apiConfigurationName
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName
DependencyConfiguration.COMPILE_ONLY -> compileOnlyConfigurationName
}
add(configurationName, dep)
} }
add(configurationName, dep)
} }
} }
} }

View File

@ -1,4 +1,4 @@
package ru.mipt.npm.gradle package ru.mipt.npm.gradle.internal
import org.apache.tools.ant.taskdefs.condition.Os import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.Project import org.gradle.api.Project
@ -6,22 +6,9 @@ import org.gradle.kotlin.dsl.findByType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import ru.mipt.npm.gradle.DependencyConfiguration
enum class FXModule(val artifact: String, vararg val dependencies: FXModule) { import ru.mipt.npm.gradle.FXModule
BASE("javafx-base"), import ru.mipt.npm.gradle.FXPlatform
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)
}
enum class FXPlatform(val id: String) {
WINDOWS("win"),
LINUX("linux"),
MAC("mac")
}
val defaultPlatform: FXPlatform = when { val defaultPlatform: FXPlatform = when {
Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS
@ -31,7 +18,7 @@ val defaultPlatform: FXPlatform = when {
} }
private fun KotlinDependencyHandler.addFXDependencies( private fun KotlinDependencyHandler.addFXDependencies(
vararg modules: FXModule, modules: List<FXModule>,
configuration: DependencyConfiguration, configuration: DependencyConfiguration,
version: String = "14", version: String = "14",
platform: FXPlatform = defaultPlatform platform: FXPlatform = defaultPlatform
@ -46,17 +33,17 @@ private fun KotlinDependencyHandler.addFXDependencies(
} }
} }
fun Project.useFx( internal fun Project.useFx(
vararg modules: FXModule, modules: List<FXModule>,
configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY, configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY,
version: String = "14", version: String = "14",
platform: FXPlatform = defaultPlatform platform: FXPlatform = defaultPlatform
): Unit = afterEvaluate{ ): Unit = afterEvaluate {
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
extensions.findByType<KotlinMultiplatformExtension>()?.apply { extensions.findByType<KotlinMultiplatformExtension>()?.apply {
sourceSets.findByName("jvmMain")?.apply { sourceSets.findByName("jvmMain")?.apply {
dependencies { dependencies {
addFXDependencies(*modules, configuration = configuration, version = version, platform = platform) addFXDependencies(modules, configuration = configuration, version = version, platform = platform)
} }
} }
} }
@ -66,7 +53,7 @@ fun Project.useFx(
extensions.findByType<KotlinJvmProjectExtension>()?.apply { extensions.findByType<KotlinJvmProjectExtension>()?.apply {
sourceSets.findByName("main")?.apply { sourceSets.findByName("main")?.apply {
dependencies { dependencies {
addFXDependencies(*modules, configuration = configuration, version = version, platform = platform) addFXDependencies(modules, configuration = configuration, version = version, platform = platform)
} }
} }
} }

View File

@ -0,0 +1,157 @@
package ru.mipt.npm.gradle.internal
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
internal fun Project.configurePublishing() {
if (plugins.findPlugin("maven-publish") == null) {
plugins.apply("maven-publish")
}
val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm"
val githubProject: String? by project
val vcs = findProperty("vcs") as? String
?: githubProject?.let { "https://github.com/$githubOrg/$it" }
if (vcs == null) {
project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.")
return
}
project.configure<PublishingExtension> {
plugins.withId("org.jetbrains.kotlin.js") {
val kotlin = extensions.findByType<KotlinJsProjectExtension>()!!
val sourcesJar: Jar by project.tasks.creating(Jar::class){
archiveClassifier.set("sources")
from(kotlin.sourceSets["main"].kotlin)
}
publications {
create("js", MavenPublication::class) {
from(components["kotlin"])
artifact(sourcesJar)
}
}
}
plugins.withId("org.jetbrains.kotlin.jvm") {
val kotlin = extensions.findByType<KotlinJvmProjectExtension>()!!
val sourcesJar: Jar by project.tasks.creating(Jar::class){
archiveClassifier.set("sources")
from(kotlin.sourceSets["main"].kotlin)
}
publications {
create("jvm", MavenPublication::class) {
from(components["kotlin"])
artifact(sourcesJar)
}
}
}
// Process each publication we have in this project
publications.withType<MavenPublication>().forEach { publication ->
publication.pom {
name.set(project.name)
description.set(project.description)
url.set(vcs)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT")
organizationUrl.set("http://npm.mipt.ru")
}
}
scm {
url.set(vcs)
tag.set(project.version.toString())
}
}
}
val githubUser: String? by project
val githubToken: String? by project
if (githubProject != null && githubUser != null && githubToken != null) {
project.logger.info("Adding github publishing to project [${project.name}]")
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/")
credentials {
username = githubUser
password = githubToken
}
}
}
}
val spaceRepo: String? by project
val spaceUser: String? by project
val spaceToken: String? by project
if (spaceRepo != null && spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories {
maven {
name = "space"
url = uri(spaceRepo!!)
credentials {
username = spaceUser
password = spaceToken
}
}
}
}
val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm"
val bintrayUser: String? by project
val bintrayApiKey: String? by project
val bintrayRepo = if (project.version.toString().contains("dev")) {
"dev"
} else {
findProperty("bintrayRepo") as? String
}
val projectName = project.name
if (bintrayRepo != null && bintrayUser != null && bintrayApiKey != null) {
project.logger.info("Adding bintray publishing to project [$projectName]")
repositories {
maven {
name = "bintray"
url = uri(
"https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=1;override=1"
)
credentials {
username = bintrayUser
password = bintrayApiKey
}
}
}
}
}
}