diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a12013 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +out/ +build/ +.idea/ +.gradle \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..d43c267 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,113 @@ +import java.util.* + +plugins { + `kotlin-dsl` + `maven-publish` +// id("com.gradle.plugin-publish") version "0.10.1" + id("com.jfrog.bintray") version "1.8.4" +} + +group = "scientifik" +version = "0.1.0" + +repositories { + gradlePluginPortal() + jcenter() +} + +val kotlinVersion = "1.3.40" + +// Add plugins used in buildSrc as dependencies, also we should specify version only here +dependencies { + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") + implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.9.6") + implementation("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4") + implementation("org.jetbrains.dokka:dokka-gradle-plugin:0.9.18") + implementation("com.moowork.gradle:gradle-node-plugin:1.3.1") + implementation("org.openjfx:javafx-plugin:0.0.7") +} + +gradlePlugin { + plugins { + create("scientifik-publish") { + id = "scientifik.publish" + description = "The publication plugin for bintray and artifactory" + implementationClass = "scientifik.ScientifikPublishPlugin" + } + create("scientifik-mpp") { + id = "scientifik.mpp" + description = "Pre-configured multiplatform project" + implementationClass = "scientifik.ScientifikMPPlugin" + } + } +} + +publishing { + repositories { + maven("https://bintray.com/mipt-npm/scientifik") + } + + val vcs = "https://github.com/mipt-npm/scientifik-gradle-tools" + + // Process each publication we have in this project + publications.filterIsInstance().forEach { publication -> + + @Suppress("UnstableApiUsage") + publication.pom { + name.set(project.name) + description.set(project.description) + 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") + 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") + } + + } + scm { + url.set(vcs) + } + } + } + + bintray { + user = project.findProperty("bintrayUser") as? String ?: System.getenv("BINTRAY_USER") + key = project.findProperty("bintrayApiKey") as? String? ?: System.getenv("BINTRAY_API_KEY") + publish = true + override = true // for multi-platform Kotlin/Native publishing + + // We have to use delegateClosureOf because bintray supports only dynamic groovy syntax + // this is a problem of this plugin + pkg.apply { + userOrg = "mipt-npm" + repo = "scientifik" + name = project.name + issueTrackerUrl = "$vcs/issues" + setLicenses("Apache-2.0") + vcsUrl = vcs + version.apply { + name = project.version.toString() + vcsTag = project.version.toString() + released = Date().toString() + } + } + + //workaround bintray bug + project.afterEvaluate { + setPublications(*project.extensions.findByType()!!.publications.names.toTypedArray()) + } + + } +} + + diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..bc059c6 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'gradle-tools' + diff --git a/src/main/kotlin/Scientifik.kt b/src/main/kotlin/Scientifik.kt new file mode 100644 index 0000000..617b2e6 --- /dev/null +++ b/src/main/kotlin/Scientifik.kt @@ -0,0 +1,9 @@ +/** + * Build constants + */ +object Scientifik { + val ioVersion = "0.1.10" + val coroutinesVersion = "1.2.2" + val atomicfuVersion = "0.12.9" + val serializationVersion = "0.11.1" +} diff --git a/src/main/kotlin/scientifik/ScientifikExtension.kt b/src/main/kotlin/scientifik/ScientifikExtension.kt new file mode 100644 index 0000000..0aebd20 --- /dev/null +++ b/src/main/kotlin/scientifik/ScientifikExtension.kt @@ -0,0 +1,7 @@ +package scientifik + +open class ScientifikExtension { + var vcs: String? = null + var bintrayRepo: String? = null + var kdoc: Boolean = true +} \ No newline at end of file diff --git a/src/main/kotlin/scientifik/ScientifikMPPlugin.kt b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt new file mode 100644 index 0000000..3aa195d --- /dev/null +++ b/src/main/kotlin/scientifik/ScientifikMPPlugin.kt @@ -0,0 +1,81 @@ +package scientifik + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.getValue +import org.gradle.kotlin.dsl.getting +import org.gradle.kotlin.dsl.invoke +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension + +open class ScientifikMPPlugin : Plugin { + override fun apply(project: Project) { + project.plugins.apply("org.jetbrains.kotlin.multiplatform") + + project.configure { + jvm { + compilations.all { + kotlinOptions { + jvmTarget = "1.8" + } + } + } + + js { + compilations.all { + kotlinOptions { + sourceMap = true + sourceMapEmbedSources = "always" + moduleKind = "umd" + } + } + } + + sourceSets.invoke { + val commonMain by getting { + dependencies { + api(kotlin("stdlib")) + } + } + val commonTest by getting { + dependencies { + implementation(kotlin("test-common")) + implementation(kotlin("test-annotations-common")) + } + } + val jvmMain by getting { + dependencies { + api(kotlin("stdlib-jdk8")) + } + } + val jvmTest by getting { + dependencies { + implementation(kotlin("test")) + implementation(kotlin("test-junit")) + } + } + val jsMain by getting { + dependencies { + api(kotlin("stdlib-js")) + } + } + val jsTest by getting { + dependencies { + implementation(kotlin("test-js")) + } + } + } + + targets.all { + sourceSets.all { + languageSettings.apply{ + progressiveMode = true + enableLanguageFeature("InlineClasses") + useExperimentalAnnotation("ExperimentalUnsignedType") + } + } + } + } + + } +} \ No newline at end of file diff --git a/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt b/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt new file mode 100644 index 0000000..328f2e1 --- /dev/null +++ b/src/main/kotlin/scientifik/ScientifikPublishPlugin.kt @@ -0,0 +1,233 @@ +package scientifik + +import com.jfrog.bintray.gradle.BintrayExtension +import com.jfrog.bintray.gradle.tasks.BintrayUploadTask +import groovy.lang.GroovyObject +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.JavaBasePlugin +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact +import org.gradle.api.tasks.bundling.Jar +import org.gradle.kotlin.dsl.* +import org.jetbrains.dokka.gradle.DokkaTask +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention +import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig +import org.jfrog.gradle.plugin.artifactory.dsl.ResolverConfig +import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask + + +// recursively search up the project chain for configuration +private val Project.bintrayRepo: String? + get() = extensions.findByType()?.bintrayRepo + ?: parent?.bintrayRepo + ?: (findProperty("bintrayRepo") as? String) + +private val Project.vcs: String? + get() = extensions.findByType()?.vcs + ?: parent?.vcs + ?: (findProperty("vcs") as? String) + +open class ScientifikPublishPlugin : Plugin { + + override fun apply(project: Project) { + + project.plugins.apply("maven-publish") + val extension = project.extensions.create("scientifik") + + val bintrayRepo = project.bintrayRepo + val vcs = project.vcs + + if (bintrayRepo == null || vcs == null) { + project.logger.warn("[${project.name}] Missing deployment configuration. Skipping publish.") + } + + project.configure { + repositories { + maven("https://bintray.com/mipt-npm/$bintrayRepo") + } + + // Process each publication we have in this project + publications.filterIsInstance().forEach { publication -> + + @Suppress("UnstableApiUsage") + publication.pom { + name.set(project.name) + description.set(project.description) + 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") + 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") + } + + } + scm { + url.set(vcs) + } + } + } + } + + if (extension.kdoc) { + project.plugins.apply("org.jetbrains.dokka") + + project.afterEvaluate { + extensions.findByType()?.apply { + val dokka by tasks.getting(DokkaTask::class) { + outputFormat = "html" + outputDirectory = "$buildDir/javadoc" + jdkVersion = 8 + + kotlinTasks { + // dokka fails to retrieve sources from MPP-tasks so we only define the jvm task + listOf(tasks.getByPath("compileKotlinJvm")) + } + sourceRoot { + // assuming only single source dir + path = sourceSets["commonMain"].kotlin.srcDirs.first().toString() + platforms = listOf("Common") + } + // although the JVM sources are now taken from the task, + // we still define the jvm source root to get the JVM marker in the generated html + sourceRoot { + // assuming only single source dir + path = sourceSets["jvmMain"].kotlin.srcDirs.first().toString() + platforms = listOf("JVM") + } + + } + + val kdocJar by tasks.registering(Jar::class) { + group = JavaBasePlugin.DOCUMENTATION_GROUP + dependsOn(dokka) + archiveClassifier.set("javadoc") + from("$buildDir/javadoc") + } + + configure { + + targets.all { + val publication = publications.findByName(name) as MavenPublication + + // Patch publications with fake javadoc + publication.artifact(kdocJar.get()) + } + + tasks.filter { it is ArtifactoryTask || it is BintrayUploadTask }.forEach { + it.doFirst { + publications.filterIsInstance() + .forEach { publication -> + val moduleFile = + buildDir.resolve("publications/${publication.name}/module.json") + if (moduleFile.exists()) { + publication.artifact(object : FileBasedMavenArtifact(moduleFile) { + override fun getDefaultExtension() = "module" + }) + } + } + } + } + } + } + + + extensions.findByType()?.apply { + val dokka by tasks.getting(DokkaTask::class) { + outputFormat = "html" + outputDirectory = "$buildDir/javadoc" + jdkVersion = 8 + } + + val kdocJar by tasks.registering(Jar::class) { + group = JavaBasePlugin.DOCUMENTATION_GROUP + dependsOn(dokka) + archiveClassifier.set("javadoc") + from("$buildDir/javadoc") + } + + configure { + publications.filterIsInstance().forEach { publication -> + publication.artifact(kdocJar.get()) + } + } + } + } + } + + project.plugins.apply("com.jfrog.bintray") + + project.configure { + user = project.findProperty("bintrayUser") as? String ?: System.getenv("BINTRAY_USER") + key = project.findProperty("bintrayApiKey") as? String? ?: System.getenv("BINTRAY_API_KEY") + publish = true + override = true // for multi-platform Kotlin/Native publishing + + // We have to use delegateClosureOf because bintray supports only dynamic groovy syntax + // this is a problem of this plugin + pkg.apply { + userOrg = "mipt-npm" + repo = bintrayRepo + name = project.name + issueTrackerUrl = "${vcs}/issues" + setLicenses("Apache-2.0") + vcsUrl = vcs + version.apply { + name = project.version.toString() + vcsTag = project.version.toString() + released = java.util.Date().toString() + } + } + + //workaround bintray bug + project.afterEvaluate { + setPublications(*project.extensions.findByType()!!.publications.names.toTypedArray()) + } + +// project.tasks.figetByPath("bintrayUpload") { +// dependsOn(publishToMavenLocal) +// } + } + + project.plugins.apply("com.jfrog.artifactory") + + project.configure { + val artifactoryUser: String? by project + val artifactoryPassword: String? by project + val artifactoryContextUrl = "http://npm.mipt.ru:8081/artifactory" + + setContextUrl(artifactoryContextUrl)//The base Artifactory URL if not overridden by the publisher/resolver + publish(delegateClosureOf { + repository(delegateClosureOf { + setProperty("repoKey", "gradle-dev-local") + setProperty("username", artifactoryUser) + setProperty("password", artifactoryPassword) + }) + + defaults(delegateClosureOf { + invokeMethod("publications", arrayOf("jvm", "js", "kotlinMultiplatform", "metadata")) + }) + }) + resolve(delegateClosureOf { + repository(delegateClosureOf { + setProperty("repoKey", "gradle-dev") + setProperty("username", artifactoryUser) + setProperty("password", artifactoryPassword) + }) + }) + } + } +} \ No newline at end of file