Skip to content

Commit

Permalink
Merge pull request #5 from cjbooms/abaquero_maven_central_release
Browse files Browse the repository at this point in the history
Issue #3: Publish Lib to maven central
  • Loading branch information
averabaq authored Jun 16, 2020
2 parents 5073fd5 + 60e71ae commit b3398d3
Showing 1 changed file with 100 additions and 3 deletions.
103 changes: 100 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.dokka.gradle.DokkaTask

plugins {
id("org.jetbrains.kotlin.jvm") version "1.3.61" // Apply the Kotlin JVM plugin to add support for Kotlin.
id("org.jmailen.kotlinter") version "2.3.2" // Lint and formatting for Kotlin using ktlint
id("com.github.johnrengelman.shadow") version "4.0.1"
id("org.jetbrains.dokka") version "0.10.1"
id("maven-publish")
id("signing")

`java-library` // For API and implementation separation.
}

val executableName = "fabrikt"

group = "com.cjbooms"
version = "1.0.0.RC1"

val projectUrl = "https://github.com/cjbooms/fabrikt"
val projectScmUrl = "scm:https://[email protected]/cjbooms/fabrikt.git"
val projectScmConUrl = "scm:https://[email protected]/cjbooms/fabrikt.git"
val projectScmDevUrl = "scm:git://github.com/cjbooms/fabrikt.git"
val projectIssueUrl = "https://github.com/cjbooms/fabrikt/issues"
val projectName = "Fabrikt"
val projectDesc = "Fabricates Kotlin code from OpenApi3 specifications"
val projectLicenseName = "Apache License 2.0"
val projectLicenseUrl = "https://opensource.org/licenses/Apache-2.0"

repositories {
jcenter()
Expand Down Expand Up @@ -42,18 +58,38 @@ dependencies {
}

tasks {
val fatJar = getByName<ShadowJar>("shadowJar") {
val shadowJar by getting(ShadowJar::class) {
manifest {
attributes["Main-Class"] = "com.cjbooms.fabrikt.cli.CodeGen"
attributes["Implementation-Title"] = "fabrikt"
attributes["Implementation-Version"] = project.version
attributes["Built-JDK"] = System.getProperty("java.version")
attributes["Built-Gradle"] = gradle.gradleVersion
}
archiveBaseName.set(executableName)
archiveClassifier.set("")
}

val dokka by getting(DokkaTask::class) {
outputFormat = "html"
outputDirectory = "$buildDir/dokka"
}

val sourcesJar by creating(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.getByName("main").allSource)
}

val kotlinDocJar by creating(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(dokka)
dependsOn(dokka)
}

val printCodeGenUsage by creating(JavaExec::class) {
dependsOn(fatJar)
dependsOn(shadowJar)
classpath = project.files("./build/libs/$executableName.jar")
main = "com.cjbooms.fabrikt.cli.CodeGen"
args = listOf("--help")
Expand All @@ -65,7 +101,68 @@ tasks {
}
dependsOn(formatKotlin)
}

withType<Test> {
useJUnitPlatform()
}
}
}

publishing {
repositories {
maven {
name = "OSSRH"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
credentials {
username = System.getenv("OSSRH_USERNAME")
password = System.getenv("OSSRH_PASSWORD")
}
}
}

publications {
create<MavenPublication>("fabrikt") {
artifact(tasks["shadowJar"])
artifact(tasks["sourcesJar"])
artifact(tasks["kotlinDocJar"])

pom {
name.set(projectName)
description.set(projectDesc)
url.set(projectUrl)
inceptionYear.set("2020")
licenses {
license {
name.set(projectLicenseName)
url.set(projectLicenseUrl)
}
}
developers {
developer {
id.set("cjbooms")
name.set("Conor Gallaguer")
email.set("[email protected]")
}
developer {
id.set("averabaq")
name.set("Alejandro Vera-Baquero")
email.set("[email protected]")
}
}
scm {
connection.set(projectScmConUrl)
developerConnection.set(projectScmDevUrl)
url.set(projectScmUrl)
}

}
}
}
}

signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)

sign(publishing.publications["fabrikt"])
}

0 comments on commit b3398d3

Please sign in to comment.