-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/build-plugin' into 'main'
Feature/build plugin See merge request kotlin/kotlin-notebook-js!3
- Loading branch information
Showing
8 changed files
with
233 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,43 @@ | ||
[versions] | ||
kotlin = "1.9.20" | ||
kotlin = "1.9.21" | ||
jupyter = "0.12.0-91" | ||
ksp = "1.9.20-1.0.14" | ||
ksp = "1.9.21-1.0.15" | ||
ktlint = "11.6.1" | ||
dokka = "1.8.20" | ||
publisher = "1.8.10-dev-43" | ||
|
||
[libraries] | ||
# gradle plugins | ||
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref ="kotlin"} | ||
kotlin-publish-plugin = { module = "org.jetbrains.kotlin:kotlin-libs-publisher", version = "1.8.10-dev-43" } | ||
|
||
plugin-kotlinJvm = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } | ||
kotlin_jvm_plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } | ||
plugin-jupyter = { module = "org.jetbrains.kotlin:kotlin-jupyter-api-gradle-plugin", version.ref = "jupyter" } | ||
|
||
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } | ||
ksp_api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } | ||
|
||
dokka-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version = "1.8.20"} | ||
ktlint-plugin = { module = "org.jlleitschuh.gradle:ktlint-gradle", version = "11.6.1" } | ||
dokka_plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version = "1.8.20"} | ||
ktlint_plugin = { module = "org.jlleitschuh.gradle:ktlint-gradle", version = "11.6.1" } | ||
kotlin_serialization_json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.6.0"} | ||
slf4j_api = { module = "org.slf4j:slf4j-api", version = "2.0.9"} | ||
swc_binding = { module = "dev.yidafu.swc:swc-binding", version = "0.3.2" } | ||
|
||
[bundles] | ||
allGradlePlugins = [ | ||
"plugin-kotlinJvm", | ||
"plugin-jupyter", | ||
"kotlin_jvm_plugin", | ||
# "plugin-jupyter", | ||
"kotlin-publish-plugin", | ||
"dokka-plugin", | ||
"ktlint-plugin", | ||
] | ||
|
||
[plugins] | ||
jvm = { id= "org.jetbrains.kotlin.jvm", version.ref = "kotlin"} | ||
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } | ||
jupyter = { id = "org.jetbrains.kotlin.jupyter.api", version.ref = "jupyter" } | ||
publisher = { id = "org.jetbrains.kotlin.libs.publisher", version.ref= "publisher"} | ||
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka"} | ||
ktlint = {id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint"} | ||
kotlin_serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } | ||
signing = { id = "org.gradle.signing" } | ||
mavenPublish = { id = "org.gradle.maven-publish"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,25 +2,150 @@ package dev.yidafu.plugin | |
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.VersionCatalogsExtension | ||
import org.gradle.api.publish.PublishingExtension | ||
import org.gradle.api.publish.maven.MavenPublication | ||
import org.gradle.api.publish.maven.tasks.GenerateMavenPom | ||
import org.gradle.jvm.tasks.Jar | ||
import org.gradle.kotlin.dsl.* | ||
import org.gradle.plugin.use.PluginDependency | ||
import org.gradle.plugins.signing.SigningExtension | ||
import org.jetbrains.dokka.gradle.DokkaTask | ||
import java.net.URI | ||
|
||
fun Project.getLibPlugin(name: String): PluginDependency { | ||
val catalogs = extensions.findByType<VersionCatalogsExtension>() | ||
val plugin = catalogs!!.find("libs").get().findPlugin(name) | ||
return plugin.get().get() | ||
} | ||
|
||
/** | ||
* plugin for library | ||
*/ | ||
class LibraryPlugin : Plugin<Project> { | ||
companion object { | ||
const val PUBLICATION_NAME = "sonatype" | ||
} | ||
|
||
/** | ||
* Apply this plugin to the given target object. | ||
* | ||
* @param project The target object | ||
*/ | ||
override fun apply(project: Project) { | ||
with(project.plugins) { | ||
apply("org.jetbrains.kotlin.jvm") | ||
apply("com.google.devtools.ksp") | ||
println("apply plugin jupyter api") | ||
apply("org.jetbrains.kotlin.jupyter.api") | ||
apply("org.jetbrains.kotlin.libs.publisher") | ||
apply("org.jetbrains.dokka") | ||
apply("org.jlleitschuh.gradle.ktlint") | ||
listOf( | ||
"jvm", | ||
"dokka", | ||
"signing", | ||
"mavenPublish", | ||
"ktlint", | ||
) | ||
.map { project.getLibPlugin(it) } | ||
.forEach { | ||
apply(it.pluginId) | ||
} | ||
} | ||
project.extensions.create("publishMan", PublishManExtension::class) | ||
|
||
val dokkaJavadoc = project.tasks.findByName("dokkaJavadoc") as DokkaTask | ||
val dokkaJavadocJar = project.tasks.register<Jar>("dokkaJavadocJar") { | ||
dependsOn(dokkaJavadoc.path) | ||
from(dokkaJavadoc.outputDirectory) | ||
archiveClassifier.set("javadoc") | ||
} | ||
val kotlinSourcesJar = project.tasks.findByName("kotlinSourcesJar") as Jar | ||
|
||
val publishing = project.extensions.getByType<PublishingExtension>() | ||
publishing.repositories { | ||
maven { | ||
url = URI("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") | ||
// 这里就是之前在issues.sonatype.org注册的账号 | ||
credentials { | ||
username = project.extra.get("sonatypeUsername") as String | ||
password = project.extra.get("sonatypePassword") as String | ||
} | ||
} | ||
} | ||
|
||
publishing.publications { | ||
create<MavenPublication>(PUBLICATION_NAME) { | ||
pom { | ||
// artifactId = "jupyter-js" | ||
from(project.components["java"]) | ||
artifact(kotlinSourcesJar) | ||
artifact(dokkaJavadocJar) | ||
|
||
versionMapping { | ||
usage("java-api") { | ||
fromResolutionOf("runtimeClasspath") | ||
} | ||
usage("java-runtime") { | ||
fromResolutionResult() | ||
} | ||
} | ||
|
||
url.set("https://github.com/yidafu/kotlin-jupyter-js/") | ||
// properties.set(mapOf( | ||
// "myProp" to "value", | ||
// "prop.with.dots" to "anotherValue" | ||
// )) | ||
|
||
licenses { | ||
license { | ||
name.set("The Apache License, Version 2.0") | ||
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") | ||
} | ||
} | ||
developers { | ||
developer { | ||
id.set("dovyih") | ||
name.set("Dov Yih") | ||
email.set("[email protected]") | ||
} | ||
} | ||
scm { | ||
connection.set("scm:git:git://github.com:yidafu/kotlin-jupyter-js.git") | ||
developerConnection.set("scm:git:ssh://github.com:yidafu/kotlin-jupyter-js.git") | ||
url.set("https://github.com:yidafu/kotlin-jupyter-js/") | ||
} | ||
} | ||
// pom.withXml { | ||
// val configurationNames = arrayOf("implementation", "api") | ||
// val deps = configurationNames.map { configurationName -> | ||
// project.configurations[configurationName].allDependencies.toList() | ||
// }.flatten() | ||
// if (deps.isNotEmpty()) { | ||
// val dependenciesNode = asNode().appendNode("dependencies") | ||
// deps.forEach { | ||
// if (it.group != null) { | ||
// val dependencyNode = dependenciesNode.appendNode("dependency") | ||
// dependencyNode.appendNode("groupId", it.group) | ||
// dependencyNode.appendNode("artifactId", it.name) | ||
// dependencyNode.appendNode("version", it.version) | ||
// } | ||
// } | ||
// } | ||
// } | ||
} | ||
} | ||
|
||
val signing = project.extensions.findByType<SigningExtension>() | ||
signing?.sign(publishing.publications[PUBLICATION_NAME]) | ||
project.tasks.withType<GenerateMavenPom> { | ||
doFirst { | ||
val publishMan = this.project.extensions.findByType<PublishManExtension>() | ||
this.project.extensions.findByType(PublishingExtension::class)?.let { ext -> | ||
println("pom name ${publishMan?.name?.getOrElse("")}") | ||
ext.publications { | ||
val publication = findByName(PUBLICATION_NAME) as MavenPublication | ||
publication.pom { | ||
name.set(publishMan?.name?.getOrElse("")) | ||
description.set(publishMan?.description?.getOrElse("")) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
build-plugin/src/main/kotlin/dev/yidafu/plugin/PublishManExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dev.yidafu.plugin | ||
|
||
import org.gradle.api.provider.Property | ||
|
||
interface PublishManExtension { | ||
val name: Property<String> | ||
val description: Property<String> | ||
// val publisher: Property<String> | ||
// val publisherEmail: Property<String> | ||
// val withDependencies: Property<Boolean> | ||
} |
26 changes: 26 additions & 0 deletions
26
build-plugin/src/main/kotlin/dev/yidafu/plugin/VersionExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dev.yidafu.plugin | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.VersionCatalog | ||
import org.gradle.api.artifacts.VersionCatalogsExtension | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.gradle.plugin.use.PluginDependency | ||
|
||
class VersionExtension(private val project: Project, private val catalogName: String) { | ||
private val catalog by lazy { | ||
val catalogs = project.extensions.getByType<VersionCatalogsExtension>() | ||
catalogs.named(catalogName) | ||
} | ||
|
||
fun getVersion(name: String): Provider<PluginDependency> { | ||
return catalog.findPlugin(name).get() | ||
} | ||
} | ||
|
||
fun Project.getVersion(name: String): Provider<PluginDependency> { | ||
val catalogs = project.extensions.getByType<VersionExtension>() | ||
return catalogs.getVersion(name) | ||
} | ||
|
||
//val Project.defaultVersionCatalog = versionC |
Oops, something went wrong.