Skip to content

Commit

Permalink
Create signing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
xgouchet committed Sep 27, 2023
1 parent 474cacc commit c5842fe
Show file tree
Hide file tree
Showing 15 changed files with 123 additions and 17 deletions.
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

### Check

You can run all the local checks with the `./gradlew check` task.

- Detekt
- Ktlint
- Unit tests

### Publishing

To be able to publish on Maven Central, you need to create a `local.properties` file
at the root of the project with the following properties:

```
# Maven OSSRH credentials
ossrhUsername=
ossrhPassword=
# GPG Signing key info
signing.keyId=…
signing.secretKeyRingFile=…
signing.password=…
```
30 changes: 30 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import java.io.File
import java.net.URI
import java.util.Properties

plugins {
`maven-publish`
id("io.github.gradle-nexus.publish-plugin")
}

buildscript {
Expand All @@ -24,3 +29,28 @@ allprojects {
task<Delete>("clean") {
delete(rootProject.buildDir)
}

group = "fr.xgouchet.elmyr"
val localPropertiesFile: File = project.rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
val p = Properties()
localPropertiesFile.inputStream().use { fis ->
p.load(fis)
}
p.forEach { k, v ->
project.ext[k.toString()] = v
}
}

nexusPublishing {
this.repositories {
sonatype {
// nexusUrl.set(URI("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"))
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
val sonatypeUsername = project.properties["ossrhUsername"]?.toString()
val sonatypePassword = project.properties["ossrhPassword"]?.toString()
if (sonatypeUsername != null) username.set(sonatypeUsername)
if (sonatypePassword != null) password.set(sonatypePassword)
}
}
}
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
implementation(libs.depsVersionGP)
implementation(libs.dokkaGP)
implementation(libs.ktlintGP)
implementation(libs.nexusPublishGP)
}

tasks.withType<KotlinCompile> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import org.gradle.kotlin.dsl.findByType

inline fun <reified T : Any> Project.extensionConfig(
crossinline configure: T.() -> Unit
) {

): T? {
val ext: T? = extensions.findByType(T::class)
ext?.configure()
return ext
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package fr.xgouchet.buildsrc.settings

import org.gradle.api.Project

fun Project.commonConfig() {
fun Project.commonConfig(projectDescription: String) {
detektConfig()
kotlinConfig()
junitConfig()
ktLintConfig()
dokkaConfig()
mavenConfig()
mavenConfig(projectDescription)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package fr.xgouchet.buildsrc.settings
import org.gradle.api.Project
import org.gradle.jvm.tasks.Jar

@Suppress("UnstableApiUsage")
fun Project.dokkaConfig() {

project.tasks.register("generateJavadoc", Jar::class.java) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,60 @@ import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.get
import org.gradle.plugins.signing.SigningExtension

fun Project.mavenConfig() {
extensionConfig<PublishingExtension> {
const val GROUP_NAME = "fr.xgouchet.elmyr"
const val VERSION = "1.4.0"

fun Project.mavenConfig(projectDescription: String) {

group = GROUP_NAME
version = VERSION

val publishingExtension = extensionConfig<PublishingExtension> {
publications.create("maven", MavenPublication::class.java) {
groupId = "com.github.xgouchet"
groupId = GROUP_NAME
artifactId = project.name
version = "1.4.0"
version = VERSION

from(components["kotlin"])
artifact(tasks.findByName("kotlinSourcesJar"))
artifact(tasks.findByName("generateJavadoc"))

pom {
name.set(project.name)
description.set(projectDescription)
url.set("https://github.com/xgouchet/Elmyr/")

licenses {
license {
name.set("MIT")
url.set("https://opensource.org/license/mit/")
}
}
developers {
developer {
name.set("Xavier F. Gouchet")
email.set("github@xgouchet.fr")
roles.set(listOf("Author", "Maintainer"))
}
}

scm {
url.set("https://github.com/xgouchet/Elmyr/")
connection.set("scm:git:git@github.com:xgouchet/Elmyr.git")
developerConnection.set("scm:git:git@github.com:xgouchet/Elmyr.git")
}
}
}
}

if (publishingExtension != null) {
extensionConfig<SigningExtension> {
// val privateKey =project.properties["ossrhUsername"]?.toString()
// val password = System.getenv("GPG_PASSWORD")
// useInMemoryPgpKeys(privateKey, password)
sign(publishingExtension.publications.getByName("maven"))
}
}
}
3 changes: 2 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
id("org.jetbrains.dokka")
id("githubWiki")
`maven-publish`
signing
}

dependencies {
Expand All @@ -20,7 +21,7 @@ dependencies {
testImplementation(libs.mockitoKotlin)
}

commonConfig()
commonConfig("Core Elmyr implementation, providing fuzzy testing and property based testing features.")

githubWiki {
types = listOf(
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ detekt = "1.19.0"
depsVersion = "0.41.0"
dokka = "1.8.20"
ktlint = "9.1.0"
nexusPublish = "1.1.0"

[libraries]
kotlin = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
Expand All @@ -37,6 +38,7 @@ detektGP = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", versio
depsVersionGP = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "depsVersion" }
dokkaGP = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" }
ktlintGP = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" }
nexusPublishGP = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexusPublish" }

[bundles]

Expand Down
3 changes: 2 additions & 1 deletion inject/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
id("org.jlleitschuh.gradle.ktlint")
id("org.jetbrains.dokka")
`maven-publish`
signing
}

dependencies {
Expand All @@ -24,4 +25,4 @@ dependencies {
testImplementation(libs.mockitoJunit5)
}

commonConfig()
commonConfig("Injection tool for Elmyr.")
5 changes: 3 additions & 2 deletions junit4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
id("org.jetbrains.dokka")
id("githubWiki")
`maven-publish`
signing
}

dependencies {
Expand All @@ -24,10 +25,10 @@ dependencies {
testImplementation(libs.mockitoKotlin)
}

commonConfig()
commonConfig("JUnit 4 integration for Elmyr, providing fuzzy testing and property based testing features.")

githubWiki {
types = listOf(
"fr.xgouchet.elmyr.junit4.ForgeRule"
"fr.xgouchet.elmyr.junit4.ForgeRule"
)
}
3 changes: 2 additions & 1 deletion junit5/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
id("org.jetbrains.dokka")
id("githubWiki")
`maven-publish`
signing
}

dependencies {
Expand All @@ -26,7 +27,7 @@ dependencies {
testImplementation(libs.mockitoKotlin)
}

commonConfig()
commonConfig("JUnit 5 integration for Elmyr, providing fuzzy testing and property based testing features.")

githubWiki {
types = listOf(
Expand Down
3 changes: 2 additions & 1 deletion jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
id("org.jlleitschuh.gradle.ktlint")
id("org.jetbrains.dokka")
`maven-publish`
signing
}

dependencies {
Expand All @@ -22,4 +23,4 @@ dependencies {
testImplementation(libs.mockitoKotlin)
}

commonConfig()
commonConfig("JVM standard classes factories for Elmyr, providing fuzzy testing and property based testing features.")
3 changes: 2 additions & 1 deletion semantics/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
id("org.jlleitschuh.gradle.ktlint")
id("org.jetbrains.dokka")
`maven-publish`
signing
}

dependencies {
Expand All @@ -22,4 +23,4 @@ dependencies {
testImplementation(libs.mockitoKotlin)
}

commonConfig()
commonConfig("Semantic generation for Elmyr.")
3 changes: 2 additions & 1 deletion spek/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
id("org.jetbrains.dokka")
id("githubWiki")
`maven-publish`
signing
}

dependencies {
Expand All @@ -28,7 +29,7 @@ dependencies {
testImplementation(libs.mockitoKotlin)
}

commonConfig()
commonConfig("Spek integration for Elmyr, providing fuzzy testing and property based testing features.")

githubWiki {
types = listOf(
Expand Down

0 comments on commit c5842fe

Please sign in to comment.