Refactor: explicit API, publishing extension, code style #28

Merged
CommanderTvis merged 1 commits from commandertvis/fix-publish into dev 2021-09-12 10:09:33 +03:00
16 changed files with 308 additions and 301 deletions
Showing only changes of commit 02d2971b79 - Show all commits

View File

@ -22,6 +22,8 @@ repositories {
java.targetCompatibility = JavaVersion.VERSION_11
kotlin.explicitApiWarning()
dependencies {
api(libs.kotlin.gradle)
implementation(libs.atomicfu.gradle)
@ -158,7 +160,7 @@ afterEvaluate {
}
if (plugins.findPlugin("signing") == null) {
plugins.apply("signing")
apply<SigningPlugin>()
}
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.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
@ -15,7 +16,7 @@ import ru.mipt.npm.gradle.internal.applySettings
import ru.mipt.npm.gradle.internal.fromJsDependencies
@Suppress("UNUSED_VARIABLE")
open class KScienceCommonPlugin : Plugin<Project> {
public open class KScienceCommonPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run {
//Common configuration
registerKScienceExtension()
@ -50,10 +51,8 @@ open class KScienceCommonPlugin : Plugin<Project> {
targetCompatibility = KScienceVersions.JVM_TARGET
}
tasks.apply {
withType<Test> {
useJUnitPlatform()
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
@ -112,7 +111,7 @@ open class KScienceCommonPlugin : Plugin<Project> {
}
}
sourceSets.invoke {
sourceSets {
val commonMain by getting {
dependencies {
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 {
dependencies {
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
@ -155,18 +154,15 @@ open class KScienceCommonPlugin : Plugin<Project> {
targetCompatibility = KScienceVersions.JVM_TARGET
}
tasks.apply {
withType<Test> {
useJUnitPlatform()
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
}
// apply dokka for all projects
if (!plugins.hasPlugin("org.jetbrains.dokka")) {
plugins.apply("org.jetbrains.dokka")
apply<DokkaPlugin>()
}
}
}

View File

@ -1,8 +1,12 @@
package ru.mipt.npm.gradle
import kotlinx.atomicfu.plugin.gradle.AtomicFUGradlePlugin
import org.gradle.api.Project
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.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
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.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"),
GRAPHICS("javafx-graphics", BASE),
CONTROLS("javafx-controls", GRAPHICS, BASE),
@ -21,30 +25,29 @@ enum class FXModule(val artifact: String, vararg val dependencies: FXModule) {
WEB("javafx-web", CONTROLS, GRAPHICS, BASE)
}
enum class FXPlatform(val id: String) {
public enum class FXPlatform(public val id: String) {
WINDOWS("win"),
LINUX("linux"),
MAC("mac")
}
enum class DependencyConfiguration {
public enum class DependencyConfiguration {
API,
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"),
TEST("test", "Test")
}
class KScienceExtension(val project: Project) {
public class KScienceExtension(public val project: Project) {
/**
* Use coroutines-core with default version or [version]
*/
fun useCoroutines(
public fun useCoroutines(
version: String = KScienceVersions.coroutinesVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API,
@ -55,14 +58,14 @@ class KScienceExtension(val project: Project) {
)
/**
* Use kotlinx-atmicfu plugin and library
* Use kotlinx-atomicfu plugin and library
*/
fun useAtomic(
public fun useAtomic(
version: String = KScienceVersions.atomicVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.IMPLEMENTATION,
): Unit = project.run {
plugins.apply("kotlinx-atomicfu")
apply<AtomicFUGradlePlugin>()
useCommonDependency(
"org.jetbrains.kotlinx:atomicfu:$version",
dependencySourceSet = sourceSet,
@ -73,13 +76,13 @@ class KScienceExtension(val project: Project) {
/**
* Use core serialization library and configure targets
*/
fun useSerialization(
public fun useSerialization(
version: String = KScienceVersions.serializationVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API,
block: SerializationTargets.() -> Unit = {},
): Unit = project.run {
plugins.apply("org.jetbrains.kotlin.plugin.serialization")
apply("org.jetbrains.kotlin.plugin.serialization")
val artifactName = if (version.startsWith("0")) {
"kotlinx-serialization-runtime"
} else {
@ -90,23 +93,23 @@ class KScienceExtension(val project: Project) {
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
SerializationTargets(sourceSet, configuration).apply(block)
SerializationTargets(sourceSet, configuration).block()
}
/**
* Add platform-specific JavaFX dependencies with given list of [FXModule]s
*/
fun useFx(
public fun useFx(
vararg modules: FXModule,
configuration: DependencyConfiguration = DependencyConfiguration.COMPILE_ONLY,
version: String = "11",
platform: FXPlatform = defaultPlatform,
) = project.useFx(modules.toList(), configuration, version, platform)
): Unit = project.useFx(modules.toList(), configuration, version, platform)
/**
* Add dependency on kotlinx-html library
*/
fun useHtml(
public fun useHtml(
version: String = KScienceVersions.htmlVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API,
@ -119,35 +122,33 @@ class KScienceExtension(val project: Project) {
/**
* Use kotlinx-datetime library with default version or [version]
*/
fun useDateTime(
public fun useDateTime(
version: String = KScienceVersions.dateTimeVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API,
) {
project.useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-datetime:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
): Unit = project.useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-datetime:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
/**
* Apply jupyter plugin
*/
fun useJupyter() {
project.plugins.apply("org.jetbrains.kotlin.jupyter.api")
public fun useJupyter() {
project.apply("org.jetbrains.kotlin.jupyter.api")
}
/**
* Mark this module as an application module. JVM application should be enabled separately
*/
fun application() {
public fun application() {
project.extensions.findByType<KotlinProjectExtension>()?.apply {
explicitApi = null
}
project.pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
project.plugins.apply(ApplicationPlugin::class.java)
project.apply<ApplicationPlugin>()
}
project.extensions.findByType<KotlinJsProjectExtension>()?.apply {
@ -160,8 +161,9 @@ class KScienceExtension(val project: Project) {
js {
binaries.executable()
}
targets.filterIsInstance<KotlinNativeTarget>().forEach {
it.binaries.executable()
targets.withType<KotlinNativeTarget> {
binaries.executable()
}
}
}
@ -171,4 +173,4 @@ internal fun Project.registerKScienceExtension() {
if (extensions.findByType<KScienceExtension>() == null) {
extensions.add("kscience", KScienceExtension(this))
}
}
}

View File

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

View File

@ -1,68 +1,57 @@
package ru.mipt.npm.gradle
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.findPlugin
import org.gradle.kotlin.dsl.*
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)
class KScienceNativePlugin : Plugin<Project> {
override fun apply(project: Project) = project.run {
public class KScienceNativePlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run {
//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")
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")
pluginManager.apply(KScienceCommonPlugin::class)
apply<KScienceCommonPlugin>()
}
configure<KotlinMultiplatformExtension> {
val hostOs = System.getProperty("os.name")
val isLinux = hostOs == "Linux"
val isMinGw = hostOs.startsWith("Windows")
val isMacOs = hostOs == "Mac OS X"
if (isLinux || isMinGw) {
linuxX64()
}
if (isMinGw) {
mingwX64()
}
if (isMacOs) {
macosX64()
}
val nativeTargets = setOf(
linuxX64(),
mingwX64(),
macosX64(),
)
sourceSets {
val commonMain = findByName("commonMain")!!
val commonTest = findByName("commonTest")!!
val nativeMain = create("nativeMain").apply {
val nativeMain by creating {
dependsOn(commonMain)
}
val nativeTest = create("nativeTest").apply {
val nativeTest by creating {
dependsOn(nativeMain)
dependsOn(commonTest)
}
findByName("linuxX64Main")?.dependsOn(nativeMain)
findByName("linuxX64Test")?.dependsOn(nativeTest)
configure(nativeTargets) {
compilations["main"]?.apply {
configure(kotlinSourceSets) {
dependsOn(nativeMain)
}
}
findByName("mingwX64Main")?.dependsOn(nativeMain)
findByName("mingwX64Test")?.dependsOn(nativeTest)
findByName("macosX64Main")?.dependsOn(nativeMain)
findByName("macosX64Test")?.dependsOn(nativeTest)
compilations["test"]?.apply {
configure(kotlinSourceSets) {
dependsOn(nativeTest)
}
}
}
}
}
}
}
}

View File

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

View File

@ -17,13 +17,41 @@ import ru.mipt.npm.gradle.internal.*
private fun Project.allTasks(): Set<Task> = allprojects.flatMapTo(HashSet()) { it.tasks }
@Suppress("unused")
class KSciencePublishingExtension(val project: Project) {
private var initializedFlag = false
public class KSciencePublishingExtension(public val project: Project) {
private var isVcsInitialized = false
fun vcs(vcsUrl: String) {
if (!initializedFlag) {
project.setupPublication(vcsUrl)
initializedFlag = true
@Deprecated("Use git function and report an issue if other VCS is used.")
public fun vcs(vcsUrl: String) {
if (!isVcsInitialized) {
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 +62,19 @@ class KSciencePublishingExtension(val project: Project) {
}
/**
* github publishing
* @param publish include github packages in release publishing. By default - false
* Adds GitHub as VCS and adds GitHub Packages Maven repository to publishing.
*
* @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) {
//automatically initialize vcs using github
if (!initializedFlag) {
vcs("https://github.com/$githubOrg/$githubProject")
}
public fun github(githubProject: String, githubOrg: String = "mipt-npm", released: Boolean = false, published: Boolean = true) {
// Automatically initialize VCS using GitHub
if (!isVcsInitialized)
git("https://github.com/$githubOrg/${githubProject}", "https://github.com/$githubOrg/${githubProject}.git")
project.addGithubPublishing(githubOrg, githubProject)
if (publish) linkPublicationsToReleaseTask("github")
if (published) project.addGithubPublishing(githubOrg, githubProject)
if (released) linkPublicationsToReleaseTask("github")
}
private val releaseTask by lazy {
@ -52,13 +82,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) {
require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" }
public fun space(spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", released: Boolean = false) {
require(isVcsInitialized) { "The project vcs is not set up use 'vcs' method to do so" }
project.addSpacePublishing(spaceRepo)
if (publish) linkPublicationsToReleaseTask("space")
if (released) linkPublicationsToReleaseTask("space")
}
// // Bintray publishing
@ -68,20 +101,23 @@ class KSciencePublishingExtension(val project: Project) {
// 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) {
require(initializedFlag) { "The project vcs is not set up use 'vcs' method to do so" }
public fun sonatype(released: Boolean = true) {
require(isVcsInitialized) { "The project vcs is not set up use 'vcs' method to do so" }
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 {
apply<ChangelogPlugin>()
@ -219,7 +255,7 @@ open class KScienceProjectPlugin : Plugin<Project> {
}
}
companion object {
const val RELEASE_GROUP = "release"
public companion object {
public const val RELEASE_GROUP: String = "release"
}
}

View File

@ -3,10 +3,10 @@ package ru.mipt.npm.gradle
import groovy.text.SimpleTemplateEngine
import kotlinx.validation.ApiValidationExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.*
import java.io.File
enum class Maturity {
public enum class Maturity {
PROTOTYPE,
EXPERIMENTAL,
DEVELOPMENT,
@ -14,16 +14,17 @@ enum class Maturity {
}
class KScienceReadmeExtension(val project: Project) {
var description: String = project.description ?: ""
var maturity: Maturity = Maturity.EXPERIMENTAL
public class KScienceReadmeExtension(public val project: Project) {
public var description: String = project.description ?: ""
public var maturity: Maturity = Maturity.EXPERIMENTAL
set(value) {
field = value
val projectName = project.name
if (value == Maturity.EXPERIMENTAL || value == Maturity.PROTOTYPE) {
project.rootProject.run {
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")
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")
fun feature(id: String, description: String, ref: String? = null, name: String = id) {
@Deprecated("Use lambda builder instead.")
public fun feature(id: String, description: String, ref: String? = null, name: String = id) {
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)
}
@ -54,25 +55,25 @@ class KScienceReadmeExtension(val project: Project) {
"features" to { featuresString() }
)
val actualizedProperties
public val actualizedProperties: Map<String, Any?>
get() = properties.mapValues { (_, value) -> value() }
fun property(key: String, value: Any?) {
public fun property(key: String, value: Any?) {
properties[key] = { value }
}
fun property(key: String, value: () -> Any?) {
public fun property(key: String, value: () -> Any?) {
properties[key] = value
}
fun propertyByTemplate(key: String, template: String) {
public fun propertyByTemplate(key: String, template: String) {
val actual = actualizedProperties
properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() }
}
internal val additionalFiles = ArrayList<File>()
fun propertyByTemplate(key: String, template: File) {
public fun propertyByTemplate(key: String, template: File) {
val actual = actualizedProperties
properties[key] = { SimpleTemplateEngine().createTemplate(template).make(actual).toString() }
additionalFiles += template
@ -81,7 +82,7 @@ class KScienceReadmeExtension(val project: Project) {
/**
* Generate a markdown string listing features
*/
fun featuresString(itemPrefix: String = " - ", pathPrefix: String = "") = buildString {
public fun featuresString(itemPrefix: String = " - ", pathPrefix: String = ""): String = buildString {
features.forEach {
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
*/
fun readmeString(): String? {
return if (readmeTemplate.exists()) {
val actual = actualizedProperties
SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString()
} else {
null
}
public fun readmeString(): String? = if (readmeTemplate.exists()) {
val actual = actualizedProperties
SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString()
} else {
null
}
}
}

View File

@ -5,21 +5,21 @@ import org.gradle.api.JavaVersion
/**
* Build constants
*/
object KScienceVersions {
const val kotlinVersion = "1.5.21"
const val kotlinxNodeVersion = "0.0.7"
const val coroutinesVersion = "1.5.1"
const val serializationVersion = "1.2.2"
const val atomicVersion = "0.16.2"
const val ktorVersion = "1.6.1"
const val htmlVersion = "0.7.3"
const val dateTimeVersion = "0.2.1"
const val jsBom = "0.0.1-pre.216-kotlin-1.5.20"
public object KScienceVersions {
public const val kotlinVersion: String = "1.5.21"
public const val kotlinxNodeVersion: String = "0.0.7"
public const val coroutinesVersion: String = "1.5.1"
public const val serializationVersion: String = "1.2.2"
public const val atomicVersion: String = "0.16.2"
public const val ktorVersion: String = "1.6.1"
public const val htmlVersion: String = "0.7.3"
public const val dateTimeVersion: String = "0.2.1"
public const val jsBom: String = "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{
const val xmlVersion = "0.82.0"
const val yamlKtVersion = "0.10.0"
public object Serialization {
public const val xmlVersion: String = "0.82.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 ru.mipt.npm.gradle.internal.useCommonDependency
class SerializationTargets(
val sourceSet: DependencySourceSet,
val configuration: DependencyConfiguration
public class SerializationTargets(
public val sourceSet: DependencySourceSet,
public val configuration: DependencyConfiguration,
) {
public fun Project.json(
version: String = KScienceVersions.serializationVersion,
): Unit = useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-serialization-json:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration,
)
fun Project.json(
version: String = KScienceVersions.serializationVersion
) {
useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-serialization-json:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
public fun Project.cbor(
version: String = KScienceVersions.serializationVersion,
): Unit = useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration,
)
fun Project.cbor(
version: String = KScienceVersions.serializationVersion
) {
useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
public fun Project.protobuf(
version: String = KScienceVersions.serializationVersion,
): Unit = useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration,
)
fun Project.protobuf(
version: String = KScienceVersions.serializationVersion
) {
useCommonDependency(
"org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
public fun Project.xml(
version: String = KScienceVersions.Serialization.xmlVersion,
): Unit = useCommonDependency(
"io.github.pdvrieze.xmlutil:serialization:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration,
)
fun Project.xml(
version: String = KScienceVersions.Serialization.xmlVersion
) {
useCommonDependency(
"io.github.pdvrieze.xmlutil:serialization:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
fun Project.yamlKt(
version: String = KScienceVersions.Serialization.yamlKtVersion
) {
useCommonDependency(
"net.mamoe.yamlkt:yamlkt:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
public fun Project.yamlKt(
version: String = KScienceVersions.Serialization.yamlKtVersion,
): Unit = useCommonDependency(
"net.mamoe.yamlkt:yamlkt:$version",
dependencySourceSet = sourceSet,
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.plugin.LanguageSettingsBuilder
internal fun LanguageSettingsBuilder.applySettings(): Unit {
internal fun LanguageSettingsBuilder.applySettings() {
languageVersion = "1.5"
apiVersion = "1.5"
progressiveMode = true
@ -23,7 +23,7 @@ internal fun LanguageSettingsBuilder.applySettings(): Unit {
useExperimentalAnnotation("kotlin.js.ExperimentalJsExport")
}
internal fun RepositoryHandler.applyRepos(): Unit {
internal fun RepositoryHandler.applyRepos() {
mavenCentral()
maven("https://repo.kotlin.link")
}
@ -50,8 +50,7 @@ internal fun Copy.fromJsDependencies(configurationName: String) = project.run {
}
}
fun KotlinMultiplatformExtension.bundleJsBinaryAsResource(bundleName: String = "js/bundle.js"){
internal fun KotlinMultiplatformExtension.bundleJsBinaryAsResource(bundleName: String = "js/bundle.js"){
js {
binaries.executable()
browser {

View File

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

View File

@ -2,6 +2,7 @@ package ru.mipt.npm.gradle.internal
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.findByType
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
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.FXPlatform
val defaultPlatform: FXPlatform = when {
internal val defaultPlatform: FXPlatform = when {
Os.isFamily(Os.FAMILY_WINDOWS) -> FXPlatform.WINDOWS
Os.isFamily(Os.FAMILY_MAC) -> FXPlatform.MAC
Os.isFamily(Os.FAMILY_UNIX) -> FXPlatform.LINUX
@ -58,4 +59,4 @@ internal fun Project.useFx(
}
}
}
}
}

View File

@ -2,10 +2,12 @@ package ru.mipt.npm.gradle.internal
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPom
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.*
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.KotlinJvmProjectExtension
@ -16,27 +18,27 @@ private fun Project.requestProperty(propertyName: String): String = requestPrope
?: error("Property $propertyName not defined")
internal fun Project.setupPublication(vcs: String) = allprojects {
internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit = {}) = allprojects {
plugins.withId("maven-publish") {
configure<PublishingExtension> {
plugins.withId("org.jetbrains.kotlin.js") {
val kotlin: KotlinJsProjectExtension = extensions.findByType()!!
val sourcesJar: Jar by tasks.creating(Jar::class) {
val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources")
kotlin.sourceSets.forEach{
from(it.kotlin)
kotlin.sourceSets.all {
from(kotlin)
}
}
afterEvaluate {
publications {
create("js", MavenPublication::class) {
kotlin.js().components.forEach {
from(it)
}
artifact(sourcesJar)
publications.create<MavenPublication>("js") {
kotlin.js().components.forEach {
from(it)
}
artifact(sourcesJar)
}
}
}
@ -44,24 +46,23 @@ internal fun Project.setupPublication(vcs: String) = allprojects {
plugins.withId("org.jetbrains.kotlin.jvm") {
val kotlin = extensions.findByType<KotlinJvmProjectExtension>()!!
val sourcesJar: Jar by tasks.creating(Jar::class) {
val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources")
kotlin.sourceSets.forEach{
kotlin.sourceSets.forEach {
from(it.kotlin)
}
}
publications {
create("jvm", MavenPublication::class) {
kotlin.target.components.forEach {
from(it)
}
artifact(sourcesJar)
publications.create<MavenPublication>("jvm") {
kotlin.target.components.forEach {
from(it)
}
artifact(sourcesJar)
}
}
val dokkaJar: Jar by tasks.creating(Jar::class) {
val dokkaJar by tasks.creating(Jar::class) {
group = "documentation"
archiveClassifier.set("javadoc")
from(tasks.findByName("dokkaHtml"))
@ -69,35 +70,35 @@ internal fun Project.setupPublication(vcs: String) = allprojects {
// Process each publication we have in this project
afterEvaluate {
publications.withType<MavenPublication>().forEach { publication ->
publication.artifact(dokkaJar)
publication.pom {
publications.withType<MavenPublication> {
artifact(dokkaJar)
pom {
name.set(project.name)
description.set(project.description ?: project.name)
url.set(vcs)
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("MIPT-NPM")
name.set("MIPT nuclear physics methods laboratory")
organization.set("MIPT")
organizationUrl.set("http://npm.mipt.ru")
organizationUrl.set("https://npm.mipt.ru")
}
}
scm {
url.set(vcs)
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
get() {
@ -137,14 +138,14 @@ internal fun Project.addGithubPublishing(
plugins.withId("maven-publish") {
configure<PublishingExtension> {
logger.info("Adding github publishing to project [${project.name}]")
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/$githubOrg/$githubProject/")
credentials {
username = githubUser
password = githubToken
}
repositories.maven {
name = "github"
url = uri("https://maven.pkg.github.com/$githubOrg/$githubProject/")
credentials {
username = githubUser
password = githubToken
}
}
}
@ -157,6 +158,7 @@ internal fun Project.addSpacePublishing(spaceRepo: String) {
logger.info("Skipping github publishing because publishing is disabled")
return
}
if (requestPropertyOrNull("publishing.space") == "false") {
logger.info("Skipping space publishing because `publishing.space == false`")
return
@ -169,15 +171,14 @@ internal fun Project.addSpacePublishing(spaceRepo: String) {
plugins.withId("maven-publish") {
configure<PublishingExtension> {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories {
maven {
name = "space"
url = uri(spaceRepo)
credentials {
username = spaceUser
password = spaceToken
}
repositories.maven {
name = "space"
url = uri(spaceRepo)
credentials {
username = spaceUser
password = spaceToken
}
}
}
@ -186,14 +187,16 @@ internal fun Project.addSpacePublishing(spaceRepo: String) {
}
internal fun Project.addSonatypePublishing() {
if(requestPropertyOrNull("publishing.enabled")!="true"){
if (requestPropertyOrNull("publishing.enabled") != "true") {
logger.info("Skipping github publishing because publishing is disabled")
return
}
if (isSnapshot()) {
logger.info("Sonatype publishing skipped for dev version")
return
}
if (requestPropertyOrNull("publishing.sonatype") == "false") {
logger.info("Skipping sonatype publishing because `publishing.sonatype == false`")
return
@ -206,40 +209,33 @@ internal fun Project.addSonatypePublishing() {
allprojects {
plugins.withId("maven-publish") {
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) {
plugins.apply("signing")
if (!plugins.hasPlugin("signing") ) {
apply<SigningPlugin>()
}
extensions.configure<SigningExtension>("signing") {
if (!signingId.isNullOrBlank()) {
val signingKey: String = requestProperty("publishing.signing.key")
val signingPassphrase: String = requestProperty("publishing.signing.passPhrase")
//if key is provided, use it
@Suppress("UnstableApiUsage")
// if key is provided, use it
useInMemoryPgpKeys(signingId, signingKey, signingPassphrase)
} // else use file signing
sign(publications)
}
repositories {
maven {
name = "sonatype"
url = uri(sonatypeRepo)
credentials {
username = sonatypeUser
password = sonatypePassword
}
repositories.maven {
name = "sonatype"
url = uri(sonatypeRepo)
credentials {
username = sonatypeUser
password = sonatypePassword
}
}
}
}
}
}
//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