From aafcb06a1e0bb5c28ee75c66b80b77702035012a Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 23 Aug 2022 16:31:44 +0300 Subject: [PATCH] manual pom config --- CHANGELOG.md | 1 + .../kscience/gradle/KScienceProjectPlugin.kt | 48 +++++++++---------- .../kscience/gradle/internal/publishing.kt | 17 ------- .../kotlin/space/kscience/gradle/pomConfig.kt | 24 ++++++++++ 4 files changed, 47 insertions(+), 43 deletions(-) create mode 100644 src/main/kotlin/space/kscience/gradle/pomConfig.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 53969d4..0f1acf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `-Xjdk-release` key ### Changed +- Require manual pom config for publications - Kotlin 1.7.20-Beta - Versions update - Project group changed to `space.kscience` diff --git a/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt b/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt index dcf0475..a48a27f 100644 --- a/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt +++ b/src/main/kotlin/space/kscience/gradle/KScienceProjectPlugin.kt @@ -4,6 +4,7 @@ import kotlinx.validation.ApiValidationExtension import kotlinx.validation.BinaryCompatibilityValidatorPlugin import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.publish.maven.MavenPom import org.gradle.api.publish.maven.tasks.PublishToMavenRepository import org.gradle.kotlin.dsl.* import org.jetbrains.changelog.ChangelogPlugin @@ -19,18 +20,6 @@ public class KSciencePublishingExtension(public val project: Project) { private var isVcsInitialized = false internal val repositoryNames = mutableSetOf() - @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 (sources) for the publication. * @@ -38,16 +27,23 @@ public class KSciencePublishingExtension(public val project: Project) { * @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) { + public fun pom( + vcsUrl: String, + connectionUrl: String? = null, + developerConnectionUrl: String? = connectionUrl, + connectionPrefix: String = "scm:git:", + pomConfig: MavenPom.() -> Unit, + ) { 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") } + connectionUrl?.let { connection.set("$connectionPrefix$it") } + developerConnectionUrl?.let { developerConnection.set("$connectionPrefix$it") } } + pomConfig() } isVcsInitialized = true @@ -63,13 +59,9 @@ public class KSciencePublishingExtension(public val project: Project) { */ public fun github( githubProject: String, - githubOrg: String = "mipt-npm", + githubOrg: String, addToRelease: Boolean = project.requestPropertyOrNull("publishing.github") == "true", ) { - // Automatically initialize VCS using GitHub - if (!isVcsInitialized) { - git("https://github.com/$githubOrg/${githubProject}", "https://github.com/$githubOrg/${githubProject}.git") - } if (addToRelease) { try { @@ -88,7 +80,7 @@ public class KSciencePublishingExtension(public val project: Project) { * @param addToRelease publish packages in the `release` task to the Space repository. */ public fun space( - spaceRepo: String = "https://maven.pkg.jetbrains.space/mipt-npm/p/sci/maven", + spaceRepo: String, addToRelease: Boolean = project.requestPropertyOrNull("publishing.space") != "false", ) { project.addSpacePublishing(spaceRepo) @@ -142,6 +134,8 @@ public open class KScienceProjectPlugin : Plugin { subprojects { val readmeExtension = KScienceReadmeExtension(this) extensions.add("readme", readmeExtension) + + @Suppress("UNUSED_VARIABLE") val generateReadme by tasks.creating { group = "documentation" description = "Generate a README file if stub is present" @@ -260,15 +254,17 @@ public open class KScienceProjectPlugin : Plugin { val pattern = "publish(?.*)PublicationTo${repositoryNameCapitalized}Repository" .toRegex() - tasks.withType().toList().forEach forEachPublication@ { + tasks.withType().toList().forEach forEachPublication@{ val matchResult = pattern.matchEntire(it.name) ?: return@forEachPublication val publicationName = matchResult.groups["publication"]!!.value.capitalize() val releaseTaskName = "release$publicationName" - val targetReleaseTask = rootProject.tasks.findByName(releaseTaskName) ?: rootProject.tasks.create(releaseTaskName) { - group = RELEASE_GROUP - description = "Publish platform release artifact for $publicationName to all repositories" - } + val targetReleaseTask = + rootProject.tasks.findByName(releaseTaskName) ?: rootProject.tasks.create(releaseTaskName) { + group = RELEASE_GROUP + description = + "Publish platform release artifact for $publicationName to all repositories" + } releaseAll.dependsOn(targetReleaseTask) diff --git a/src/main/kotlin/space/kscience/gradle/internal/publishing.kt b/src/main/kotlin/space/kscience/gradle/internal/publishing.kt index fd45e3c..679bd32 100644 --- a/src/main/kotlin/space/kscience/gradle/internal/publishing.kt +++ b/src/main/kotlin/space/kscience/gradle/internal/publishing.kt @@ -80,23 +80,6 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit name.set(project.name) description.set(project.description ?: project.name) - licenses { - license { - name.set("The Apache Software License, Version 2.0") - 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("https://npm.mipt.ru") - } - } - scm { tag.set(project.version.toString()) } diff --git a/src/main/kotlin/space/kscience/gradle/pomConfig.kt b/src/main/kotlin/space/kscience/gradle/pomConfig.kt new file mode 100644 index 0000000..5cea379 --- /dev/null +++ b/src/main/kotlin/space/kscience/gradle/pomConfig.kt @@ -0,0 +1,24 @@ +package space.kscience.gradle + +import org.gradle.api.publish.maven.MavenPom + +public fun MavenPom.useApache2Licence(){ + licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") + } + } +} + +public fun MavenPom.useSPCTeam(){ + developers { + developer { + id.set("SPC") + name.set("Scientific programming centre") + organization.set("MIPT") + organizationUrl.set("https://sciprog.center/") + } + } +} \ No newline at end of file