New publishing mechanics. Kotlin to 1.3.70

This commit is contained in:
Alexander Nozik 2020-03-14 14:42:11 +03:00
parent 50020082a8
commit 9e8b21d327
10 changed files with 207 additions and 119 deletions

View File

@ -7,7 +7,7 @@ plugins {
} }
group = "scientifik" group = "scientifik"
version = "0.4.0" version = "0.4.0-dev"
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()

Binary file not shown.

View File

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

3
gradlew.bat vendored
View File

@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

View File

@ -5,4 +5,10 @@ object Scientifik {
const val coroutinesVersion = "1.3.4" const val coroutinesVersion = "1.3.4"
const val serializationVersion = "0.20.0" const val serializationVersion = "0.20.0"
const val JVM_VERSION = "11" const val JVM_VERSION = "11"
object Serialization{
const val xmlVersion = "0.20.0.0"
const val yamlVersion = "0.16.1"
const val bsonVersion = "0.2.1"
}
} }

View File

@ -2,11 +2,11 @@ package scientifik
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.tasks.Copy import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
import java.io.File
open class ScientifikJSPlugin : Plugin<Project> { open class ScientifikJSPlugin : Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
@ -18,7 +18,14 @@ open class ScientifikJSPlugin : Plugin<Project> {
configure<KotlinJsProjectExtension> { configure<KotlinJsProjectExtension> {
target { target {
browser() browser {
webpackTask {
outputFileName = "main.bundle.js"
}
distribution {
directory = project.jsDistDirectory
}
}
} }
sourceSets["main"].apply { sourceSets["main"].apply {
languageSettings.applySettings() languageSettings.applySettings()
@ -37,31 +44,18 @@ open class ScientifikJSPlugin : Plugin<Project> {
} }
tasks.apply { tasks.apply {
val browserWebpack by getting(KotlinWebpack::class) {
afterEvaluate {
val destination = listOf(name, version.toString()).joinToString("-")
destinationDirectory = destinationDirectory?.resolve(destination)
}
outputFileName = "main.bundle.js"
}
val browserDistribution by getting {
val installJsDist by creating(Copy::class) { doLast {
group = "distribution" val indexFile = project.jsDistDirectory.resolve("index.html")
dependsOn(browserWebpack) if (indexFile.exists()) {
from(fileTree("src/main/web")) println("Run JS distribution at: ${indexFile.canonicalPath}")
afterEvaluate {
into(browserWebpack.destinationDirectory!!)
doLast {
val indexFile = File(browserWebpack.destinationDirectory!!, "index.html")
if (indexFile.exists()) {
println("Run JS distribution at: ${indexFile.canonicalPath}")
}
} }
} }
group = "distribution"
} }
findByName("assemble")?.dependsOn(installJsDist) // findByName("assemble")?.dependsOn(installJsDist)
} }
} }

View File

@ -6,13 +6,10 @@ import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.publish.PublishingExtension import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.* import org.gradle.kotlin.dsl.*
import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
import java.io.File
open class ScientifikMPPlugin : Plugin<Project> { open class ScientifikMPPlugin : Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
@ -23,6 +20,7 @@ open class ScientifikMPPlugin : Plugin<Project> {
repositories.applyRepos() repositories.applyRepos()
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {
jvm { jvm {
compilations.all { compilations.all {
kotlinOptions { kotlinOptions {
@ -32,10 +30,16 @@ open class ScientifikMPPlugin : Plugin<Project> {
} }
js { js {
browser {} browser {
webpackTask {
outputFileName = "main.bundle.js"
}
distribution {
directory = project.jsDistDirectory
}
}
} }
sourceSets.invoke { sourceSets.invoke {
val commonMain by getting { val commonMain by getting {
dependencies { dependencies {
@ -108,42 +112,31 @@ open class ScientifikMPPlugin : Plugin<Project> {
} }
} }
} }
}
tasks.apply {
val jsBrowserWebpack by getting(KotlinWebpack::class) {
afterEvaluate {
val destination = listOf(name, "js", version.toString()).joinToString("-")
destinationDirectory = destinationDirectory?.resolve(destination)
}
outputFileName = "main.bundle.js"
}
tasks.apply {
val installJsDist by creating(Copy::class) { val jsBrowserDistribution by getting {
group = "distribution"
dependsOn(jsBrowserWebpack)
from(project.fileTree("src/jsMain/web"))
afterEvaluate {
into(jsBrowserWebpack.destinationDirectory!!)
doLast { doLast {
val indexFile = File(jsBrowserWebpack.destinationDirectory!!, "index.html") val indexFile = project.jsDistDirectory.resolve("index.html")
if (indexFile.exists()) { if (indexFile.exists()) {
println("Run JS distribution at: ${indexFile.canonicalPath}") println("Run JS distribution at: ${indexFile.canonicalPath}")
} }
} }
group = "distribution"
} }
}
findByName("assemble")?.dependsOn(installJsDist) // findByName("assemble")?.dependsOn(installJsDist)
// withType<Test>(){ // withType<Test>(){
// useJUnitPlatform() // useJUnitPlatform()
// } // }
// }
}
} }
} }
} }
} }

View File

@ -4,10 +4,8 @@ import org.gradle.api.Plugin
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.MavenPublication import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType import org.gradle.kotlin.dsl.withType
@ -30,7 +28,6 @@ open class ScientifikPublishPlugin : Plugin<Project> {
project.configure<PublishingExtension> { project.configure<PublishingExtension> {
// Process each publication we have in this project // Process each publication we have in this project
publications.withType<MavenPublication>().forEach { publication -> publications.withType<MavenPublication>().forEach { publication ->
@Suppress("UnstableApiUsage") @Suppress("UnstableApiUsage")
publication.pom { publication.pom {
name.set(project.name) name.set(project.name)
@ -55,6 +52,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
} }
scm { scm {
url.set(vcs) url.set(vcs)
tag.set(project.version.toString())
} }
} }
} }
@ -65,7 +63,7 @@ open class ScientifikPublishPlugin : Plugin<Project> {
if (githubProject != null && githubUser != null && githubToken != null) { if (githubProject != null && githubUser != null && githubToken != null) {
project.logger.info("Adding github publishing to project [${project.name}]") project.logger.info("Adding github publishing to project [${project.name}]")
repositories { repositories {
val githubMavenRepository = maven { maven {
name = "github" name = "github"
url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/") url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/")
credentials { credentials {
@ -74,60 +72,39 @@ open class ScientifikPublishPlugin : Plugin<Project> {
} }
} }
val githubPublishTasks = publications.filterIsInstance<MavenPublication>().map { publication ->
tasks.register<PublishToMavenRepository>("publish${publication.name.capitalize()}ToGithub") {
group = "publishing"
this.publication = publication
this.repository = githubMavenRepository
}
}
tasks.register<PublishToMavenRepository>("publishToGithub") {
group = "publishing"
dependsOn(githubPublishTasks)
}
} }
} }
val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm"
val bintrayUser = project.findProperty("bintrayUser") as? String
val bintrayKey = project.findProperty("bintrayApiKey") as? String
val bintrayRepo = if (project.version.toString().contains("dev")) { val bintrayRepo = if (project.version.toString().contains("dev")) {
"dev" "dev"
} else { } else {
findProperty("bintrayRepo") as? String findProperty("bintrayRepo") as? String
} }
val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm" val projectName = project.name
val bintrayUser = project.findProperty("bintrayUser") as? String
val bintrayKey = project.findProperty("bintrayApiKey") as? String
if (bintrayRepo != null && bintrayUser != null && bintrayKey != null) { if (bintrayRepo != null && bintrayUser != null && bintrayKey != null) {
project.logger.info("Adding bintray publishing to project [${project.name}]") project.logger.info("Adding bintray publishing to project [$projectName]")
repositories { repositories {
val bintrayMavenRepository = maven { maven {
name = "bintray" name = "bintray"
uri("https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/${project.name}/;publish=0;override=1") url = uri(
"https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=0;override=1"
)
credentials { credentials {
this.username = bintrayUser username = bintrayUser
this.password = bintrayKey password = bintrayKey
} }
} }
val bintrayPublishTasks = publications.withType<MavenPublication>().map { publication ->
tasks.register<PublishToMavenRepository>("publish${publication.name.capitalize()}ToBintray") {
group = "publishing"
this.publication = publication
this.repository = bintrayMavenRepository
}
}
tasks.register<PublishToMavenRepository>("publishToBintray") {
group = "publishing"
dependsOn(bintrayPublishTasks)
}
} }
} }
} }
} }

View File

@ -1,8 +1,10 @@
package scientifik package scientifik
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.RepositoryHandler import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.kotlin.dsl.maven import org.gradle.kotlin.dsl.maven
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
import java.io.File
internal fun LanguageSettingsBuilder.applySettings(): Unit { internal fun LanguageSettingsBuilder.applySettings(): Unit {
progressiveMode = true progressiveMode = true
@ -13,7 +15,7 @@ internal fun LanguageSettingsBuilder.applySettings(): Unit {
useExperimentalAnnotation("kotlin.time.ExperimentalTime") useExperimentalAnnotation("kotlin.time.ExperimentalTime")
} }
internal fun RepositoryHandler.applyRepos(): Unit{ internal fun RepositoryHandler.applyRepos(): Unit {
mavenCentral() mavenCentral()
jcenter() jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap") maven("https://dl.bintray.com/kotlin/kotlin-eap")
@ -23,3 +25,16 @@ internal fun RepositoryHandler.applyRepos(): Unit{
maven("https://kotlin.bintray.com/kotlin-js-wrappers/") maven("https://kotlin.bintray.com/kotlin-js-wrappers/")
maven("https://dl.bintray.com/mipt-npm/dataforge") maven("https://dl.bintray.com/mipt-npm/dataforge")
} }
val Project.jsDistDirectory: File
get() {
val distributionName = listOf(
name,
"js",
version.toString()
).joinToString("-")
return buildDir.resolve(
"distributions/$distributionName}"
)
}

View File

@ -7,62 +7,162 @@ import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.invoke import org.gradle.kotlin.dsl.invoke
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
internal fun Project.useDependency(vararg pairs: Pair<String, String>) { enum class DependencyConfiguration {
API,
IMPLEMENTATION
}
enum class DependencySourceSet(val setName: String, val suffix: String) {
MAIN("main", "Main"),
TEST("test", "Test")
}
internal fun Project.useDependency(
vararg pairs: Pair<String, String>,
dependencySourceSet: DependencySourceSet = DependencySourceSet.MAIN,
dependencyConfiguration: DependencyConfiguration = DependencyConfiguration.API
) {
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
extensions.findByType<KotlinMultiplatformExtension>()?.apply { extensions.findByType<KotlinMultiplatformExtension>()?.apply {
sourceSets { sourceSets {
pairs.forEach { (name, dep)-> pairs.forEach { (target, dep) ->
val name = target + dependencySourceSet.suffix
findByName(name)?.apply { findByName(name)?.apply {
dependencies { dependencies {
implementation(dep) when (dependencyConfiguration) {
DependencyConfiguration.API -> api(dep)
DependencyConfiguration.IMPLEMENTATION -> implementation(dep)
}
} }
} }
} }
} }
} }
} }
pairs.find { it.first == "jvmMain" }?.let { dep ->
pairs.find { it.first == "jvm" }?.let { dep ->
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
sourceSets.findByName("main")?.apply { sourceSets.findByName(dependencySourceSet.setName)?.apply {
dependencies.apply{ dependencies.apply {
add(implementationConfigurationName, dep.second) val configurationName = when (dependencyConfiguration) {
} DependencyConfiguration.API -> apiConfigurationName
DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName
}
add(configurationName, dep.second)
}
} }
} }
} }
pairs.find { it.first == "jsMain" }?.let { dep -> pairs.find { it.first == "js" }?.let { dep ->
pluginManager.withPlugin("org.jetbrains.kotlin.js") { pluginManager.withPlugin("org.jetbrains.kotlin.js") {
sourceSets.findByName("main")?.apply { sourceSets.findByName(dependencySourceSet.setName)?.apply {
sourceSets.findByName("main")?.apply { dependencies.apply {
dependencies.apply{ val configurationName = when (dependencyConfiguration) {
add(implementationConfigurationName, dep.second) DependencyConfiguration.API -> apiConfigurationName
DependencyConfiguration.IMPLEMENTATION -> implementationConfigurationName
} }
add(configurationName, dep.second)
} }
} }
} }
} }
} }
class SerializationTargets(
val sourceSet: DependencySourceSet,
val configuration: DependencyConfiguration
) {
fun Project.cbor(
version: String = Scientifik.serializationVersion
) {
useDependency(
"common" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-common:$version",
"jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$version",
"js" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-js:$version",
"native" to "org.jetbrains.kotlinx:kotlinx-serialization-cbor-native:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
fun Project.useSerialization(version: String = Scientifik.serializationVersion) { fun Project.protobuf(
plugins.apply("org.jetbrains.kotlin.plugin.serialization") version: String = Scientifik.serializationVersion
useDependency( ) {
"commonMain" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$version", useDependency(
"jvmMain" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$version", "common" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-common:$version",
"jsMain" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$version", "jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$version",
"nativeMain" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$version" "js" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-js:$version",
) "native" to "org.jetbrains.kotlinx:kotlinx-serialization-protobuf-native:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
fun Project.xml(
version: String = Scientifik.Serialization.xmlVersion
) {
useDependency(
"common" to "net.devrieze:xmlutil:$version",
"jvm" to "net.devrieze:xmlutil:$version",
"js" to "net.devrieze:xmlutil:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
fun Project.yaml(
version: String = Scientifik.Serialization.yamlVersion
) {
useDependency(
"jvm" to "com.charleskorn.kaml:kaml:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
fun Project.bson(
version: String = Scientifik.Serialization.bsonVersion
) {
useDependency(
"jvm" to "com.github.jershell:kbson:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
)
}
} }
fun Project.useCoroutines(version: String = Scientifik.coroutinesVersion) = useDependency( fun Project.serialization(
"commonMain" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$version", version: String = Scientifik.serializationVersion,
"jvmMain" to "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version", sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
"jsMain" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$version", configuration: DependencyConfiguration = DependencyConfiguration.API,
"nativeMain" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$version" block: SerializationTargets.() -> Unit = {}
) {
plugins.apply("org.jetbrains.kotlin.plugin.serialization")
useDependency(
"common" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$version",
"jvm" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$version",
"js" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$version",
"native" to "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$version",
dependencySourceSet = sourceSet
)
SerializationTargets(sourceSet, configuration).apply(block)
}
fun Project.coroutines(
version: String = Scientifik.coroutinesVersion,
sourceSet: DependencySourceSet = DependencySourceSet.MAIN,
configuration: DependencyConfiguration = DependencyConfiguration.API
) = useDependency(
"common" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$version",
"jvm" to "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version",
"js" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$version",
"native" to "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$version",
dependencySourceSet = sourceSet,
dependencyConfiguration = configuration
) )
//fun Project.useAtomic(version: String = Scientifik.atomicfuVersion) { //fun Project.atomic(version: String = Scientifik.atomicfuVersion) {
// plugins.apply("kotlinx-atomicfu") // plugins.apply("kotlinx-atomicfu")
// useDependency( // useDependency(
// "commonMain" to "org.jetbrains.kotlinx:atomicfu-common:$version", // "commonMain" to "org.jetbrains.kotlinx:atomicfu-common:$version",