Skip to content

Commit

Permalink
publish to maven central support
Browse files Browse the repository at this point in the history
  • Loading branch information
morisil committed Aug 16, 2024
1 parent 2e72e68 commit 7ee2885
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 26 deletions.
80 changes: 56 additions & 24 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@
* see <https://www.gnu.org/licenses/>.
*/

import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
alias(libs.plugins.kotlin.jvm) apply false
`maven-publish`
signing
alias(libs.plugins.versions)
alias(libs.plugins.dokka) apply false
alias(libs.plugins.publish)
}

val githubAccount = "xemantic"

allprojects {
repositories {
mavenCentral()
Expand All @@ -34,7 +40,24 @@ allprojects {

subprojects {

if (project.name.startsWith("xemantic")) {
afterEvaluate {
if (project.name != "demo") {
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
if (project.name != "simple-java") {
tasks.named<KotlinCompilationTask<*>>("compileKotlin").configure {
compilerOptions {
apiVersion.set(KotlinVersion.KOTLIN_2_0)
}
}
}
}
}

if (project.name.startsWith(rootProject.name)) {

apply(plugin = "maven-publish")
apply(plugin = "java-library")
Expand All @@ -58,7 +81,11 @@ subprojects {
)
)
}

metaInf {
from(rootProject.rootDir) {
include("LICENSE")
}
}
}

named<Jar>("javadocJar") {
Expand All @@ -71,28 +98,20 @@ subprojects {
repositories {
maven {
name = "GitHubPackages"
setUrl("https://maven.pkg.github.com/xemantic/xemantic-kotlin-swing-dsl")
setUrl("https://maven.pkg.github.com/$githubAccount/${rootProject.name}")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
// maven {
// name = "OSSRH"
// setUrl("https://s01.oss.sonatype.org/content/repositories/snapshots/")
// credentials {
// username = System.getenv("MAVEN_USERNAME")
// password = System.getenv("MAVEN_PASSWORD")
// }
// }
}
publications {
create<MavenPublication>("maven") {
from(components["kotlin"])
artifact(tasks.named<Jar>("javadocJar"))
pom {
description = "Kotlin goodies for Java Swing"
url = "https://github.com/xemantic/xemantic-kotlin-swing-dsl"
url = "https://github.com/$githubAccount/${rootProject.name}"
inceptionYear = "2020"
organization {
name = "Xemantic"
Expand All @@ -106,15 +125,17 @@ subprojects {
}
}
scm {
url = "https://github.com/xemantic/xemantic-kotlin-swing-dsl"
url = "https://github.com/$githubAccount/${rootProject.name}"
connection = "scm:git:git:github.com/$githubAccount/${rootProject.name}.git"
developerConnection = "scm:git:https://github.com/$githubAccount/${rootProject.name}.git"
}
ciManagement {
system = "GitHub"
url = "https://github.com/xemantic/xemantic-kotlin-swing-dsl/actions"
url = "https://github.com/$githubAccount/${rootProject.name}/actions"
}
issueManagement {
system = "GitHub"
url = "https://github.com/xemantic/xemantic-kotlin-swing-dsl/issues"
url = "https://github.com/$githubAccount/${rootProject.name}/issues"
}
developers {
developer {
Expand All @@ -133,12 +154,23 @@ subprojects {

}

//signing {
// if (
// project.hasProperty("signing.keyId")
// && project.hasProperty("signing.password")
// && project.hasProperty("signing.secretKeyRingFile")
// ) {
// sign(publishing.publications)
// }
//}
signing {
if (
project.hasProperty("signing.keyId")
&& project.hasProperty("signing.password")
&& project.hasProperty("signing.secretKeyRingFile")
) {
sign(publishing.publications["maven"])
}
}

nexusPublishing {
repositories {
sonatype { //only for users registered in Sonatype after 24 Feb 2021
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(System.getenv("SONATYPE_USER"))
password.set(System.getenv("SONATYPE_PASSWORD"))
}
}
}
6 changes: 4 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ kotlinxCoroutines = "1.8.1"
kotest = "5.9.1"

versionsPlugin = "0.51.0"
dokka = "1.9.20"
dokkaPlugin = "1.9.20"
publishPlugin = "2.0.0"

[libraries]
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" }
Expand All @@ -16,4 +17,5 @@ kotest-assertions-core = { group = "io.kotest", name = "kotest-assertions-core",
[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
versions = { id = "com.github.ben-manes.versions", version.ref = "versionsPlugin" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokkaPlugin" }
publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "publishPlugin" }

0 comments on commit 7ee2885

Please sign in to comment.