Version 0.8.0

This commit is contained in:
Alexander Nozik 2021-02-21 16:06:25 +03:00
parent 7a2d5c40f1
commit ab259a5fb6
5 changed files with 231 additions and 222 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Ktor version to versions
- Add sonatype publishing
- Per-platform release publishing
### Changed
- Kotlin to 1.4.30 stable.

View File

@ -55,7 +55,7 @@ project.extensions.findByType<GradlePluginDevelopmentExtension>()?.apply{
create("publishing") {
id = "ru.mipt.npm.gradle.publish"
description = "The publication plugin for bintray and github"
implementationClass = "ru.mipt.npm.gradle.KSciencePublishingPlugin"
implementationClass = "ru.mipt.npm.gradle.KSciencePublishPlugin"
}
create("mpp") {

View File

@ -56,11 +56,11 @@ open class KScienceProjectPlugin : Plugin<Project> {
group = "documentation"
description = "Generate a README file if stub is present"
if(readmeExtension.readmeTemplate.exists()) {
if (readmeExtension.readmeTemplate.exists()) {
inputs.file(readmeExtension.readmeTemplate)
}
readmeExtension.additionalFiles.forEach {
if(it.exists()){
if (it.exists()) {
inputs.file(it)
}
}
@ -75,7 +75,7 @@ open class KScienceProjectPlugin : Plugin<Project> {
}
}
}
tasks.withType<DokkaTask>{
tasks.withType<DokkaTask> {
dependsOn(generateReadme)
}
}
@ -90,11 +90,11 @@ open class KScienceProjectPlugin : Plugin<Project> {
}
}
if(rootReadmeExtension.readmeTemplate.exists()) {
if (rootReadmeExtension.readmeTemplate.exists()) {
inputs.file(rootReadmeExtension.readmeTemplate)
}
rootReadmeExtension.additionalFiles.forEach {
if(it.exists()){
if (it.exists()) {
inputs.file(it)
}
}
@ -117,7 +117,7 @@ open class KScienceProjectPlugin : Plugin<Project> {
appendln("> ${ext.description}")
appendln(">\n> **Maturity**: ${ext.maturity}")
val featureString = ext.featuresString(itemPrefix = "> - ", pathPrefix = "$name/")
if(featureString.isNotBlank()) {
if (featureString.isNotBlank()) {
appendln(">\n> **Features:**")
appendln(featureString)
}
@ -142,30 +142,38 @@ open class KScienceProjectPlugin : Plugin<Project> {
}
}
tasks.withType<DokkaTask>{
tasks.withType<DokkaTask> {
dependsOn(generateReadme)
}
val patchChangelog by tasks.getting
val release by tasks.creating{
afterEvaluate {
afterEvaluate {
val release by tasks.creating {
group = RELEASE_GROUP
description = "Publish development or production release based on version suffix"
dependsOn(generateReadme)
tasks.findByName("publishAllPublicationsToSonatypeRepository")?.let {
val publicationPlatform = project.findProperty("ci.publication.platform") as? String
val publicationName = if(publicationPlatform == null){
"AllPublications"
} else {
publicationPlatform.capitalize() + "Publication"
}
tasks.findByName("publish${publicationName}ToSonatypeRepository")?.let {
dependsOn(it)
}
tasks.findByName("publishAllPublicationsToBintrayRepository")?.let {
tasks.findByName("publish${publicationName}ToBintrayRepository")?.let {
dependsOn(it)
}
tasks.findByName("publishAllPublicationsToSpaceRepository")?.let {
tasks.findByName("publish${publicationName}ToSpaceRepository")?.let {
dependsOn(it)
}
}
}
}
companion object{
companion object {
const val RELEASE_GROUP = "release"
}
}

View File

@ -0,0 +1,208 @@
package ru.mipt.npm.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.SigningExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
private fun Project.isSnapshot() = version.toString().contains("dev") || version.toString().endsWith("SNAPSHOT")
open class KSciencePublishingPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.afterEvaluate {
if (plugins.findPlugin("maven-publish") == null) {
plugins.apply("maven-publish")
}
val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm"
val githubProject: String? by project
val vcs = findProperty("vcs") as? String
?: githubProject?.let { "https://github.com/$githubOrg/$it" }
configure<PublishingExtension> {
plugins.withId("org.jetbrains.kotlin.js") {
val kotlin = extensions.findByType<KotlinJsProjectExtension>()!!
val sourcesJar: Jar by project.tasks.creating(Jar::class) {
archiveClassifier.set("sources")
from(kotlin.sourceSets["main"].kotlin)
}
publications {
create("js", MavenPublication::class) {
from(components["kotlin"])
artifact(sourcesJar)
}
}
}
plugins.withId("org.jetbrains.kotlin.jvm") {
val kotlin = extensions.findByType<KotlinJvmProjectExtension>()!!
val sourcesJar: Jar by project.tasks.creating(Jar::class) {
archiveClassifier.set("sources")
from(kotlin.sourceSets["main"].kotlin)
}
publications {
create("jvm", MavenPublication::class) {
from(components["kotlin"])
artifact(sourcesJar)
}
}
}
val dokkaJar: Jar by tasks.creating(Jar::class) {
group = "documentation"
archiveClassifier.set("javadoc")
from(tasks.findByName("dokkaHtml"))
}
// Process each publication we have in this project
publications.withType<MavenPublication>().forEach { publication ->
publication.artifact(dokkaJar)
publication.pom {
name.set(project.name)
description.set(project.description ?: project.name)
vcs?.let { 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")
}
}
vcs?.let {
scm {
url.set(vcs)
tag.set(project.version.toString())
//developerConnection = "scm:git:[fetch=]/*ВАША ССЫЛКА НА .git файл*/[push=]/*Повторить предыдущую ссылку*/"
}
}
}
}
val githubUser: String? by project
val githubToken: String? by project
if (githubProject != null && githubUser != null && githubToken != null) {
project.logger.info("Adding github publishing to project [${project.name}]")
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/")
credentials {
username = githubUser
password = githubToken
}
}
}
}
val spaceRepo: String? by project
val spaceUser: String? by project
val spaceToken: String? by project
if (spaceRepo != null && spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories {
maven {
name = "space"
url = uri(spaceRepo!!)
credentials {
username = spaceUser
password = spaceToken
}
}
}
}
val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm"
val bintrayUser: String? by project
val bintrayApiKey: String? by project
val bintrayPublish: String? by project
val bintrayRepo = if (isSnapshot()) {
"dev"
} else {
findProperty("bintrayRepo") as? String
}
val projectName = project.name
if (bintrayPublish == "true" && bintrayRepo != null && bintrayUser != null && bintrayApiKey != null) {
project.logger.info("Adding bintray publishing to project [$projectName]")
repositories {
maven {
name = "bintray"
url = uri(
"https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=1;override=1"
)
credentials {
username = bintrayUser
password = bintrayApiKey
}
}
}
}
val sonatypePublish: String? by project
val sonatypeUser: String? by project
val sonatypePassword: String? by project
val keyId: String? by project
val signingKey: String? = project.findProperty("signingKey") as? String ?: System.getenv("signingKey")
val signingKeyPassphrase: String? by project
if (sonatypePublish == "true" && sonatypeUser != null && sonatypePassword != null) {
val sonatypeRepo: String = if (isSnapshot()) {
"https://oss.sonatype.org/content/repositories/snapshots"
} else {
"https://oss.sonatype.org/service/local/staging/deploy/maven2"
}
if (plugins.findPlugin("signing") == null) {
plugins.apply("signing")
}
extensions.configure<SigningExtension>("signing") {
if (!signingKey.isNullOrBlank()) {
//if key is provided, use it
@Suppress("UnstableApiUsage")
useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase)
} // else use file signing
sign(publications)
}
repositories {
maven {
name = "sonatype"
url = uri(sonatypeRepo)
credentials {
username = sonatypeUser
password = sonatypePassword
}
}
}
}
}
}
}

View File

@ -1,208 +0,0 @@
package ru.mipt.npm.gradle
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.SigningExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
open class KSciencePublishingPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.plugins.withId("ru.mipt.npm.common") {
project.afterEvaluate {
if (plugins.findPlugin("maven-publish") == null) {
plugins.apply("maven-publish")
}
val githubOrg: String = project.findProperty("githubOrg") as? String ?: "mipt-npm"
val githubProject: String? by project
val vcs = findProperty("vcs") as? String
?: githubProject?.let { "https://github.com/$githubOrg/$it" }
project.configure<PublishingExtension> {
plugins.withId("org.jetbrains.kotlin.js") {
val kotlin = extensions.findByType<KotlinJsProjectExtension>()!!
val sourcesJar: Jar by project.tasks.creating(Jar::class) {
archiveClassifier.set("sources")
from(kotlin.sourceSets["main"].kotlin)
}
publications {
create("js", MavenPublication::class) {
from(components["kotlin"])
artifact(sourcesJar)
}
}
}
plugins.withId("org.jetbrains.kotlin.jvm") {
val kotlin = extensions.findByType<KotlinJvmProjectExtension>()!!
val sourcesJar: Jar by project.tasks.creating(Jar::class) {
archiveClassifier.set("sources")
from(kotlin.sourceSets["main"].kotlin)
}
publications {
create("jvm", MavenPublication::class) {
from(components["kotlin"])
artifact(sourcesJar)
}
}
}
val dokkaJar: Jar by tasks.creating(Jar::class) {
group = "documentation"
archiveClassifier.set("javadoc")
from(tasks.findByName("dokkaHtml"))
}
// Process each publication we have in this project
publications.withType<MavenPublication>().forEach { publication ->
publication.artifact(dokkaJar)
publication.pom {
name.set(project.name)
description.set(project.description ?: project.name)
vcs?.let { 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")
}
}
vcs?.let {
scm {
url.set(vcs)
tag.set(project.version.toString())
//developerConnection = "scm:git:[fetch=]/*ВАША ССЫЛКА НА .git файл*/[push=]/*Повторить предыдущую ссылку*/"
}
}
}
}
val githubUser: String? by project
val githubToken: String? by project
if (githubProject != null && githubUser != null && githubToken != null) {
project.logger.info("Adding github publishing to project [${project.name}]")
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/mipt-npm/$githubProject/")
credentials {
username = githubUser
password = githubToken
}
}
}
}
val spaceRepo: String? by project
val spaceUser: String? by project
val spaceToken: String? by project
if (spaceRepo != null && spaceUser != null && spaceToken != null) {
project.logger.info("Adding mipt-npm Space publishing to project [${project.name}]")
repositories {
maven {
name = "space"
url = uri(spaceRepo!!)
credentials {
username = spaceUser
password = spaceToken
}
}
}
}
val bintrayOrg = project.findProperty("bintrayOrg") as? String ?: "mipt-npm"
val bintrayUser: String? by project
val bintrayApiKey: String? by project
val bintrayPublish: Boolean? by project
val bintrayRepo = if (project.version.toString().contains("dev")) {
"dev"
} else {
findProperty("bintrayRepo") as? String
}
val projectName = project.name
if (bintrayPublish == true && bintrayRepo != null && bintrayUser != null && bintrayApiKey != null) {
project.logger.info("Adding bintray publishing to project [$projectName]")
repositories {
maven {
name = "bintray"
url = uri(
"https://api.bintray.com/maven/$bintrayOrg/$bintrayRepo/$projectName/;publish=1;override=1"
)
credentials {
username = bintrayUser
password = bintrayApiKey
}
}
}
}
val sonatypePublish: Boolean? by project
val sonatypeUser: String? by project
val sonatypePassword: String? by project
val keyId: String? by project
val signingKey: String? = project.findProperty("signingKey") as? String ?: System.getenv("signingKey")
val signingKeyPassphrase: String? by project
if (sonatypePublish == true && sonatypeUser != null && sonatypePassword != null) {
val sonatypeRepo: String = if (project.version.toString().contains("dev")) {
"https://oss.sonatype.org/content/repositories/snapshots"
} else {
"https://oss.sonatype.org/service/local/staging/deploy/maven2"
}
if (plugins.findPlugin("signing") == null) {
plugins.apply("signing")
}
extensions.configure<SigningExtension>("signing") {
if (!signingKey.isNullOrBlank()) {
//if key is provided, use it
@Suppress("UnstableApiUsage")
useInMemoryPgpKeys(keyId, signingKey, signingKeyPassphrase)
} // else use file signing
sign(publications)
}
repositories {
maven {
name = "sonatype"
url = uri(sonatypeRepo)
credentials {
username = sonatypeUser
password = sonatypePassword
}
}
}
}
}
}
}
}