Compare commits

..

9 Commits

11 changed files with 175 additions and 323 deletions

View File

@ -10,11 +10,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add development mode for fullstack. - Add development mode for fullstack.
### Changed ### Changed
- Kotlin 1.9.20
- Remove publishing defaults for Space and GitHub. Now publishing repositories is configured quasi-manually. Property keys for username and tokens are generated automatically.
- All publishing targets are enabled by default. Introduce `publishing.targets` variable to regulate what is added to the module. - All publishing targets are enabled by default. Introduce `publishing.targets` variable to regulate what is added to the module.
### Deprecated ### Deprecated
- JVM plugin in favor of Mpp.
### Removed ### Removed
- JS plugin. It is deprecated in favor of MPP.
- Unnecessary `dependsOn` for native dependencies.
- Groovy gradle dependency notation. - Groovy gradle dependency notation.
### Fixed ### Fixed

View File

@ -25,6 +25,7 @@ kotlin.explicitApiWarning()
dependencies { dependencies {
api(libs.kotlin.gradle) api(libs.kotlin.gradle)
api("org.gradle.toolchains:foojay-resolver:0.7.0")
implementation(libs.binary.compatibility.validator) implementation(libs.binary.compatibility.validator)
implementation(libs.changelog.gradle) implementation(libs.changelog.gradle)
implementation(libs.dokka.gradle) implementation(libs.dokka.gradle)
@ -65,23 +66,17 @@ gradlePlugin {
description = "Pre-configured JVM project" description = "Pre-configured JVM project"
implementationClass = "space.kscience.gradle.KScienceJVMPlugin" implementationClass = "space.kscience.gradle.KScienceJVMPlugin"
} }
create("js") {
id = "space.kscience.gradle.js"
description = "Pre-configured JS project"
implementationClass = "space.kscience.gradle.KScienceJSPlugin"
}
} }
} }
tasks.create("version") { tasks.create("version") {
group = "publishing" group = "publishing"
val versionFile = project.buildDir.resolve("project-version.txt") val versionFileProvider = project.layout.buildDirectory.file("project-version.txt")
outputs.file(versionFile) outputs.file(versionFileProvider)
doLast { doLast {
val versionFile = versionFileProvider.get().asFile
versionFile.createNewFile() versionFile.createNewFile()
versionFile.writeText(project.version.toString()) versionFile.writeText(project.version.toString())
println(project.version)
} }
} }
@ -117,7 +112,7 @@ val emptySourcesJar by tasks.creating(Jar::class) {
} }
publishing { publishing {
val vcs = "https://github.com/mipt-npm/gradle-tools" val vcs = "https://github.com/SciProgCentre/gradle-tools"
// Process each publication we have in this project // Process each publication we have in this project
publications { publications {
@ -151,10 +146,10 @@ publishing {
developers { developers {
developer { developer {
id.set("MIPT-NPM") id.set("SPC")
name.set("MIPT nuclear physics methods laboratory") name.set("Scientific Programming Centre")
organization.set("MIPT") organization.set("SPC")
organizationUrl.set("https://npm.mipt.ru") organizationUrl.set("https://sciprog.center/")
} }
} }
@ -166,20 +161,18 @@ publishing {
} }
} }
val spaceRepo = "https://maven.pkg.jetbrains.space/spc/p/sci/maven" val spaceRepo = "https://maven.sciprog.center/kscience"
val spaceUser: String? = findProperty("publishing.space.user") as? String val spcUser: String? = findProperty("publishing.spc.user") as? String
val spaceToken: String? = findProperty("publishing.space.token") as? String val spcToken: String? = findProperty("publishing.spc.token") as? String
if (spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
if (spcUser != null && spcToken != null) {
repositories.maven { repositories.maven {
name = "space" name = "spc"
url = uri(spaceRepo) url = uri(spaceRepo)
credentials { credentials {
username = spaceUser username = spcUser
password = spaceToken password = spcToken
} }
} }
} }

View File

@ -1,26 +1,47 @@
[versions] [versions]
tools = "0.14.10-kotlin-1.9.0" tools = "0.15.0-kotlin-1.9.20"
kotlin = "1.9.0" kotlin = "1.9.20"
# https://github.com/Kotlin/kotlinx-atomicfu
atomicfu = "0.22.0" atomicfu = "0.22.0"
# https://github.com/Kotlin/binary-compatibility-validator
binary-compatibility-validator = "0.13.2" binary-compatibility-validator = "0.13.2"
changelog = "2.1.2" # https://github.com/JetBrains/gradle-changelog-plugin
dokka = "1.8.20" changelog = "2.2.0"
kotlin-jupyter = "0.12.0-43" # https://github.com/Kotlin/dokka
dokka = "1.9.10"
# https://github.com/Kotlin/kotlin-jupyter
kotlin-jupyter = "0.12.0-81"
# https://github.com/Kotlin/kotlinx-benchmark
kotlinx-benchmark = "0.4.9" kotlinx-benchmark = "0.4.9"
kotlinx-cli = "0.3.5" # https://github.com/Kotlin/kotlinx-cli
kotlinx-cli = "0.3.6"
# https://github.com/Kotlin/kotlinx.coroutines
kotlinx-coroutines = "1.7.3" kotlinx-coroutines = "1.7.3"
kotlinx-datetime = "0.4.0" # https://github.com/Kotlin/kotlinx-datetime
kotlinx-datetime = "0.4.1"
# https://github.com/Kotlin/kotlinx.html
kotlinx-html = "0.9.1" kotlinx-html = "0.9.1"
# https://github.com/Kotlin/kotlinx-knit
kotlinx-knit = "0.4.0" kotlinx-knit = "0.4.0"
# https://github.com/Kotlin/kotlinx-nodejs
kotlinx-nodejs = "0.0.7" kotlinx-nodejs = "0.0.7"
kotlinx-serialization = "1.5.1" # https://github.com/Kotlin/kotlinx.serialization
ktor = "2.3.3" kotlinx-serialization = "1.6.0"
# https://ktor.io/
ktor = "2.3.5"
# https://github.com/pdvrieze/xmlutil
xmlutil = "0.86.1" xmlutil = "0.86.1"
# https://github.com/Him188/yamlkt
yamlkt = "0.13.0" yamlkt = "0.13.0"
jsBom = "1.0.0-pre.618" # https://github.com/JetBrains/kotlin-wrappers
jsBom = "1.0.0-pre.624"
junit = "5.9.3" junit = "5.9.3"
compose = "1.5.0-rc01" # https://github.com/JetBrains/compose-multiplatform
logback = "1.4.7" compose = "1.5.3"
# https://mvnrepository.com/artifact/org.slf4j/slf4j-api
slf4j = "2.0.9"
# https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
logback = "1.4.11"
[libraries] [libraries]
atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" } atomicfu-gradle = { module = "org.jetbrains.kotlinx:atomicfu-gradle-plugin", version.ref = "atomicfu" }
@ -81,6 +102,8 @@ xmlutil-serialization = { module = "io.github.pdvrieze.xmlutil:serialization", v
yamlkt = { module = "net.mamoe.yamlkt:yamlkt", version.ref = "yamlkt" } yamlkt = { module = "net.mamoe.yamlkt:yamlkt", version.ref = "yamlkt" }
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
[plugins] [plugins]

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-8.1.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -1,6 +1,5 @@
package space.kscience.gradle package space.kscience.gradle
import org.gradle.api.Action
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.plugins.ApplicationPlugin import org.gradle.api.plugins.ApplicationPlugin
@ -20,7 +19,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmTargetDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmJsTargetDsl
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlinx.jupyter.api.plugin.tasks.JupyterApiResourcesTask import org.jetbrains.kotlinx.jupyter.api.plugin.tasks.JupyterApiResourcesTask
@ -108,7 +107,7 @@ public open class KScienceExtension(public val project: Project) {
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {
sourceSets.findByName("commonMain")?.apply { sourceSets.findByName("commonMain")?.apply {
dependencies { dependencies {
api(platform("io.ktor:ktor-bom:$version")) api(project.dependencies.platform("io.ktor:ktor-bom:$version"))
} }
} }
} }
@ -117,7 +116,7 @@ public open class KScienceExtension(public val project: Project) {
configure<KotlinJvmProjectExtension> { configure<KotlinJvmProjectExtension> {
sourceSets.findByName("main")?.apply { sourceSets.findByName("main")?.apply {
dependencies { dependencies {
api(platform("io.ktor:ktor-bom:$version")) api(project.dependencies.platform("io.ktor:ktor-bom:$version"))
} }
} }
} }
@ -126,7 +125,7 @@ public open class KScienceExtension(public val project: Project) {
configure<KotlinJsProjectExtension> { configure<KotlinJsProjectExtension> {
sourceSets.findByName("main")?.apply { sourceSets.findByName("main")?.apply {
dependencies { dependencies {
api(platform("io.ktor:ktor-bom:$version")) api(project.dependencies.platform("io.ktor:ktor-bom:$version"))
} }
} }
} }
@ -182,13 +181,6 @@ public open class KScienceExtension(public val project: Project) {
} }
} }
project.pluginManager.withPlugin("org.jetbrains.kotlin.js") {
project.configure<KotlinJsProjectExtension> {
sourceSets.getByName(sourceSet ?: "test") {
dependencies(dependencyBlock)
}
}
}
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
project.configure<KotlinMultiplatformExtension> { project.configure<KotlinMultiplatformExtension> {
@ -235,7 +227,7 @@ public open class KScienceExtension(public val project: Project) {
binaries.executable() binaries.executable()
} }
targets.withType<KotlinWasmTargetDsl> { targets.withType<KotlinWasmJsTargetDsl> {
binaries.executable() binaries.executable()
} }
} }
@ -265,8 +257,8 @@ public open class KScienceExtension(public val project: Project) {
public val jsTest: DefaultSourceSet get() = DefaultSourceSet("jsTest") public val jsTest: DefaultSourceSet get() = DefaultSourceSet("jsTest")
public val nativeMain: DefaultSourceSet get() = DefaultSourceSet("nativeMain") public val nativeMain: DefaultSourceSet get() = DefaultSourceSet("nativeMain")
public val nativeTest: DefaultSourceSet get() = DefaultSourceSet("nativeTest") public val nativeTest: DefaultSourceSet get() = DefaultSourceSet("nativeTest")
public val wasmMain: DefaultSourceSet get() = DefaultSourceSet("wasmMain") public val wasmJsMain: DefaultSourceSet get() = DefaultSourceSet("wasmJsMain")
public val wasmTest: DefaultSourceSet get() = DefaultSourceSet("wasmTest") public val wasmJsTest: DefaultSourceSet get() = DefaultSourceSet("wasmJsTest")
} }
@ -376,8 +368,8 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
project.configure<KotlinMultiplatformExtension> { project.configure<KotlinMultiplatformExtension> {
jvm { jvm {
compilations.all { compilations.all {
kotlinOptions { compilerOptions.configure {
freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs freeCompilerArgs.addAll(defaultKotlinJvmArgs)
} }
} }
block() block()
@ -424,31 +416,32 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
} }
} }
/**
* Add Wasm/Js target
*/
@OptIn(ExperimentalWasmDsl::class) @OptIn(ExperimentalWasmDsl::class)
public fun wasm(block: KotlinWasmTargetDsl.() -> Unit = {}) { public fun wasm(block: KotlinWasmJsTargetDsl.() -> Unit = {}) {
if (project.requestPropertyOrNull("kscience.wasm.disabled") == "true") { // if (project.requestPropertyOrNull("kscience.wasm.disabled") == "true") {
project.logger.warn("Wasm target is disabled with 'kscience.wasm.disabled' property") // project.logger.warn("Wasm target is disabled with 'kscience.wasm.disabled' property")
return // return
} // }
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
project.configure<KotlinMultiplatformExtension> { project.configure<KotlinMultiplatformExtension> {
wasm { wasmJs {
browser { browser {
testTask(Action { testTask {
useKarma { useKarma {
this.webpackConfig.experiments.add("topLevelAwait") useChromeCanaryHeadless()
useChromeHeadlessWasmGc()
useConfigDirectory(project.projectDir.resolve("karma.config.d").resolve("wasm"))
} }
}) }
} }
block() block()
} }
sourceSets { sourceSets {
getByName("wasmTest") { getByName("wasmJsTest") {
dependencies { dependencies {
implementation(kotlin("test")) implementation(kotlin("test-wasm-js"))
} }
} }
} }
@ -472,14 +465,14 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
browserConfig: KotlinJsBrowserDsl.() -> Unit = {}, browserConfig: KotlinJsBrowserDsl.() -> Unit = {},
) { ) {
js { js {
binaries.executable()
browser { browser {
webpackTask(Action { webpackTask {
mainOutputFileName.set(bundleName) mainOutputFileName.set(bundleName)
}) }
browserConfig() browserConfig()
} }
jsConfig() jsConfig()
binaries.executable()
} }
jvm { jvm {
val processResourcesTaskName = val processResourcesTaskName =
@ -506,79 +499,45 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
val nativeConfiguration = KScienceNativeConfiguration(this).apply(block) val nativeConfiguration = KScienceNativeConfiguration(this).apply(block)
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {
val nativeTargets: List<KotlinNativeTarget> = nativeConfiguration.targets.values.forEach { nativeTarget ->
nativeConfiguration.targets.values.map { nativeTarget -> when (nativeTarget.preset) {
when (nativeTarget.preset) { KotlinNativePreset.linuxX64 -> linuxX64(
KotlinNativePreset.linuxX64 -> linuxX64( nativeTarget.targetName,
nativeTarget.targetName, nativeTarget.targetConfiguration
nativeTarget.targetConfiguration )
)
KotlinNativePreset.mingwX64 -> mingwX64( KotlinNativePreset.mingwX64 -> mingwX64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.macosX64 -> macosX64( KotlinNativePreset.macosX64 -> macosX64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.macosArm64 -> macosArm64( KotlinNativePreset.macosArm64 -> macosArm64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.iosX64 -> iosX64( KotlinNativePreset.iosX64 -> iosX64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.iosArm64 -> iosArm64( KotlinNativePreset.iosArm64 -> iosArm64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
KotlinNativePreset.iosSimulatorArm64 -> iosSimulatorArm64( KotlinNativePreset.iosSimulatorArm64 -> iosSimulatorArm64(
nativeTarget.targetName, nativeTarget.targetName,
nativeTarget.targetConfiguration nativeTarget.targetConfiguration
) )
// else -> {
// logger.error("Native preset ${nativeTarget.preset} not recognised.")
// null
// }
}
}
sourceSets {
val commonMain by getting
val commonTest by getting
val nativeMain by creating {
dependsOn(commonMain)
}
val nativeTest by creating {
//should NOT depend on nativeMain because automatic dependency by plugin
dependsOn(commonTest)
}
configure(nativeTargets) {
compilations["main"]?.apply {
configure(kotlinSourceSets) {
dependsOn(nativeMain)
}
}
compilations["test"]?.apply {
configure(kotlinSourceSets) {
dependsOn(nativeTest)
}
}
} }
} }
} }
} }
} }

View File

@ -1,56 +0,0 @@
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 {
if (!plugins.hasPlugin("org.jetbrains.kotlin.js")) {
plugins.apply("org.jetbrains.kotlin.js")
} else {
logger.info("Kotlin JS plugin is already present")
}
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>()
}
}
}

View File

@ -10,12 +10,13 @@ import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.withType import org.gradle.kotlin.dsl.withType
import org.jetbrains.dokka.gradle.DokkaPlugin import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension 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.applySettings
import space.kscience.gradle.internal.defaultKotlinJvmArgs import space.kscience.gradle.internal.defaultKotlinJvmArgs
public open class KScienceJVMPlugin : Plugin<Project> { public open class KScienceJVMPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
logger.warn("KSCience JVM plugin is deprecated. Use MPP.")
if (!plugins.hasPlugin("org.jetbrains.kotlin.jvm")) { if (!plugins.hasPlugin("org.jetbrains.kotlin.jvm")) {
plugins.apply("org.jetbrains.kotlin.jvm") plugins.apply("org.jetbrains.kotlin.jvm")
} else { } else {
@ -27,6 +28,9 @@ public open class KScienceJVMPlugin : Plugin<Project> {
configure<KotlinJvmProjectExtension> { configure<KotlinJvmProjectExtension> {
sourceSets.all { sourceSets.all {
languageSettings.applySettings() languageSettings.applySettings()
compilerOptions{
freeCompilerArgs.addAll(defaultKotlinJvmArgs)
}
} }
sourceSets["test"].apply { sourceSets["test"].apply {
@ -42,12 +46,6 @@ public open class KScienceJVMPlugin : Plugin<Project> {
} }
} }
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + defaultKotlinJvmArgs
}
}
tasks.withType<Test> { tasks.withType<Test> {
useJUnitPlatform() useJUnitPlatform()
} }

View File

@ -10,6 +10,7 @@ import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
import space.kscience.gradle.internal.applySettings import space.kscience.gradle.internal.applySettings
import space.kscience.gradle.internal.defaultKotlinCommonArgs
public open class KScienceMPPlugin : Plugin<Project> { public open class KScienceMPPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
@ -23,23 +24,29 @@ public open class KScienceMPPlugin : Plugin<Project> {
registerKScienceExtension(::KScienceMppExtension) registerKScienceExtension(::KScienceMppExtension)
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {
sourceSets { sourceSets {
getByName("commonMain"){ getByName("commonMain") {
dependencies { dependencies {
api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}")) api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}"))
} }
} }
getByName("commonTest"){ getByName("commonTest") {
dependencies { dependencies {
implementation(kotlin("test-common")) implementation(kotlin("test"))
implementation(kotlin("test-annotations-common")) implementation(kotlin("test-annotations-common"))
} }
} }
all {
languageSettings.applySettings()
}
} }
sourceSets.all { targets.all {
languageSettings.applySettings() compilations.all {
kotlinOptions{
freeCompilerArgs += defaultKotlinCommonArgs
}
}
} }
if (explicitApi == null) explicitApiWarning() if (explicitApi == null) explicitApiWarning()

View File

@ -15,7 +15,9 @@ import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
import space.kscience.gradle.internal.* import space.kscience.gradle.internal.addPublishing
import space.kscience.gradle.internal.addSonatypePublishing
import space.kscience.gradle.internal.setupPublication
/** /**
* Simplifies adding repositories for Maven publishing, responds for releasing tasks for projects. * Simplifies adding repositories for Maven publishing, responds for releasing tasks for projects.
@ -54,42 +56,20 @@ public class KSciencePublishingExtension(public val project: Project) {
} }
/** /**
* Adds GitHub as VCS and adds GitHub Packages Maven repository to publishing. * Add a repository with [repositoryName]. Uses "publishing.$repositoryName.user" and "publishing.$repositoryName.token"
* * properties pattern to store user and token
* @param githubProject the GitHub project.
* @param githubOrg the GitHub user or organization.
* @param deploy publish packages in the `deploy` task to the GitHub repository.
*/ */
public fun github( public fun repository(
githubOrg: String, repositoryName: String,
githubProject: String, url: String,
deploy: Boolean = project.requestPropertyOrNull("publishing.github") == "true",
) { ) {
if (deploy) { require(isVcsInitialized) { "The project vcs is not set up use 'pom' method to do so" }
try { project.addPublishing(repositoryName, url)
project.addGithubPublishing(githubOrg, githubProject)
} catch (t: Throwable) {
project.logger.error("Failed to set up github publication", t)
}
}
}
/**
* Adds Space Packages Maven repository to publishing.
*
* @param spaceRepo the repository URL.
* @param deploy publish packages in the `deploy` task to the Space repository.
*/
public fun space(
spaceRepo: String,
) {
project.addSpacePublishing(spaceRepo)
} }
/** /**
* Adds Sonatype Maven repository to publishing. * Adds Sonatype Maven repository to publishing.
*
* @param addToRelease publish packages in the `release` task to the Sonatype repository.
*/ */
public fun sonatype(sonatypeRoot: String = "https://s01.oss.sonatype.org") { public fun sonatype(sonatypeRoot: String = "https://s01.oss.sonatype.org") {
require(isVcsInitialized) { "The project vcs is not set up use 'pom' method to do so" } require(isVcsInitialized) { "The project vcs is not set up use 'pom' method to do so" }
@ -142,7 +122,7 @@ public open class KScienceProjectPlugin : Plugin<Project> {
val readmeExtension = KScienceReadmeExtension(this) val readmeExtension = KScienceReadmeExtension(this)
extensions.add("readme", readmeExtension) extensions.add("readme", readmeExtension)
val generateReadme by tasks.creating { tasks.create("generateReadme") {
group = "documentation" group = "documentation"
description = "Generate a README file if stub is present" description = "Generate a README file if stub is present"
@ -236,12 +216,12 @@ public open class KScienceProjectPlugin : Plugin<Project> {
tasks.create("version") { tasks.create("version") {
group = "publishing" group = "publishing"
val versionFile = project.buildDir.resolve("project-version.txt") val versionFileProvider = project.layout.buildDirectory.file("project-version.txt")
outputs.file(versionFile) outputs.file(versionFileProvider)
doLast { doLast {
val versionFile = versionFileProvider.get().asFile
versionFile.createNewFile() versionFile.createNewFile()
versionFile.writeText(project.version.toString()) versionFile.writeText(project.version.toString())
println(project.version)
} }
} }

View File

@ -7,8 +7,15 @@ import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
import space.kscience.gradle.KScienceVersions import space.kscience.gradle.KScienceVersions
internal val defaultKotlinJvmArgs: List<String> = internal val defaultKotlinJvmArgs: List<String> = listOf(
listOf("-Xjvm-default=all", "-Xlambdas=indy"/* "-Xjdk-release=${KScienceVersions.JVM_TARGET}"*/) "-Xjvm-default=all",
"-Xlambdas=indy",
/* "-Xjdk-release=${KScienceVersions.JVM_TARGET}"*/
)
internal val defaultKotlinCommonArgs: List<String> = listOf(
"-Xexpect-actual-classes"
)
internal fun resolveKotlinVersion(): KotlinVersion { internal fun resolveKotlinVersion(): KotlinVersion {
val (major, minor, patch) = KScienceVersions.kotlinVersion.split(".", "-") val (major, minor, patch) = KScienceVersions.kotlinVersion.split(".", "-")
@ -23,6 +30,7 @@ internal fun LanguageSettingsBuilder.applySettings(
apiVersion = versionString apiVersion = versionString
progressiveMode = true progressiveMode = true
optIn("kotlin.RequiresOptIn") optIn("kotlin.RequiresOptIn")
optIn("kotlin.ExperimentalUnsignedTypes") optIn("kotlin.ExperimentalUnsignedTypes")
optIn("kotlin.ExperimentalStdlibApi") optIn("kotlin.ExperimentalStdlibApi")

View File

@ -8,9 +8,7 @@ import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.SigningExtension import org.gradle.plugins.signing.SigningExtension
import org.gradle.plugins.signing.SigningPlugin import org.gradle.plugins.signing.SigningPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.targets
import space.kscience.gradle.isInDevelopment import space.kscience.gradle.isInDevelopment
internal fun Project.requestPropertyOrNull(propertyName: String): String? = findProperty(propertyName) as? String internal fun Project.requestPropertyOrNull(propertyName: String): String? = findProperty(propertyName) as? String
@ -24,17 +22,6 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
plugins.withId("maven-publish") { plugins.withId("maven-publish") {
configure<PublishingExtension> { configure<PublishingExtension> {
plugins.withId("org.jetbrains.kotlin.js") {
val kotlin: KotlinJsProjectExtension = extensions.findByType()!!
publications.create<MavenPublication>("js") {
kotlin.targets.flatMap { it.components }.forEach {
from(it)
}
}
}
plugins.withId("org.jetbrains.kotlin.jvm") { plugins.withId("org.jetbrains.kotlin.jvm") {
val kotlin = extensions.findByType<KotlinJvmProjectExtension>()!! val kotlin = extensions.findByType<KotlinJvmProjectExtension>()!!
@ -46,9 +33,7 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
} }
publications.create<MavenPublication>("jvm") { publications.create<MavenPublication>("jvm") {
kotlin.target.components.forEach { from(project.components["java"])
from(it)
}
artifact(sourcesJar) artifact(sourcesJar)
} }
@ -91,7 +76,7 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
val signingKey: String = requestProperty("publishing.signing.key") val signingKey: String = requestProperty("publishing.signing.key")
val signingPassphrase: String = requestProperty("publishing.signing.passPhrase") val signingPassphrase: String = requestProperty("publishing.signing.passPhrase")
// if key is provided, use it // if a key is provided, use it
useInMemoryPgpKeys(signingId, signingKey, signingPassphrase) useInMemoryPgpKeys(signingId, signingKey, signingPassphrase)
} // else use agent signing } // else use agent signing
sign(publications) sign(publications)
@ -103,30 +88,31 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
} }
} }
internal fun Project.addGithubPublishing( internal fun Project.addPublishing(
githubOrg: String, repositoryName: String,
githubProject: String, urlString:String
) { ){
val githubUser: String? = requestPropertyOrNull("publishing.github.user") require(repositoryName.matches("\\w*".toRegex())){"Repository name must contain only letters or numbers"}
val githubToken: String? = requestPropertyOrNull("publishing.github.token") val user: String? = requestPropertyOrNull("publishing.$repositoryName.user")
val token: String? = requestPropertyOrNull("publishing.$repositoryName.token")
if (githubUser == null || githubToken == null) { if (user == null || token == null) {
logger.info("Skipping Github publishing because Github credentials are not defined") logger.info("Skipping $repositoryName publishing because $repositoryName credentials are not defined")
return return
} }
allprojects { allprojects {
plugins.withId("maven-publish") { plugins.withId("maven-publish") {
configure<PublishingExtension> { configure<PublishingExtension> {
logger.info("Adding Github publishing to project [${project.name}]") logger.info("Adding $repositoryName publishing to project [${project.name}]")
repositories.maven { repositories.maven {
name = "github" name = repositoryName
url = uri("https://maven.pkg.github.com/$githubOrg/$githubProject/") url = uri(urlString)
credentials { credentials {
username = githubUser username = user
password = githubToken password = token
} }
} }
} }
@ -134,62 +120,11 @@ internal fun Project.addGithubPublishing(
} }
} }
internal fun Project.addSpacePublishing(spaceRepo: String) {
val spaceUser: String? = requestPropertyOrNull("publishing.space.user")
val spaceToken: String? = requestPropertyOrNull("publishing.space.token")
if (spaceUser == null || spaceToken == null) {
logger.info("Skipping Space publishing because Space credentials are not defined")
return
}
allprojects {
plugins.withId("maven-publish") {
configure<PublishingExtension> {
project.logger.info("Adding SPC Space publishing to project [${project.name}]")
repositories.maven {
name = "space"
url = uri(spaceRepo)
credentials {
username = spaceUser
password = spaceToken
}
}
}
}
}
}
internal fun Project.addSonatypePublishing(sonatypeRoot: String) { internal fun Project.addSonatypePublishing(sonatypeRoot: String) {
if (isInDevelopment) { if (isInDevelopment) {
logger.info("Sonatype publishing skipped for development version") logger.info("Sonatype publishing skipped for development version")
return } else {
} addPublishing("sonatype", "$sonatypeRoot/service/local/staging/deploy/maven2")
val sonatypeUser: String? = requestPropertyOrNull("publishing.sonatype.user")
val sonatypePassword: String? = requestPropertyOrNull("publishing.sonatype.password")
if (sonatypeUser == null || sonatypePassword == null) {
logger.info("Skipping Sonatype publishing because Sonatype credentials are not defined")
return
}
allprojects {
plugins.withId("maven-publish") {
configure<PublishingExtension> {
repositories.maven {
val sonatypeRepo = "$sonatypeRoot/service/local/staging/deploy/maven2"
name = "sonatype"
url = uri(sonatypeRepo)
credentials {
username = sonatypeUser
password = sonatypePassword
}
}
}
}
} }
} }