pre-0.10.8

This commit is contained in:
Alexander Nozik 2021-12-12 12:23:29 +03:00
parent 0ba835925e
commit 7d16d0f5c7
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
7 changed files with 212 additions and 198 deletions

View File

@ -1,11 +1,11 @@
[versions] [versions]
tools = "0.10.7" tools = "0.10.8-kotlin-1.6.0"
kotlin = "1.6.0" kotlin = "1.6.0"
atomicfu = "0.17.0" atomicfu = "0.17.0"
binary-compatibility-validator = "0.8.0" binary-compatibility-validator = "0.8.0"
changelog = "1.3.1" changelog = "1.3.1"
dokka = "1.6.0" dokka = "1.6.0"
kotlin-jupyter = "0.11.0-6" kotlin-jupyter = "0.11.0-39"
kotlinx-benchmark = "0.3.1" kotlinx-benchmark = "0.3.1"
kotlinx-cli = "0.3.3" kotlinx-cli = "0.3.3"
kotlinx-collections-immutable = "0.3.4" kotlinx-collections-immutable = "0.3.4"
@ -15,10 +15,10 @@ kotlinx-html = "0.7.3"
kotlinx-knit = "0.3.0" kotlinx-knit = "0.3.0"
kotlinx-nodejs = "0.0.7" kotlinx-nodejs = "0.0.7"
kotlinx-serialization = "1.3.1" kotlinx-serialization = "1.3.1"
ktor = "1.6.5" ktor = "1.6.6"
xmlutil = "0.83.0" xmlutil = "0.83.0"
yamlkt = "0.10.2" yamlkt = "0.10.2"
jsBom = "0.0.1-pre.265-kotlin-1.5.31" jsBom = "0.0.1-pre.279-kotlin-1.6.0"
junit = "5.8.1" junit = "5.8.1"
[libraries] [libraries]

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

View File

@ -2,169 +2,10 @@ 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.api.tasks.Copy
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.*
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.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.fromJsDependencies
@Suppress("UNUSED_VARIABLE") @Suppress("UNUSED_VARIABLE")
public open class KScienceCommonPlugin : Plugin<Project> { public open class KScienceCommonPlugin : Plugin<Project> {
public companion object { override fun apply(project: Project): Unit = project.configureKScience(
public val defaultJvmArgs: List<String> = listOf("-Xjvm-default=all", "-Xlambdas=indy") KotlinVersion(1, 6, 0)
} )
override fun apply(project: Project): Unit = project.run {
//Common configuration
registerKScienceExtension()
repositories.applyRepos()
//Configuration for K-JVM plugin
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
//logger.info("Applying KScience configuration for JVM project")
configure<KotlinJvmProjectExtension> {
explicitApiWarning()
sourceSets.all {
languageSettings.applySettings()
}
sourceSets["test"].apply {
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
}
}
}
tasks.withType<KotlinJvmCompile> {
kotlinOptions {
jvmTarget = KScienceVersions.JVM_TARGET.toString()
freeCompilerArgs = freeCompilerArgs + defaultJvmArgs
}
}
extensions.findByType<JavaPluginExtension>()?.apply {
targetCompatibility = KScienceVersions.JVM_TARGET
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
//logger.info("Applying KScience configuration for JS project")
configure<KotlinJsProjectExtension> {
explicitApiWarning()
js(IR) {
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
}
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"))
}
}
}
(tasks.findByName("processResources") as? Copy)?.apply {
fromJsDependencies("runtimeClasspath")
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> {
explicitApiWarning()
jvm {
compilations.all {
kotlinOptions {
jvmTarget = KScienceVersions.JVM_TARGET.toString()
freeCompilerArgs = freeCompilerArgs + defaultJvmArgs
}
}
}
js(IR) {
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}"))
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmMain by getting
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
}
}
val jsMain by getting
val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}
}
sourceSets.all {
languageSettings.applySettings()
}
(tasks.findByName("jsProcessResources") as? Copy)?.apply {
fromJsDependencies("jsRuntimeClasspath")
}
extensions.findByType<JavaPluginExtension>()?.apply {
targetCompatibility = KScienceVersions.JVM_TARGET
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
}
// apply dokka for all projects
if (!plugins.hasPlugin("org.jetbrains.dokka")) {
apply<DokkaPlugin>()
}
}
} }

View File

@ -54,10 +54,18 @@ public class KSciencePublishingExtension(public val project: Project) {
} }
} }
@Suppress("UNUSED_VARIABLE") private val release by project.tasks.creating {
group = KScienceProjectPlugin.RELEASE_GROUP
description = "Publish development or production release based on version suffix"
}
private fun linkPublicationsToReleaseTask(name: String) = project.afterEvaluate { private fun linkPublicationsToReleaseTask(name: String) = project.afterEvaluate {
allTasks() allTasks()
.filter { it.name == "publish${publicationTarget}To${name.capitalize()}Repository" } .filter { it.name == "publish${publicationTarget}To${name.capitalize()}Repository" }
.forEach { releaseTask?.dependsOn(it) } .forEach {
logger.info("Linking $it to release")
release.dependsOn(it)
}
} }
/** /**
@ -65,40 +73,42 @@ public class KSciencePublishingExtension(public val project: Project) {
* *
* @param githubProject the GitHub project. * @param githubProject the GitHub project.
* @param githubOrg the GitHub user or organization. * @param githubOrg the GitHub user or organization.
* @param release whether publish packages in the `release` task to the GitHub repository. * @param publish add publish task for github.
* @param addToRelease publish packages in the `release` task to the GitHub repository.
*/ */
public fun github( public fun github(
githubProject: String, githubProject: String,
githubOrg: String = "mipt-npm", githubOrg: String = "mipt-npm",
release: Boolean = false, addToRelease: Boolean = project.requestPropertyOrNull("publishing.github") == "true",
publish: Boolean = true
) { ) {
// Automatically initialize VCS using GitHub // Automatically initialize VCS using GitHub
if (!isVcsInitialized) { if (!isVcsInitialized) {
git("https://github.com/$githubOrg/${githubProject}", "https://github.com/$githubOrg/${githubProject}.git") git("https://github.com/$githubOrg/${githubProject}", "https://github.com/$githubOrg/${githubProject}.git")
} }
if (publish) project.addGithubPublishing(githubOrg, githubProject) if (addToRelease) {
if (release) linkPublicationsToReleaseTask("github") try {
project.addGithubPublishing(githubOrg, githubProject)
linkPublicationsToReleaseTask("github")
} catch (t: Throwable){
project.logger.error("Failed to set up github publication", t)
}
} }
private val releaseTask by lazy {
project.tasks.findByName("release")
} }
/** /**
* Adds Space Packages Maven repository to publishing. * Adds Space Packages Maven repository to publishing.
* *
* @param spaceRepo the repository URL. * @param spaceRepo the repository URL.
* @param release whether publish packages in the `release` task to the Space repository. * @param addToRelease publish packages in the `release` task to the Space repository.
*/ */
public fun space( public fun space(
spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven",
release: Boolean = true addToRelease: Boolean = project.requestPropertyOrNull("publishing.space") != "false",
) { ) {
project.addSpacePublishing(spaceRepo) project.addSpacePublishing(spaceRepo)
if (release) linkPublicationsToReleaseTask("space") if (addToRelease) linkPublicationsToReleaseTask("space")
} }
// // Bintray publishing // // Bintray publishing
@ -110,13 +120,15 @@ public class KSciencePublishingExtension(public val project: Project) {
/** /**
* Adds Sonatype Maven repository to publishing. * Adds Sonatype Maven repository to publishing.
* *
* @param release whether publish packages in the `release` task to the Sonatype repository. * @param addToRelease publish packages in the `release` task to the Sonatype repository.
*/ */
public fun sonatype(release: Boolean = true) { public fun sonatype(
addToRelease: Boolean = (project.requestPropertyOrNull("publishing.sonatype") != "false"),
) {
require(isVcsInitialized) { "The project vcs is not set up use 'git' method to do so" } require(isVcsInitialized) { "The project vcs is not set up use 'git' method to do so" }
project.addSonatypePublishing() project.addSonatypePublishing()
if (release) linkPublicationsToReleaseTask("sonatype") if (addToRelease) linkPublicationsToReleaseTask("sonatype")
} }
} }
@ -246,14 +258,6 @@ public open class KScienceProjectPlugin : Plugin<Project> {
dependsOn(generateReadme) dependsOn(generateReadme)
} }
//val patchChangelog by tasks.getting
@Suppress("UNUSED_VARIABLE") val release by tasks.creating {
group = RELEASE_GROUP
description = "Publish development or production release based on version suffix"
dependsOn(generateReadme)
}
// Disable API validation for snapshots // Disable API validation for snapshots
if (isSnapshot()) { if (isSnapshot()) {
extensions.findByType<ApiValidationExtension>()?.apply { extensions.findByType<ApiValidationExtension>()?.apply {

View File

@ -0,0 +1,166 @@
package ru.mipt.npm.gradle
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.*
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.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.fromJsDependencies
private val defaultJvmArgs: List<String> = listOf("-Xjvm-default=all", "-Xlambdas=indy")
public fun Project.configureKScience(
kotlinVersion: KotlinVersion
){
//Common configuration
registerKScienceExtension()
repositories.applyRepos()
//Configuration for K-JVM plugin
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
//logger.info("Applying KScience configuration for JVM project")
configure<KotlinJvmProjectExtension> {
explicitApiWarning()
sourceSets.all {
languageSettings.applySettings(kotlinVersion)
}
sourceSets["test"].apply {
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
}
}
}
tasks.withType<KotlinJvmCompile> {
kotlinOptions {
jvmTarget = KScienceVersions.JVM_TARGET.toString()
freeCompilerArgs = freeCompilerArgs + defaultJvmArgs
}
}
extensions.findByType<JavaPluginExtension>()?.apply {
targetCompatibility = KScienceVersions.JVM_TARGET
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
//logger.info("Applying KScience configuration for JS project")
configure<KotlinJsProjectExtension> {
explicitApiWarning()
js(IR) {
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
}
sourceSets.all {
languageSettings.applySettings(kotlinVersion)
}
sourceSets["main"].apply {
dependencies {
api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}"))
}
}
sourceSets["test"].apply {
dependencies {
implementation(kotlin("test-js"))
}
}
}
(tasks.findByName("processResources") as? Copy)?.apply {
fromJsDependencies("runtimeClasspath")
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> {
explicitApiWarning()
jvm {
compilations.all {
kotlinOptions {
jvmTarget = KScienceVersions.JVM_TARGET.toString()
freeCompilerArgs = freeCompilerArgs + defaultJvmArgs
}
}
}
js(IR) {
browser {
commonWebpackConfig {
cssSupport.enabled = true
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
api(project.dependencies.platform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:${KScienceVersions.jsBom}"))
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmMain by getting
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit5"))
implementation("org.junit.jupiter:junit-jupiter:${KScienceVersions.junit}")
}
}
val jsMain by getting
val jsTest by getting {
dependencies {
implementation(kotlin("test-js"))
}
}
}
sourceSets.all {
languageSettings.applySettings(kotlinVersion)
}
(tasks.findByName("jsProcessResources") as? Copy)?.apply {
fromJsDependencies("jsRuntimeClasspath")
}
extensions.findByType<JavaPluginExtension>()?.apply {
targetCompatibility = KScienceVersions.JVM_TARGET
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
}
// apply dokka for all projects
if (!plugins.hasPlugin("org.jetbrains.dokka")) {
apply<DokkaPlugin>()
}
}

View File

@ -11,9 +11,12 @@ 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() { internal fun LanguageSettingsBuilder.applySettings(
languageVersion = "1.6" kotlinVersion: KotlinVersion
apiVersion = "1.6" ) {
val versionString = "${kotlinVersion.major}.${kotlinVersion.minor}"
languageVersion = versionString
apiVersion = versionString
progressiveMode = true progressiveMode = true
optIn("kotlin.RequiresOptIn") optIn("kotlin.RequiresOptIn")

View File

@ -11,10 +11,10 @@ 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
private fun Project.requestPropertyOrNull(propertyName: String): String? = findProperty(propertyName) as? String internal fun Project.requestPropertyOrNull(propertyName: String): String? = findProperty(propertyName) as? String
?: System.getenv(propertyName) ?: System.getenv(propertyName)
private fun Project.requestProperty(propertyName: String): String = requestPropertyOrNull(propertyName) internal fun Project.requestProperty(propertyName: String): String = requestPropertyOrNull(propertyName)
?: error("Property $propertyName not defined") ?: error("Property $propertyName not defined")
@ -126,8 +126,8 @@ internal fun Project.addGithubPublishing(
logger.info("Skipping github publishing because publishing is disabled") logger.info("Skipping github publishing because publishing is disabled")
return return
} }
if (requestPropertyOrNull("publishing.github") == "false") { if (requestPropertyOrNull("publishing.github") != "false") {
logger.info("Skipping github publishing because `publishing.github == false`") logger.info("Skipping github publishing because `publishing.github != true`")
return return
} }