Merge branch 'dev' into commandertvis/version-catalog

This commit is contained in:
Alexander Nozik 2021-09-12 11:12:27 +03:00 committed by GitHub
commit e586d20c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 305 additions and 300 deletions

View File

@ -10,6 +10,7 @@ plugins {
group = "ru.mipt.npm" group = "ru.mipt.npm"
version = libs.versions.tools.get() version = libs.versions.tools.get()
description = "Build tools for DataForge and kscience projects" description = "Build tools for DataForge and kscience projects"
changelog.version.set(project.version.toString()) changelog.version.set(project.version.toString())
@ -20,8 +21,12 @@ repositories {
maven("https://repo.kotlin.link") maven("https://repo.kotlin.link")
} }
val kotlinVersion = "1.5.30"
java.targetCompatibility = JavaVersion.VERSION_11 java.targetCompatibility = JavaVersion.VERSION_11
kotlin.explicitApiWarning()
dependencies { dependencies {
api(libs.kotlin.gradle) api(libs.kotlin.gradle)
implementation(libs.atomicfu.gradle) implementation(libs.atomicfu.gradle)
@ -170,7 +175,7 @@ afterEvaluate {
} }
if (plugins.findPlugin("signing") == null) { if (plugins.findPlugin("signing") == null) {
plugins.apply("signing") apply<SigningPlugin>()
} }
repositories.maven { repositories.maven {

View File

@ -6,6 +6,7 @@ import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.Copy import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.testing.Test import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
@ -15,7 +16,7 @@ import ru.mipt.npm.gradle.internal.applySettings
import ru.mipt.npm.gradle.internal.fromJsDependencies import ru.mipt.npm.gradle.internal.fromJsDependencies
@Suppress("UNUSED_VARIABLE") @Suppress("UNUSED_VARIABLE")
open class KScienceCommonPlugin : Plugin<Project> { public open class KScienceCommonPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
//Common configuration //Common configuration
registerKScienceExtension() registerKScienceExtension()
@ -50,12 +51,10 @@ open class KScienceCommonPlugin : Plugin<Project> {
targetCompatibility = KScienceVersions.JVM_TARGET targetCompatibility = KScienceVersions.JVM_TARGET
} }
tasks.apply { tasks.withType<Test> {
withType<Test> {
useJUnitPlatform() useJUnitPlatform()
} }
} }
}
pluginManager.withPlugin("org.jetbrains.kotlin.js") { pluginManager.withPlugin("org.jetbrains.kotlin.js") {
//logger.info("Applying KScience configuration for JS project") //logger.info("Applying KScience configuration for JS project")
@ -112,7 +111,7 @@ open class KScienceCommonPlugin : Plugin<Project> {
} }
} }
sourceSets.invoke { sourceSets {
val commonMain by getting { val commonMain by getting {
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}"))
@ -128,7 +127,7 @@ open class KScienceCommonPlugin : Plugin<Project> {
val jvmTest by getting { val jvmTest by getting {
dependencies { dependencies {
implementation(kotlin("test-junit5")) implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:5.6.1") implementation("org.junit.jupiter:junit-jupiter:5.7.2")
} }
} }
val jsMain by getting val jsMain by getting
@ -155,18 +154,15 @@ open class KScienceCommonPlugin : Plugin<Project> {
targetCompatibility = KScienceVersions.JVM_TARGET targetCompatibility = KScienceVersions.JVM_TARGET
} }
tasks.apply { tasks.withType<Test> {
withType<Test> {
useJUnitPlatform() useJUnitPlatform()
} }
} }
} }
}
// apply dokka for all projects // apply dokka for all projects
if (!plugins.hasPlugin("org.jetbrains.dokka")) { if (!plugins.hasPlugin("org.jetbrains.dokka")) {
plugins.apply("org.jetbrains.dokka") apply<DokkaPlugin>()
} }
} }
} }

View File

@ -1,8 +1,12 @@
package ru.mipt.npm.gradle package ru.mipt.npm.gradle
import kotlinx.atomicfu.plugin.gradle.AtomicFUGradlePlugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.ApplicationPlugin import org.gradle.api.plugins.ApplicationPlugin
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.findByType import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.withType
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
@ -11,7 +15,7 @@ import ru.mipt.npm.gradle.internal.defaultPlatform
import ru.mipt.npm.gradle.internal.useCommonDependency import ru.mipt.npm.gradle.internal.useCommonDependency
import ru.mipt.npm.gradle.internal.useFx import ru.mipt.npm.gradle.internal.useFx
enum class FXModule(val artifact: String, vararg val dependencies: FXModule) { public enum class FXModule(public val artifact: String, public vararg val dependencies: FXModule) {
BASE("javafx-base"), BASE("javafx-base"),
GRAPHICS("javafx-graphics", BASE), GRAPHICS("javafx-graphics", BASE),
CONTROLS("javafx-controls", GRAPHICS, BASE), CONTROLS("javafx-controls", GRAPHICS, BASE),
@ -21,31 +25,29 @@ enum class FXModule(val artifact: String, vararg val dependencies: FXModule) {
WEB("javafx-web", CONTROLS, GRAPHICS, BASE) WEB("javafx-web", CONTROLS, GRAPHICS, BASE)
} }
enum class FXPlatform(val id: String) { public enum class FXPlatform(public val id: String) {
WINDOWS("win"), WINDOWS("win"),
LINUX("linux"), LINUX("linux"),
MAC("mac") MAC("mac")
} }
enum class DependencyConfiguration { public enum class DependencyConfiguration {
API, API,
IMPLEMENTATION, IMPLEMENTATION,
COMPILE_ONLY COMPILE_ONLY,
} }
enum class DependencySourceSet(val setName: String, val suffix: String) { public enum class DependencySourceSet(public val setName: String, public val suffix: String) {
MAIN("main", "Main"), MAIN("main", "Main"),
TEST("test", "Test") TEST("test", "Test")
} }
class KScienceExtension(val project: Project) { public class KScienceExtension(public val project: Project) {
/** /**
* Use coroutines-core with default version or [version] * Use coroutines-core with default version or [version]
*/ */
@Deprecated("Use version catalog.") public fun useCoroutines(
fun useCoroutines(
version: String = KScienceVersions.coroutinesVersion, version: String = KScienceVersions.coroutinesVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN, sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API, configuration: DependencyConfiguration = DependencyConfiguration.API,
@ -56,15 +58,14 @@ class KScienceExtension(val project: Project) {
) )
/** /**
* Use kotlinx-atmicfu plugin and library * Use kotlinx-atomicfu plugin and library
*/ */
@Deprecated("Use version catalog.") public fun useAtomic(
fun useAtomic(
version: String = KScienceVersions.atomicVersion, version: String = KScienceVersions.atomicVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN, sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION, configuration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION,
): Unit = project.run { ): Unit = project.run {
plugins.apply("kotlinx-atomicfu") apply<AtomicFUGradlePlugin>()
useCommonDependency( useCommonDependency(
"org.jetbrains.kotlinx:atomicfu:$version", "org.jetbrains.kotlinx:atomicfu:$version",
dependencySourceSet = sourceSet, dependencySourceSet = sourceSet,
@ -75,14 +76,13 @@ class KScienceExtension(val project: Project) {
/** /**
* Use core serialization library and configure targets * Use core serialization library and configure targets
*/ */
@Deprecated("Use version catalog.") public fun useSerialization(
fun useSerialization(
version: String = KScienceVersions.serializationVersion, version: String = KScienceVersions.serializationVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN, sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API, configuration: DependencyConfiguration = DependencyConfiguration.API,
block: SerializationTargets.() -> Unit = {}, block: SerializationTargets.() -> Unit = {},
): Unit = project.run { ): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.plugin.serialization") apply("org.jetbrains.kotlin.plugin.serialization")
val artifactName = if (version.startsWith("0")) { val artifactName = if (version.startsWith("0")) {
"kotlinx-serialization-runtime" "kotlinx-serialization-runtime"
} else { } else {
@ -93,24 +93,23 @@ class KScienceExtension(val project: Project) {
dependencySourceSet = sourceSet, dependencySourceSet = sourceSet,
dependencyConfiguration = configuration dependencyConfiguration = configuration
) )
SerializationTargets(sourceSet, configuration).apply(block) SerializationTargets(sourceSet, configuration).block()
} }
/** /**
* Add platform-specific JavaFX dependencies with given list of [FXModule]s * Add platform-specific JavaFX dependencies with given list of [FXModule]s
*/ */
fun useFx( public fun useFx(
vararg modules: FXModule, vararg modules: FXModule,
configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY, configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY,
version: String = "11", version: String = "11",
platform: FXPlatform = defaultPlatform, platform: FXPlatform = defaultPlatform,
) = project.useFx(modules.toList(), configuration, version, platform) ): Unit = project.useFx(modules.toList(), configuration, version, platform)
/** /**
* Add dependency on kotlinx-html library * Add dependency on kotlinx-html library
*/ */
@Deprecated("Use version catalog.") public fun useHtml(
fun useHtml(
version: String = KScienceVersions.htmlVersion, version: String = KScienceVersions.htmlVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN, sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API, configuration: DependencyConfiguration = DependencyConfiguration.API,
@ -123,36 +122,33 @@ class KScienceExtension(val project: Project) {
/** /**
* Use kotlinx-datetime library with default version or [version] * Use kotlinx-datetime library with default version or [version]
*/ */
@Deprecated("Use version catalog.") public fun useDateTime(
fun useDateTime(
version: String = KScienceVersions.dateTimeVersion, version: String = KScienceVersions.dateTimeVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN, sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API, configuration: DependencyConfiguration = DependencyConfiguration.API,
) { ): Unit = project.useCommonDependency(
project.useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-datetime:$version", "org.jetbrains.kotlinx:kotlinx-datetime:$version",
dependencySourceSet = sourceSet, dependencySourceSet = sourceSet,
dependencyConfiguration = configuration dependencyConfiguration = configuration
) )
}
/** /**
* Apply jupyter plugin * Apply jupyter plugin
*/ */
fun useJupyter() { public fun useJupyter() {
project.plugins.apply("org.jetbrains.kotlin.jupyter.api") project.apply("org.jetbrains.kotlin.jupyter.api")
} }
/** /**
* 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
*/ */
fun application() { public fun application() {
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(ApplicationPlugin::class.java) project.apply<ApplicationPlugin>()
} }
project.extensions.findByType<KotlinJsProjectExtension>()?.apply { project.extensions.findByType<KotlinJsProjectExtension>()?.apply {
@ -165,8 +161,9 @@ class KScienceExtension(val project: Project) {
js { js {
binaries.executable() binaries.executable()
} }
targets.filterIsInstance<KotlinNativeTarget>().forEach {
it.binaries.executable() targets.withType<KotlinNativeTarget> {
binaries.executable()
} }
} }
} }

View File

@ -4,13 +4,14 @@ import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.apply
open class KScienceJSPlugin : Plugin<Project> { public open class KScienceJSPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run { override fun apply(project: Project): Unit = project.run {
if (plugins.findPlugin("org.jetbrains.kotlin.js") == null) { if (!plugins.hasPlugin("org.jetbrains.kotlin.js")) {
pluginManager.apply("org.jetbrains.kotlin.js") apply("org.jetbrains.kotlin.js")
} else { } else {
logger.info("Kotlin JS plugin is already present") logger.info("Kotlin JS plugin is already present")
} }
plugins.apply(KScienceCommonPlugin::class)
apply<KScienceCommonPlugin>()
} }
} }

View File

@ -4,13 +4,13 @@ import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.apply
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 {
if (plugins.findPlugin("org.jetbrains.kotlin.jvm") == null) { if (!plugins.hasPlugin("org.jetbrains.kotlin.jvm"))
pluginManager.apply("org.jetbrains.kotlin.jvm") apply("org.jetbrains.kotlin.jvm")
} else { else
logger.info("Kotlin JVM plugin is already present") logger.info("Kotlin JVM plugin is already present")
}
plugins.apply(KScienceCommonPlugin::class) apply<KScienceCommonPlugin>()
} }
} }

View File

@ -4,13 +4,14 @@ import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.apply
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 {
if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) { if (!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) {
pluginManager.apply("org.jetbrains.kotlin.multiplatform") apply("org.jetbrains.kotlin.multiplatform")
} else { } else {
logger.info("Kotlin MPP plugin is already present") logger.info("Kotlin MPP plugin is already present")
} }
plugins.apply(KScienceCommonPlugin::class)
apply<KScienceCommonPlugin>()
} }
} }

View File

@ -1,67 +1,56 @@
package ru.mipt.npm.gradle package ru.mipt.npm.gradle
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
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.apply import org.gradle.kotlin.dsl.*
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.findPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
private fun KotlinMultiplatformExtension.sourceSets(configure: Action<NamedDomainObjectContainer<KotlinSourceSet>>): Unit = public class KScienceNativePlugin : Plugin<Project> {
(this as org.gradle.api.plugins.ExtensionAware).extensions.configure("sourceSets", configure) override fun apply(project: Project): Unit = project.run {
class KScienceNativePlugin : Plugin<Project> {
override fun apply(project: Project) = project.run {
//Apply multiplatform plugin is not applied, apply it //Apply multiplatform plugin is not applied, apply it
if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) { if (!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) {
logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically")
pluginManager.apply("org.jetbrains.kotlin.multiplatform") apply("org.jetbrains.kotlin.multiplatform")
} }
if (plugins.findPlugin(KScienceCommonPlugin::class) == null) {
if (!plugins.hasPlugin(KScienceCommonPlugin::class)) {
logger.info("KScience plugin is not resolved. Adding it automatically") logger.info("KScience plugin is not resolved. Adding it automatically")
pluginManager.apply(KScienceCommonPlugin::class) apply<KScienceCommonPlugin>()
} }
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {
val hostOs = System.getProperty("os.name") val nativeTargets = setOf(
linuxX64(),
val isLinux = hostOs == "Linux" mingwX64(),
val isMinGw = hostOs.startsWith("Windows") macosX64(),
val isMacOs = hostOs == "Mac OS X" )
if (isLinux || isMinGw) {
linuxX64()
}
if (isMinGw) {
mingwX64()
}
if (isMacOs) {
macosX64()
}
sourceSets { sourceSets {
val commonMain = findByName("commonMain")!! val commonMain = findByName("commonMain")!!
val commonTest = findByName("commonTest")!! val commonTest = findByName("commonTest")!!
val nativeMain = create("nativeMain").apply { val nativeMain by creating {
dependsOn(commonMain) dependsOn(commonMain)
} }
val nativeTest = create("nativeTest").apply { val nativeTest by creating {
dependsOn(nativeMain)
dependsOn(commonTest) dependsOn(commonTest)
} }
findByName("linuxX64Main")?.dependsOn(nativeMain) configure(nativeTargets) {
findByName("linuxX64Test")?.dependsOn(nativeTest) compilations["main"]?.apply {
configure(kotlinSourceSets) {
dependsOn(nativeMain)
}
}
findByName("mingwX64Main")?.dependsOn(nativeMain) compilations["test"]?.apply {
findByName("mingwX64Test")?.dependsOn(nativeTest) configure(kotlinSourceSets) {
dependsOn(nativeTest)
findByName("macosX64Main")?.dependsOn(nativeMain) }
findByName("macosX64Test")?.dependsOn(nativeTest) }
}
} }
} }
} }

View File

@ -1,31 +1,27 @@
package ru.mipt.npm.gradle package ru.mipt.npm.gradle
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
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.apply import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.findPlugin import org.gradle.kotlin.dsl.findPlugin
import org.gradle.kotlin.dsl.invoke
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
private fun KotlinMultiplatformExtension.sourceSets(configure: Action<NamedDomainObjectContainer<KotlinSourceSet>>): Unit =
(this as org.gradle.api.plugins.ExtensionAware).extensions.configure("sourceSets", configure)
/** /**
* Create a separate target for node * Create a separate target for node
*/ */
class KScienceNodePlugin : Plugin<Project> { public class KScienceNodePlugin : Plugin<Project> {
override fun apply(target: Project) = target.run { override fun apply(target: Project): Unit = target.run {
//Apply multiplatform plugin is not applied, apply it //Apply multiplatform plugin is not applied, apply it
if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) { if (plugins.findPlugin("org.jetbrains.kotlin.multiplatform") == null) {
logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically") logger.info("Kotlin multiplatform plugin is not resolved. Adding it automatically")
pluginManager.apply("org.jetbrains.kotlin.multiplatform") apply("org.jetbrains.kotlin.multiplatform")
} }
if (plugins.findPlugin(KScienceCommonPlugin::class) == null) { if (plugins.findPlugin(KScienceCommonPlugin::class) == null) {
logger.info("KScience plugin is not resolved. Adding it automatically") logger.info("KScience plugin is not resolved. Adding it automatically")
pluginManager.apply(KScienceCommonPlugin::class) apply<KScienceCommonPlugin>()
} }
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {

View File

@ -11,19 +11,46 @@ import org.jetbrains.changelog.ChangelogPlugin
import org.jetbrains.changelog.ChangelogPluginExtension import org.jetbrains.changelog.ChangelogPluginExtension
import org.jetbrains.dokka.gradle.AbstractDokkaTask import org.jetbrains.dokka.gradle.AbstractDokkaTask
import org.jetbrains.dokka.gradle.DokkaPlugin import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.DokkaTask
import ru.mipt.npm.gradle.internal.* import ru.mipt.npm.gradle.internal.*
private fun Project.allTasks(): Set<Task> = allprojects.flatMapTo(HashSet()) { it.tasks } private fun Project.allTasks(): Set<Task> = allprojects.flatMapTo(HashSet()) { it.tasks }
@Suppress("unused") @Suppress("unused")
class KSciencePublishingExtension(val project: Project) { public class KSciencePublishingExtension(public val project: Project) {
private var initializedFlag = false private var isVcsInitialized = false
fun vcs(vcsUrl: String) { @Deprecated("Use git function and report an issue if other VCS is used.")
if (!initializedFlag) { public fun vcs(vcsUrl: String) {
project.setupPublication(vcsUrl) if (!isVcsInitialized) {
initializedFlag = true project.setupPublication {
url.set(vcsUrl)
scm { url.set(vcsUrl) }
}
isVcsInitialized = true
}
}
/**
* Configures Git repository for the publication.
*
* @param vcsUrl URL of the repository's web interface.
* @param connectionUrl URL of the Git repository.
* @param developerConnectionUrl URL of the Git repository for developers.
*/
public fun git(vcsUrl: String, connectionUrl: String? = null, developerConnectionUrl: String? = connectionUrl) {
if (!isVcsInitialized) {
project.setupPublication {
url.set(vcsUrl)
scm {
url.set(vcsUrl)
connectionUrl?.let { connection.set("scm:git:$it") }
developerConnectionUrl?.let { developerConnection.set("scm:git:$it") }
}
}
isVcsInitialized = true
} }
} }
@ -34,17 +61,19 @@ class KSciencePublishingExtension(val project: Project) {
} }
/** /**
* github publishing * Adds GitHub as VCS and adds GitHub Packages Maven repository to publishing.
* @param publish include github packages in release publishing. By default - false *
* @param githubProject the GitHub project.
* @param githubOrg the GitHub user or organization.
* @param released whether publish packages in the `release` task to the GitHub repository.
*/ */
fun github(githubProject: String, githubOrg: String = "mipt-npm", publish: Boolean = false) { public fun github(githubProject: String, githubOrg: String = "mipt-npm", released: Boolean = false, published: Boolean = true) {
//automatically initialize vcs using github // Automatically initialize VCS using GitHub
if (!initializedFlag) { if (!isVcsInitialized)
vcs("https://github.com/$githubOrg/$githubProject") git("https://github.com/$githubOrg/${githubProject}", "https://github.com/$githubOrg/${githubProject}.git")
}
project.addGithubPublishing(githubOrg, githubProject) if (published) project.addGithubPublishing(githubOrg, githubProject)
if (publish) linkPublicationsToReleaseTask("github") if (released) linkPublicationsToReleaseTask("github")
} }
private val releaseTask by lazy { private val releaseTask by lazy {
@ -52,13 +81,16 @@ class KSciencePublishingExtension(val project: Project) {
} }
/** /**
* Space publishing * Adds Space Packages Maven repository to publishing.
*
* @param spaceRepo the repository URL.
* @param released whether publish packages in the `release` task to the Space repository.
*/ */
fun space(spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", publish: Boolean = false) { public fun space(spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", released: Boolean = false) {
require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" } require(isVcsInitialized) { "The project vcs is not set up use 'vcs' method to do so" }
project.addSpacePublishing(spaceRepo) project.addSpacePublishing(spaceRepo)
if (publish) linkPublicationsToReleaseTask("space") if (released) linkPublicationsToReleaseTask("space")
} }
// // Bintray publishing // // Bintray publishing
@ -68,20 +100,23 @@ class KSciencePublishingExtension(val project: Project) {
// var bintrayRepo: String? by project.extra // var bintrayRepo: String? by project.extra
/** /**
* Sonatype publishing * Adds Sonatype Maven repository to publishing.
*
* @param released whether publish packages in the `release` task to the Sonatype repository.
*/ */
fun sonatype(publish: Boolean = true) { public fun sonatype(released: Boolean = true) {
require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" } require(isVcsInitialized) { "The project vcs is not set up use 'vcs' method to do so" }
project.addSonatypePublishing() project.addSonatypePublishing()
if (publish) linkPublicationsToReleaseTask("sonatype") if (released) linkPublicationsToReleaseTask("sonatype")
} }
} }
/** /**
* Apply extension and repositories * Applies third-party plugins (Dokka, Changelog, binary compatibility validator); configures Maven publishing, README
* generation.
*/ */
open class KScienceProjectPlugin : Plugin<Project> { public open class KScienceProjectPlugin : Plugin<Project> {
override fun apply(target: Project): Unit = target.run { override fun apply(target: Project): Unit = target.run {
apply<ChangelogPlugin>() apply<ChangelogPlugin>()
@ -131,7 +166,8 @@ open class KScienceProjectPlugin : Plugin<Project> {
} }
} }
} }
tasks.withType<DokkaTask> {
tasks.withType<AbstractDokkaTask> {
dependsOn(generateReadme) dependsOn(generateReadme)
} }
} }
@ -219,7 +255,7 @@ open class KScienceProjectPlugin : Plugin<Project> {
} }
} }
companion object { public companion object {
const val RELEASE_GROUP = "release" public const val RELEASE_GROUP: String = "release"
} }
} }

View File

@ -3,10 +3,10 @@ package ru.mipt.npm.gradle
import groovy.text.SimpleTemplateEngine import groovy.text.SimpleTemplateEngine
import kotlinx.validation.ApiValidationExtension import kotlinx.validation.ApiValidationExtension
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.*
import java.io.File import java.io.File
enum class Maturity { public enum class Maturity {
PROTOTYPE, PROTOTYPE,
EXPERIMENTAL, EXPERIMENTAL,
DEVELOPMENT, DEVELOPMENT,
@ -14,16 +14,17 @@ enum class Maturity {
} }
class KScienceReadmeExtension(val project: Project) { public class KScienceReadmeExtension(public val project: Project) {
var description: String = project.description ?: "" public var description: String = project.description ?: ""
var maturity: Maturity = Maturity.EXPERIMENTAL
public var maturity: Maturity = Maturity.EXPERIMENTAL
set(value) { set(value) {
field = value field = value
val projectName = project.name val projectName = project.name
if (value == Maturity.EXPERIMENTAL || value == Maturity.PROTOTYPE) { if (value == Maturity.EXPERIMENTAL || value == Maturity.PROTOTYPE) {
project.rootProject.run { project.rootProject.run {
plugins.withId("org.jetbrains.kotlinx.binary-compatibility-validator") { plugins.withId("org.jetbrains.kotlinx.binary-compatibility-validator") {
extensions.getByType<ApiValidationExtension>().apply { extensions.findByType<ApiValidationExtension>()?.apply {
project.logger.warn("$value project $projectName is excluded from API validation") project.logger.warn("$value project $projectName is excluded from API validation")
ignoredProjects.add(projectName) ignoredProjects.add(projectName)
} }
@ -32,18 +33,18 @@ class KScienceReadmeExtension(val project: Project) {
} }
} }
var readmeTemplate: File = project.file("docs/README-TEMPLATE.md") public var readmeTemplate: File = project.file("docs/README-TEMPLATE.md")
data class Feature(val id: String, val description: String, val ref: String?, val name: String = id) public data class Feature(val id: String, val description: String, val ref: String?, val name: String = id)
val features: MutableList<Feature> = ArrayList() public val features: MutableList<Feature> = ArrayList()
@Deprecated("Use lambda builder instead") @Deprecated("Use lambda builder instead.")
fun feature(id: String, description: String, ref: String? = null, name: String = id) { public fun feature(id: String, description: String, ref: String? = null, name: String = id) {
features += Feature(id, description, ref, name) features += Feature(id, description, ref, name)
} }
fun feature(id: String, ref: String? = null, name: String = id, description: () -> String) { public fun feature(id: String, ref: String? = null, name: String = id, description: () -> String) {
features += Feature(id, description(), ref, name) features += Feature(id, description(), ref, name)
} }
@ -54,25 +55,25 @@ class KScienceReadmeExtension(val project: Project) {
"features" to { featuresString() } "features" to { featuresString() }
) )
val actualizedProperties public val actualizedProperties: Map<String, Any?>
get() = properties.mapValues { (_, value) -> value() } get() = properties.mapValues { (_, value) -> value() }
fun property(key: String, value: Any?) { public fun property(key: String, value: Any?) {
properties[key] = { value } properties[key] = { value }
} }
fun property(key: String, value: () -> Any?) { public fun property(key: String, value: () -> Any?) {
properties[key] = value properties[key] = value
} }
fun propertyByTemplate(key: String, template: String) { public fun propertyByTemplate(key: String, template: String) {
val actual = actualizedProperties val actual = actualizedProperties
properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() } properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() }
} }
internal val additionalFiles = ArrayList<File>() internal val additionalFiles = ArrayList<File>()
fun propertyByTemplate(key: String, template: File) { public fun propertyByTemplate(key: String, template: File) {
val actual = actualizedProperties val actual = actualizedProperties
properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() } properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() }
additionalFiles += template additionalFiles += template
@ -81,7 +82,7 @@ class KScienceReadmeExtension(val project: Project) {
/** /**
* Generate a markdown string listing features * Generate a markdown string listing features
*/ */
fun featuresString(itemPrefix: String = " - ", pathPrefix: String = "") = buildString { public fun featuresString(itemPrefix: String = " - ", pathPrefix: String = ""): String = buildString {
features.forEach { features.forEach {
appendLine("$itemPrefix[${it.name}]($pathPrefix${it.ref ?: "#"}) : ${it.description}") appendLine("$itemPrefix[${it.name}]($pathPrefix${it.ref ?: "#"}) : ${it.description}")
} }
@ -90,12 +91,10 @@ class KScienceReadmeExtension(val project: Project) {
/** /**
* Generate a readme string from the stub * Generate a readme string from the stub
*/ */
fun readmeString(): String? { public fun readmeString(): String? = if (readmeTemplate.exists()) {
return if (readmeTemplate.exists()) {
val actual = actualizedProperties val actual = actualizedProperties
SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString() SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString()
} else { } else {
null null
} }
} }
}

View File

@ -7,20 +7,20 @@ import org.gradle.api.JavaVersion
*/ */
@Deprecated("Use version catalog.") @Deprecated("Use version catalog.")
object KScienceVersions { object KScienceVersions {
const val kotlinVersion = "1.5.21" const val kotlinVersion = "1.5.30"
const val kotlinxNodeVersion = "0.0.7" const val kotlinxNodeVersion = "0.0.7"
const val coroutinesVersion = "1.5.1" const val coroutinesVersion = "1.5.1"
const val serializationVersion = "1.2.2" const val serializationVersion = "1.2.2"
const val atomicVersion = "0.16.2" const val atomicVersion = "0.16.2"
const val ktorVersion = "1.6.1" const val ktorVersion = "1.6.2"
const val htmlVersion = "0.7.3" const val htmlVersion = "0.7.3"
const val dateTimeVersion = "0.2.1" const val dateTimeVersion = "0.2.1"
const val jsBom = "0.0.1-pre.216-kotlin-1.5.20" const val jsBom = "0.0.1-pre.216-kotlin-1.5.20"
val JVM_TARGET = JavaVersion.VERSION_11 public val JVM_TARGET: JavaVersion = JavaVersion.VERSION_11
object Serialization{ public object Serialization {
const val xmlVersion = "0.82.0" public const val xmlVersion: String = "0.82.0"
const val yamlKtVersion = "0.10.0" public const val yamlKtVersion: String = "0.10.0"
} }
} }

View File

@ -3,58 +3,47 @@ package ru.mipt.npm.gradle
import org.gradle.api.Project import org.gradle.api.Project
import ru.mipt.npm.gradle.internal.useCommonDependency import ru.mipt.npm.gradle.internal.useCommonDependency
class SerializationTargets( public class SerializationTargets(
val sourceSet: DependencySourceSet, public val sourceSet: DependencySourceSet,
val configuration: DependencyConfiguration public val configuration: DependencyConfiguration,
) { ) {
public fun Project.json(
fun Project.json( version: String = KScienceVersions.serializationVersion,
version: String = KScienceVersions.serializationVersion ): Unit = useCommonDependency(
) {
useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-serialization-json:$version", "org.jetbrains.kotlinx:kotlinx-serialization-json:$version",
dependencySourceSet = sourceSet, dependencySourceSet = sourceSet,
dependencyConfiguration = configuration dependencyConfiguration = configuration,
) )
}
fun Project.cbor( public fun Project.cbor(
version: String = KScienceVersions.serializationVersion version: String = KScienceVersions.serializationVersion,
) { ): Unit = useCommonDependency(
useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version", "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version",
dependencySourceSet = sourceSet, dependencySourceSet = sourceSet,
dependencyConfiguration = configuration dependencyConfiguration = configuration,
) )
}
fun Project.protobuf( public fun Project.protobuf(
version: String = KScienceVersions.serializationVersion version: String = KScienceVersions.serializationVersion,
) { ): Unit = useCommonDependency(
useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version", "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version",
dependencySourceSet = sourceSet, dependencySourceSet = sourceSet,
dependencyConfiguration = configuration dependencyConfiguration = configuration,
) )
}
fun Project.xml( public fun Project.xml(
version: String = KScienceVersions.Serialization.xmlVersion version: String = KScienceVersions.Serialization.xmlVersion,
) { ): Unit = useCommonDependency(
useCommonDependency(
"io.github.pdvrieze.xmlutil:serialization:$version", "io.github.pdvrieze.xmlutil:serialization:$version",
dependencySourceSet = sourceSet, dependencySourceSet = sourceSet,
dependencyConfiguration = configuration dependencyConfiguration = configuration,
) )
}
fun Project.yamlKt( public fun Project.yamlKt(
version: String = KScienceVersions.Serialization.yamlKtVersion version: String = KScienceVersions.Serialization.yamlKtVersion,
) { ): Unit = useCommonDependency(
useCommonDependency(
"net.mamoe.yamlkt:yamlkt:$version", "net.mamoe.yamlkt:yamlkt:$version",
dependencySourceSet = sourceSet, dependencySourceSet = sourceSet,
dependencyConfiguration = configuration dependencyConfiguration = configuration,
) )
} }
}

View File

@ -11,7 +11,7 @@ import org.gradle.language.jvm.tasks.ProcessResources
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
internal fun LanguageSettingsBuilder.applySettings(): Unit { internal fun LanguageSettingsBuilder.applySettings() {
languageVersion = "1.5" languageVersion = "1.5"
apiVersion = "1.5" apiVersion = "1.5"
progressiveMode = true progressiveMode = true
@ -23,7 +23,7 @@ internal fun LanguageSettingsBuilder.applySettings(): Unit {
useExperimentalAnnotation("kotlin.js.ExperimentalJsExport") useExperimentalAnnotation("kotlin.js.ExperimentalJsExport")
} }
internal fun RepositoryHandler.applyRepos(): Unit { internal fun RepositoryHandler.applyRepos() {
mavenCentral() mavenCentral()
maven("https://repo.kotlin.link") maven("https://repo.kotlin.link")
} }
@ -50,8 +50,7 @@ internal fun Copy.fromJsDependencies(configurationName: String) = project.run {
} }
} }
internal fun KotlinMultiplatformExtension.bundleJsBinaryAsResource(bundleName: String = "js/bundle.js"){
fun KotlinMultiplatformExtension.bundleJsBinaryAsResource(bundleName: String = "js/bundle.js"){
js { js {
binaries.executable() binaries.executable()
browser { browser {

View File

@ -87,7 +87,6 @@ internal fun Project.useCommonDependency(
} }
} }
withPlugin("org.jetbrains.kotlin.jvm") { withPlugin("org.jetbrains.kotlin.jvm") {
configure<KotlinJvmProjectExtension> { configure<KotlinJvmProjectExtension> {
sourceSets.findByName(dependencySourceSet.setName)?.apply { sourceSets.findByName(dependencySourceSet.setName)?.apply {
@ -102,6 +101,7 @@ internal fun Project.useCommonDependency(
} }
} }
} }
withPlugin("org.jetbrains.kotlin.js") { withPlugin("org.jetbrains.kotlin.js") {
configure<KotlinJsProjectExtension> { configure<KotlinJsProjectExtension> {
sourceSets.findByName(dependencySourceSet.setName)?.apply { sourceSets.findByName(dependencySourceSet.setName)?.apply {

View File

@ -2,6 +2,7 @@ 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
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.findByType 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
@ -10,7 +11,7 @@ import ru.mipt.npm.gradle.DependencyConfiguration
import ru.mipt.npm.gradle.FXModule import ru.mipt.npm.gradle.FXModule
import ru.mipt.npm.gradle.FXPlatform import ru.mipt.npm.gradle.FXPlatform
val defaultPlatform: FXPlatform = when { internal val defaultPlatform: FXPlatform = when {
Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS
Os.isFamily(Os.FAMILY_MAC) -> FXPlatform.MAC Os.isFamily(Os.FAMILY_MAC) -> FXPlatform.MAC
Os.isFamily(Os.FAMILY_UNIX) -> FXPlatform.LINUX Os.isFamily(Os.FAMILY_UNIX) -> FXPlatform.LINUX

View File

@ -2,10 +2,12 @@ package ru.mipt.npm.gradle.internal
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar 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.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
@ -16,52 +18,51 @@ private fun Project.requestProperty(propertyName: String): String = requestPrope
?: error("Property $propertyName not defined") ?: error("Property $propertyName not defined")
internal fun Project.setupPublication(vcs: String) = allprojects { internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit = {}) = allprojects {
plugins.withId("maven-publish") { plugins.withId("maven-publish") {
configure<PublishingExtension> { configure<PublishingExtension> {
plugins.withId("org.jetbrains.kotlin.js") { plugins.withId("org.jetbrains.kotlin.js") {
val kotlin: KotlinJsProjectExtension = extensions.findByType()!! val kotlin: KotlinJsProjectExtension = extensions.findByType()!!
val sourcesJar: Jar by tasks.creating(Jar::class) { val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources") archiveClassifier.set("sources")
kotlin.sourceSets.forEach{
from(it.kotlin) kotlin.sourceSets.all {
from(kotlin)
} }
} }
afterEvaluate { afterEvaluate {
publications { publications.create<MavenPublication>("js") {
create("js", MavenPublication::class) {
kotlin.js().components.forEach { kotlin.js().components.forEach {
from(it) from(it)
} }
artifact(sourcesJar) artifact(sourcesJar)
} }
} }
} }
}
plugins.withId("org.jetbrains.kotlin.jvm") { plugins.withId("org.jetbrains.kotlin.jvm") {
val kotlin = extensions.findByType<KotlinJvmProjectExtension>()!! val kotlin = extensions.findByType<KotlinJvmProjectExtension>()!!
val sourcesJar: Jar by tasks.creating(Jar::class) { val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources") archiveClassifier.set("sources")
kotlin.sourceSets.forEach { kotlin.sourceSets.forEach {
from(it.kotlin) from(it.kotlin)
} }
} }
publications { publications.create<MavenPublication>("jvm") {
create("jvm", MavenPublication::class) {
kotlin.target.components.forEach { kotlin.target.components.forEach {
from(it) from(it)
} }
artifact(sourcesJar) artifact(sourcesJar)
} }
} }
}
val dokkaJar: Jar by tasks.creating(Jar::class) { val dokkaJar by tasks.creating(Jar::class) {
group = "documentation" group = "documentation"
archiveClassifier.set("javadoc") archiveClassifier.set("javadoc")
from(tasks.findByName("dokkaHtml")) from(tasks.findByName("dokkaHtml"))
@ -69,35 +70,35 @@ internal fun Project.setupPublication(vcs: String) = allprojects {
// Process each publication we have in this project // Process each publication we have in this project
afterEvaluate { afterEvaluate {
publications.withType<MavenPublication>().forEach { publication -> publications.withType<MavenPublication> {
publication.artifact(dokkaJar) artifact(dokkaJar)
publication.pom {
pom {
name.set(project.name) name.set(project.name)
description.set(project.description ?: project.name) description.set(project.description ?: project.name)
url.set(vcs)
licenses { licenses {
license { license {
name.set("The Apache Software License, Version 2.0") name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo") distribution.set("repo")
} }
} }
developers { developers {
developer { developer {
id.set("MIPT-NPM") id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory") name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT") organization.set("MIPT")
organizationUrl.set("http://npm.mipt.ru") organizationUrl.set("https://npm.mipt.ru")
}
} }
}
scm { scm {
url.set(vcs)
tag.set(project.version.toString()) tag.set(project.version.toString())
//developerConnection = "scm:git:[fetch=]/*ВАША ССЫЛКА НА .git файл*/[push=]/*Повторить предыдущую ссылку*/"
} }
mavenPomConfiguration()
} }
} }
} }
@ -105,7 +106,7 @@ internal fun Project.setupPublication(vcs: String) = allprojects {
} }
} }
internal fun Project.isSnapshot() = version.toString().contains("dev") || version.toString().endsWith("SNAPSHOT") internal fun Project.isSnapshot() = "dev" in version.toString() || version.toString().endsWith("SNAPSHOT")
internal val Project.publicationTarget: String internal val Project.publicationTarget: String
get() { get() {
@ -137,10 +138,11 @@ internal fun Project.addGithubPublishing(
plugins.withId("maven-publish") { plugins.withId("maven-publish") {
configure<PublishingExtension> { configure<PublishingExtension> {
logger.info("Adding github publishing to project [${project.name}]") logger.info("Adding github publishing to project [${project.name}]")
repositories {
maven { repositories.maven {
name = "github" name = "github"
url = uri("https://maven.pkg.github.com/$githubOrg/$githubProject/") url = uri("https://maven.pkg.github.com/$githubOrg/$githubProject/")
credentials { credentials {
username = githubUser username = githubUser
password = githubToken password = githubToken
@ -150,13 +152,13 @@ internal fun Project.addGithubPublishing(
} }
} }
} }
}
internal fun Project.addSpacePublishing(spaceRepo: String) { internal fun Project.addSpacePublishing(spaceRepo: String) {
if (requestPropertyOrNull("publishing.enabled") != "true") { if (requestPropertyOrNull("publishing.enabled") != "true") {
logger.info("Skipping github publishing because publishing is disabled") logger.info("Skipping github publishing because publishing is disabled")
return return
} }
if (requestPropertyOrNull("publishing.space") == "false") { if (requestPropertyOrNull("publishing.space") == "false") {
logger.info("Skipping space publishing because `publishing.space == false`") logger.info("Skipping space publishing because `publishing.space == false`")
return return
@ -169,16 +171,15 @@ internal fun Project.addSpacePublishing(spaceRepo: String) {
plugins.withId("maven-publish") { plugins.withId("maven-publish") {
configure<PublishingExtension> { configure<PublishingExtension> {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]") project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories {
maven { repositories.maven {
name = "space" name = "space"
url = uri(spaceRepo) url = uri(spaceRepo)
credentials { credentials {
username = spaceUser username = spaceUser
password = spaceToken password = spaceToken
} }
}
} }
} }
} }
@ -190,10 +191,12 @@ internal fun Project.addSonatypePublishing() {
logger.info("Skipping github publishing because publishing is disabled") logger.info("Skipping github publishing because publishing is disabled")
return return
} }
if (isSnapshot()) { if (isSnapshot()) {
logger.info("Sonatype publishing skipped for dev version") logger.info("Sonatype publishing skipped for dev version")
return return
} }
if (requestPropertyOrNull("publishing.sonatype") == "false") { if (requestPropertyOrNull("publishing.sonatype") == "false") {
logger.info("Skipping sonatype publishing because `publishing.sonatype == false`") logger.info("Skipping sonatype publishing because `publishing.sonatype == false`")
return return
@ -206,27 +209,27 @@ internal fun Project.addSonatypePublishing() {
allprojects { allprojects {
plugins.withId("maven-publish") { plugins.withId("maven-publish") {
configure<PublishingExtension> { configure<PublishingExtension> {
val sonatypeRepo: String = "https://oss.sonatype.org/service/local/staging/deploy/maven2" val sonatypeRepo = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
if (plugins.findPlugin("signing") == null) { if (!plugins.hasPlugin("signing") ) {
plugins.apply("signing") apply<SigningPlugin>()
} }
extensions.configure<SigningExtension>("signing") { extensions.configure<SigningExtension>("signing") {
if (!signingId.isNullOrBlank()) { if (!signingId.isNullOrBlank()) {
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 key is provided, use it
@Suppress("UnstableApiUsage")
useInMemoryPgpKeys(signingId, signingKey, signingPassphrase) useInMemoryPgpKeys(signingId, signingKey, signingPassphrase)
} // else use file signing } // else use file signing
sign(publications) sign(publications)
} }
repositories { repositories.maven {
maven {
name = "sonatype" name = "sonatype"
url = uri(sonatypeRepo) url = uri(sonatypeRepo)
credentials { credentials {
username = sonatypeUser username = sonatypeUser
password = sonatypePassword password = sonatypePassword
@ -236,10 +239,3 @@ internal fun Project.addSonatypePublishing() {
} }
} }
} }
}
//internal val Project.bintrayPublish: Boolean
// get() = (findProperty("publishing.bintray.publish") as? String)?.toBoolean() ?: false
//internal val Project.bintrayOrg: String? get() = findProperty("publishing.bintray.org") as? String
//internal val Project.bintrayUser: String? get() = findProperty("publishing.bintray.user") as? String
//internal val Project.bintrayApiKey: String? get() = findProperty("publishing.bintray.apiKey") as? String