set up convention plugins

- tidy up build scripts to use convention plugins
- use centralised repo definition
- tidy up some of the build config
This commit is contained in:
Adam 2023-05-31 21:10:57 +02:00
parent 34b69a7d1f
commit 93e113fa69
14 changed files with 498 additions and 141 deletions

View file

@ -1,11 +1,8 @@
import buildsrc.utils.Rife2TestListener
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
plugins {
@ -14,30 +11,20 @@ plugins {
id("io.gitlab.arturbosch.detekt") version "1.22.0"
id("java-library")
id("maven-publish")
id("org.jetbrains.dokka") version "1.7.20"
id("org.jetbrains.kotlin.jvm") version "1.8.0"
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlinx.kover") version "0.6.1"
id("org.sonarqube") version "3.5.0.2730"
id("signing")
buildsrc.conventions.publishing
buildsrc.conventions.sonarqube
}
description = "A simple defensive library to encode/decode URL components"
group = "net.thauvin.erik"
version = "1.3.1-SNAPSHOT"
val mavenName = "UrlEncoder"
val deployDir = "deploy"
val deployDir = project.layout.projectDirectory.dir("deploy")
val gitHub = "ethauvin/${rootProject.name}"
val mavenUrl = "https://github.com/$gitHub"
val publicationName = "mavenJava"
val myClassName = "$group.${rootProject.name}.$mavenName"
repositories {
mavenCentral()
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
}
dependencies {
// testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
@ -57,23 +44,6 @@ application {
mainClass.set(myClassName)
}
sonarqube {
properties {
property("sonar.projectName", rootProject.name)
property("sonar.projectKey", "ethauvin_${rootProject.name}")
property("sonar.organization", "ethauvin-github")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.sourceEncoding", "UTF-8")
property("sonar.coverage.jacoco.xmlReportPaths", "${project.buildDir}/reports/kover/xml/report.xml")
}
}
val javadocJar by tasks.creating(Jar::class) {
dependsOn(tasks.dokkaJavadoc)
from(tasks.dokkaJavadoc)
archiveClassifier.set("javadoc")
}
tasks {
jar {
manifest {
@ -102,58 +72,23 @@ tasks {
}
test {
useJUnitPlatform()
addTestListener(object : TestListener {
override fun beforeTest(p0: TestDescriptor?) = Unit
override fun beforeSuite(p0: TestDescriptor?) = Unit
override fun afterTest(desc: TestDescriptor, result: TestResult) = Unit
override fun afterSuite(desc: TestDescriptor, result: TestResult) {
if (desc.parent == null) {
val passed = result.successfulTestCount
val failed = result.failedTestCount
val skipped = result.skippedTestCount
if (project.properties["testsBadgeApiKey"] != null) {
val apiKey = project.properties["testsBadgeApiKey"]
println(apiKey)
val response: HttpResponse<String> = HttpClient.newHttpClient()
.send(
HttpRequest.newBuilder()
.uri(
URI(
"https://rife2.com/tests-badge/update/net.thauvin.erik/urlencoder?" +
"apiKey=$apiKey&" +
"passed=$passed&" +
"failed=$failed&" +
"skipped=$skipped"
)
)
.POST(HttpRequest.BodyPublishers.noBody())
.build(), HttpResponse.BodyHandlers.ofString()
)
println("RESPONSE: ${response.statusCode()}")
println(response.body())
}
}
}
})
addTestListener(Rife2TestListener(project.properties["testsBadgeApiKey"]?.toString()))
}
withType<Test> {
useJUnitPlatform()
testLogging {
exceptionFormat = TestExceptionFormat.FULL
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
}
}
withType<GenerateMavenPom> {
withType<GenerateMavenPom>().configureEach {
destination = file("$projectDir/pom.xml")
}
clean {
doLast {
project.delete(fileTree(deployDir))
}
delete(deployDir)
}
withType<DokkaTask>().configureEach {
@ -164,7 +99,7 @@ tasks {
}
}
val copyToDeploy by registering(Copy::class) {
val copyToDeploy by registering(Sync::class) {
from(configurations.runtimeClasspath) {
exclude("annotations-*.jar")
}
@ -173,12 +108,11 @@ tasks {
}
register("deploy") {
description = "Copies all needed files to the $deployDir directory."
description = "Copies all needed files to the 'deploy' directory."
group = PublishingPlugin.PUBLISH_TASK_GROUP
dependsOn(clean, build, jar)
dependsOn(build, jar)
outputs.dir(deployDir)
inputs.files(copyToDeploy)
mustRunAfter(clean)
}
"sonar" {
@ -188,58 +122,10 @@ tasks {
publishing {
publications {
create<MavenPublication>(publicationName) {
create<MavenPublication>("mavenJava") {
from(components["java"])
artifactId = rootProject.name
artifact(javadocJar)
pom {
name.set("$mavenName for Kotlin")
description.set(project.description)
url.set(mavenUrl)
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("gbevin")
name.set("Geert Bevin")
email.set("gbevin@uwyn.com")
url.set("https://github.com/gbevin")
}
developer {
id.set("ethauvin")
name.set("Erik C. Thauvin")
email.set("erik@thauvin.net")
url.set("https://erik.thauvin.net/")
}
}
scm {
connection.set("scm:git://github.com/$gitHub.git")
developerConnection.set("scm:git@github.com:$gitHub.git")
url.set(mavenUrl)
}
issueManagement {
system.set("GitHub")
url.set("$mavenUrl/issues")
}
}
}
}
repositories {
maven {
name = "ossrh"
url = if (project.version.toString().contains("SNAPSHOT"))
uri("https://oss.sonatype.org/content/repositories/snapshots/") else
uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials(PasswordCredentials::class)
artifactId = "${rootProject.name}-lib"
artifact(tasks.javadocJar)
}
}
}
signing {
useGpgCmd()
sign(publishing.publications[publicationName])
}