Change publishing logic. Adjust to adhere to gradle 8.3 changes.

This commit is contained in:
Alexander Nozik 2023-09-12 21:04:29 +03:00
parent c3bdd8edca
commit 2f5e053aea
5 changed files with 52 additions and 125 deletions

View File

@ -76,12 +76,12 @@ gradlePlugin {
tasks.create("version") {
group = "publishing"
val versionFile = project.buildDir.resolve("project-version.txt")
outputs.file(versionFile)
val versionFileProvider = project.layout.buildDirectory.file("project-version.txt")
outputs.file(versionFileProvider)
doLast {
val versionFile = versionFileProvider.get().asFile
versionFile.createNewFile()
versionFile.writeText(project.version.toString())
println(project.version)
}
}

View File

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

View File

@ -17,10 +17,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWasmTargetDsl
import org.jetbrains.kotlin.gradle.targets.js.dsl.*
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlinx.jupyter.api.plugin.tasks.JupyterApiResourcesTask
@ -108,7 +105,7 @@ public open class KScienceExtension(public val project: Project) {
configure<KotlinMultiplatformExtension> {
sourceSets.findByName("commonMain")?.apply {
dependencies {
api(platform("io.ktor:ktor-bom:$version"))
api(project.dependencies.platform("io.ktor:ktor-bom:$version"))
}
}
}
@ -117,7 +114,7 @@ public open class KScienceExtension(public val project: Project) {
configure<KotlinJvmProjectExtension> {
sourceSets.findByName("main")?.apply {
dependencies {
api(platform("io.ktor:ktor-bom:$version"))
api(project.dependencies.platform("io.ktor:ktor-bom:$version"))
}
}
}
@ -126,7 +123,7 @@ public open class KScienceExtension(public val project: Project) {
configure<KotlinJsProjectExtension> {
sourceSets.findByName("main")?.apply {
dependencies {
api(platform("io.ktor:ktor-bom:$version"))
api(project.dependencies.platform("io.ktor:ktor-bom:$version"))
}
}
}
@ -235,7 +232,7 @@ public open class KScienceExtension(public val project: Project) {
binaries.executable()
}
targets.withType<KotlinWasmTargetDsl> {
targets.withType<KotlinWasmJsTargetDsl> {
binaries.executable()
}
}
@ -265,8 +262,8 @@ public open class KScienceExtension(public val project: Project) {
public val jsTest: DefaultSourceSet get() = DefaultSourceSet("jsTest")
public val nativeMain: DefaultSourceSet get() = DefaultSourceSet("nativeMain")
public val nativeTest: DefaultSourceSet get() = DefaultSourceSet("nativeTest")
public val wasmMain: DefaultSourceSet get() = DefaultSourceSet("wasmMain")
public val wasmTest: DefaultSourceSet get() = DefaultSourceSet("wasmTest")
public val wasmJsMain: DefaultSourceSet get() = DefaultSourceSet("wasmJsMain")
public val wasmJsTest: DefaultSourceSet get() = DefaultSourceSet("wasmJsTest")
}
@ -426,27 +423,27 @@ public open class KScienceMppExtension(project: Project) : KScienceExtension(pro
@OptIn(ExperimentalWasmDsl::class)
public fun wasm(block: KotlinWasmTargetDsl.() -> Unit = {}) {
if (project.requestPropertyOrNull("kscience.wasm.disabled") == "true") {
project.logger.warn("Wasm target is disabled with 'kscience.wasm.disabled' property")
return
}
// if (project.requestPropertyOrNull("kscience.wasm.disabled") == "true") {
// project.logger.warn("Wasm target is disabled with 'kscience.wasm.disabled' property")
// return
// }
project.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
project.configure<KotlinMultiplatformExtension> {
wasm {
wasmJs {
browser {
testTask(Action {
testTask {
useKarma {
this.webpackConfig.experiments.add("topLevelAwait")
useChromeHeadlessWasmGc()
useConfigDirectory(project.projectDir.resolve("karma.config.d").resolve("wasm"))
}
})
}
}
block()
}
sourceSets {
getByName("wasmTest") {
getByName("wasmJsTest") {
dependencies {
implementation(kotlin("test"))
}

View File

@ -15,7 +15,9 @@ import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
import space.kscience.gradle.internal.*
import space.kscience.gradle.internal.addPublishing
import space.kscience.gradle.internal.addSonatypePublishing
import space.kscience.gradle.internal.setupPublication
/**
* Simplifies adding repositories for Maven publishing, responds for releasing tasks for projects.
@ -54,42 +56,20 @@ public class KSciencePublishingExtension(public val project: Project) {
}
/**
* 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 deploy publish packages in the `deploy` task to the GitHub repository.
* Add a repository with [repositoryName]. Uses "publishing.$repositoryName.user" and "publishing.$repositoryName.token"
* properties pattern to store user and token
*/
public fun github(
githubOrg: String,
githubProject: String,
deploy: Boolean = project.requestPropertyOrNull("publishing.github") == "true",
public fun repository(
repositoryName: String,
url: String,
) {
if (deploy) {
try {
project.addGithubPublishing(githubOrg, githubProject)
} catch (t: Throwable) {
project.logger.error("Failed to set up github publication", t)
}
}
}
/**
* Adds Space Packages Maven repository to publishing.
*
* @param spaceRepo the repository URL.
* @param deploy publish packages in the `deploy` task to the Space repository.
*/
public fun space(
spaceRepo: String,
) {
project.addSpacePublishing(spaceRepo)
require(isVcsInitialized) { "The project vcs is not set up use 'pom' method to do so" }
project.addPublishing(repositoryName, url)
}
/**
* Adds Sonatype Maven repository to publishing.
*
* @param addToRelease publish packages in the `release` task to the Sonatype repository.
*/
public fun sonatype(sonatypeRoot: String = "https://s01.oss.sonatype.org") {
require(isVcsInitialized) { "The project vcs is not set up use 'pom' method to do so" }
@ -142,7 +122,7 @@ public open class KScienceProjectPlugin : Plugin<Project> {
val readmeExtension = KScienceReadmeExtension(this)
extensions.add("readme", readmeExtension)
val generateReadme by tasks.creating {
tasks.create("generateReadme") {
group = "documentation"
description = "Generate a README file if stub is present"
@ -236,12 +216,12 @@ public open class KScienceProjectPlugin : Plugin<Project> {
tasks.create("version") {
group = "publishing"
val versionFile = project.buildDir.resolve("project-version.txt")
outputs.file(versionFile)
val versionFileProvider = project.layout.buildDirectory.file("project-version.txt")
outputs.file(versionFileProvider)
doLast {
val versionFile = versionFileProvider.get().asFile
versionFile.createNewFile()
versionFile.writeText(project.version.toString())
println(project.version)
}
}

View File

@ -46,7 +46,7 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
}
publications.create<MavenPublication>("jvm") {
kotlin.target.components.forEach {
project.components.forEach {
from(it)
}
@ -91,7 +91,7 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
val signingKey: String = requestProperty("publishing.signing.key")
val signingPassphrase: String = requestProperty("publishing.signing.passPhrase")
// if key is provided, use it
// if a key is provided, use it
useInMemoryPgpKeys(signingId, signingKey, signingPassphrase)
} // else use agent signing
sign(publications)
@ -103,30 +103,31 @@ internal fun Project.setupPublication(mavenPomConfiguration: MavenPom.() -> Unit
}
}
internal fun Project.addGithubPublishing(
githubOrg: String,
githubProject: String,
) {
val githubUser: String? = requestPropertyOrNull("publishing.github.user")
val githubToken: String? = requestPropertyOrNull("publishing.github.token")
internal fun Project.addPublishing(
repositoryName: String,
urlString:String
){
require(repositoryName.matches("\\w*".toRegex())){"Repository name must contain only letters or numbers"}
val user: String? = requestPropertyOrNull("publishing.$repositoryName.user")
val token: String? = requestPropertyOrNull("publishing.$repositoryName.token")
if (githubUser == null || githubToken == null) {
logger.info("Skipping Github publishing because Github credentials are not defined")
if (user == null || token == null) {
logger.info("Skipping $repositoryName publishing because $repositoryName credentials are not defined")
return
}
allprojects {
plugins.withId("maven-publish") {
configure<PublishingExtension> {
logger.info("Adding Github publishing to project [${project.name}]")
logger.info("Adding $repositoryName publishing to project [${project.name}]")
repositories.maven {
name = "github"
url = uri("https://maven.pkg.github.com/$githubOrg/$githubProject/")
name = repositoryName
url = uri(urlString)
credentials {
username = githubUser
password = githubToken
username = user
password = token
}
}
}
@ -134,62 +135,11 @@ internal fun Project.addGithubPublishing(
}
}
internal fun Project.addSpacePublishing(spaceRepo: String) {
val spaceUser: String? = requestPropertyOrNull("publishing.space.user")
val spaceToken: String? = requestPropertyOrNull("publishing.space.token")
if (spaceUser == null || spaceToken == null) {
logger.info("Skipping Space publishing because Space credentials are not defined")
return
}
allprojects {
plugins.withId("maven-publish") {
configure<PublishingExtension> {
project.logger.info("Adding SPC Space publishing to project [${project.name}]")
repositories.maven {
name = "space"
url = uri(spaceRepo)
credentials {
username = spaceUser
password = spaceToken
}
}
}
}
}
}
internal fun Project.addSonatypePublishing(sonatypeRoot: String) {
if (isInDevelopment) {
logger.info("Sonatype publishing skipped for development version")
return
}
val sonatypeUser: String? = requestPropertyOrNull("publishing.sonatype.user")
val sonatypePassword: String? = requestPropertyOrNull("publishing.sonatype.password")
if (sonatypeUser == null || sonatypePassword == null) {
logger.info("Skipping Sonatype publishing because Sonatype credentials are not defined")
return
}
allprojects {
plugins.withId("maven-publish") {
configure<PublishingExtension> {
repositories.maven {
val sonatypeRepo = "$sonatypeRoot/service/local/staging/deploy/maven2"
name = "sonatype"
url = uri(sonatypeRepo)
credentials {
username = sonatypeUser
password = sonatypePassword
}
}
}
}
} else {
addPublishing("sonatype", "$sonatypeRoot/service/local/staging/deploy/maven2")
}
}