diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..c58c404 --- /dev/null +++ b/CONTRIBUTING.md @@ -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=… +``` \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 672050a..b74105e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { @@ -24,3 +29,28 @@ allprojects { task("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) + } + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index ead76b1..c164c31 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -28,6 +28,7 @@ dependencies { implementation(libs.depsVersionGP) implementation(libs.dokkaGP) implementation(libs.ktlintGP) + implementation(libs.nexusPublishGP) } tasks.withType { diff --git a/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/BaseExtensionConfig.kt b/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/BaseExtensionConfig.kt index 357c1cb..6f79c43 100644 --- a/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/BaseExtensionConfig.kt +++ b/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/BaseExtensionConfig.kt @@ -5,8 +5,8 @@ import org.gradle.kotlin.dsl.findByType inline fun Project.extensionConfig( crossinline configure: T.() -> Unit -) { - +): T? { val ext: T? = extensions.findByType(T::class) ext?.configure() + return ext } diff --git a/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/CommonConfig.kt b/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/CommonConfig.kt index 41e2306..07369fd 100644 --- a/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/CommonConfig.kt +++ b/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/CommonConfig.kt @@ -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) } diff --git a/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/DokkaConfig.kt b/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/DokkaConfig.kt index 7d0ad56..3dad8dd 100644 --- a/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/DokkaConfig.kt +++ b/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/DokkaConfig.kt @@ -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) { diff --git a/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/MavenConfig.kt b/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/MavenConfig.kt index 8fd0d62..d22187c 100644 --- a/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/MavenConfig.kt +++ b/buildSrc/src/main/kotlin/fr/xgouchet/buildsrc/settings/MavenConfig.kt @@ -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 { +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 { 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 { +// val privateKey =project.properties["ossrhUsername"]?.toString() +// val password = System.getenv("GPG_PASSWORD") +// useInMemoryPgpKeys(privateKey, password) + sign(publishingExtension.publications.getByName("maven")) } } } \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts index dbe5c6b..018a40e 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -8,6 +8,7 @@ plugins { id("org.jetbrains.dokka") id("githubWiki") `maven-publish` + signing } dependencies { @@ -20,7 +21,7 @@ dependencies { testImplementation(libs.mockitoKotlin) } -commonConfig() +commonConfig("Core Elmyr implementation, providing fuzzy testing and property based testing features.") githubWiki { types = listOf( diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index dfaa86b..8281b4f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } @@ -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] diff --git a/inject/build.gradle.kts b/inject/build.gradle.kts index 89314d5..4f5eb3f 100644 --- a/inject/build.gradle.kts +++ b/inject/build.gradle.kts @@ -7,6 +7,7 @@ plugins { id("org.jlleitschuh.gradle.ktlint") id("org.jetbrains.dokka") `maven-publish` + signing } dependencies { @@ -24,4 +25,4 @@ dependencies { testImplementation(libs.mockitoJunit5) } -commonConfig() +commonConfig("Injection tool for Elmyr.") diff --git a/junit4/build.gradle.kts b/junit4/build.gradle.kts index ffadd69..24dd521 100644 --- a/junit4/build.gradle.kts +++ b/junit4/build.gradle.kts @@ -8,6 +8,7 @@ plugins { id("org.jetbrains.dokka") id("githubWiki") `maven-publish` + signing } dependencies { @@ -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" ) } diff --git a/junit5/build.gradle.kts b/junit5/build.gradle.kts index 417cddb..aa788db 100644 --- a/junit5/build.gradle.kts +++ b/junit5/build.gradle.kts @@ -8,6 +8,7 @@ plugins { id("org.jetbrains.dokka") id("githubWiki") `maven-publish` + signing } dependencies { @@ -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( diff --git a/jvm/build.gradle.kts b/jvm/build.gradle.kts index dc13c4a..84a3fe2 100644 --- a/jvm/build.gradle.kts +++ b/jvm/build.gradle.kts @@ -7,6 +7,7 @@ plugins { id("org.jlleitschuh.gradle.ktlint") id("org.jetbrains.dokka") `maven-publish` + signing } dependencies { @@ -22,4 +23,4 @@ dependencies { testImplementation(libs.mockitoKotlin) } -commonConfig() +commonConfig("JVM standard classes factories for Elmyr, providing fuzzy testing and property based testing features.") diff --git a/semantics/build.gradle.kts b/semantics/build.gradle.kts index dc13c4a..f71b6f5 100644 --- a/semantics/build.gradle.kts +++ b/semantics/build.gradle.kts @@ -7,6 +7,7 @@ plugins { id("org.jlleitschuh.gradle.ktlint") id("org.jetbrains.dokka") `maven-publish` + signing } dependencies { @@ -22,4 +23,4 @@ dependencies { testImplementation(libs.mockitoKotlin) } -commonConfig() +commonConfig("Semantic generation for Elmyr.") diff --git a/spek/build.gradle.kts b/spek/build.gradle.kts index d743615..7f5c9e8 100644 --- a/spek/build.gradle.kts +++ b/spek/build.gradle.kts @@ -8,6 +8,7 @@ plugins { id("org.jetbrains.dokka") id("githubWiki") `maven-publish` + signing } dependencies { @@ -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(