tweaks and fixes
- introduce kotlin-jvm convention - tidy up code-quality build config
This commit is contained in:
parent
b8a394c9ad
commit
6670346890
5 changed files with 119 additions and 89 deletions
|
@ -1,18 +1,31 @@
|
|||
package buildsrc.conventions
|
||||
|
||||
import buildsrc.utils.Rife2TestListener
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||
|
||||
/** common config for all subprojects */
|
||||
|
||||
plugins {
|
||||
base
|
||||
base
|
||||
}
|
||||
|
||||
if (project != rootProject) {
|
||||
project.version = rootProject.version
|
||||
project.group = rootProject.group
|
||||
project.version = rootProject.version
|
||||
project.group = rootProject.group
|
||||
}
|
||||
|
||||
tasks.withType<AbstractArchiveTask>().configureEach {
|
||||
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
|
||||
isPreserveFileTimestamps = false
|
||||
isReproducibleFileOrder = true
|
||||
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
|
||||
isPreserveFileTimestamps = false
|
||||
isReproducibleFileOrder = true
|
||||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
val testsBadgeApiKey = providers.gradleProperty("testsBadgeApiKey")
|
||||
addTestListener(Rife2TestListener(testsBadgeApiKey))
|
||||
testLogging {
|
||||
exceptionFormat = TestExceptionFormat.FULL
|
||||
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,17 +17,25 @@
|
|||
|
||||
package buildsrc.conventions
|
||||
|
||||
import org.sonarqube.gradle.SonarTask
|
||||
|
||||
plugins {
|
||||
id("org.sonarqube")
|
||||
id("org.sonarqube")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
id("org.jetbrains.kotlinx.kover")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
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/report.xml")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<SonarTask>().configureEach {
|
||||
dependsOn(tasks.matching { it.name == "koverXmlReport" })
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package buildsrc.conventions.lang
|
||||
|
||||
import buildsrc.utils.Rife2TestListener
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.sonarqube.gradle.SonarTask
|
||||
|
||||
/**
|
||||
* Common configuration for Kotlin/JVM projects
|
||||
*
|
||||
* (this can be removed after Kotlin Multiplatform migration)
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("buildsrc.conventions.base")
|
||||
kotlin("jvm")
|
||||
id("buildsrc.conventions.code-quality")
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(11)
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
compilerOptions {
|
||||
jvmTarget.set(JvmTarget.JVM_11)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
useJUnitPlatform()
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
package buildsrc.utils
|
||||
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.testing.TestDescriptor
|
||||
import org.gradle.api.tasks.testing.TestListener
|
||||
import org.gradle.api.tasks.testing.TestResult
|
||||
|
@ -26,37 +27,39 @@ import java.net.http.HttpRequest
|
|||
import java.net.http.HttpResponse
|
||||
|
||||
class Rife2TestListener(
|
||||
private val testBadgeApiKey: String?
|
||||
private val testBadgeApiKey: Provider<String>
|
||||
) : 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
|
||||
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 (testBadgeApiKey != null) {
|
||||
println(testBadgeApiKey)
|
||||
val response: HttpResponse<String> = HttpClient.newHttpClient()
|
||||
.send(
|
||||
HttpRequest.newBuilder()
|
||||
.uri(
|
||||
URI(
|
||||
"https://rife2.com/tests-badge/update/net.thauvin.erik/urlencoder?" +
|
||||
"apiKey=$testBadgeApiKey&" +
|
||||
"passed=$passed&" +
|
||||
"failed=$failed&" +
|
||||
"skipped=$skipped"
|
||||
)
|
||||
)
|
||||
.POST(HttpRequest.BodyPublishers.noBody())
|
||||
.build(), HttpResponse.BodyHandlers.ofString()
|
||||
)
|
||||
println("RESPONSE: ${response.statusCode()}")
|
||||
println(response.body())
|
||||
}
|
||||
val apiKey = testBadgeApiKey.orNull
|
||||
|
||||
if (apiKey != null) {
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,17 @@
|
|||
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
|
||||
|
||||
|
||||
plugins {
|
||||
buildsrc.conventions.lang.`kotlin-jvm`
|
||||
buildsrc.conventions.publishing
|
||||
id("application")
|
||||
id("com.github.ben-manes.versions")
|
||||
id("io.gitlab.arturbosch.detekt")
|
||||
id("java-library")
|
||||
id("maven-publish")
|
||||
id("org.jetbrains.kotlin.jvm")
|
||||
id("org.jetbrains.kotlinx.kover")
|
||||
|
||||
buildsrc.conventions.publishing
|
||||
buildsrc.conventions.sonarqube
|
||||
}
|
||||
|
||||
description = "A simple defensive library to encode/decode URL components"
|
||||
|
||||
val deployDir = project.layout.projectDirectory.dir("deploy")
|
||||
val mainClassName = "net.thauvin.erik.urlencoder.UrlEncoder"
|
||||
val urlEncoderMainClass = "net.thauvin.erik.urlencoder.UrlEncoder"
|
||||
|
||||
dependencies {
|
||||
// testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
|
||||
|
@ -32,20 +22,14 @@ base {
|
|||
archivesName.set(rootProject.name)
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set(mainClassName)
|
||||
mainClass.set(urlEncoderMainClass)
|
||||
}
|
||||
|
||||
tasks {
|
||||
jar {
|
||||
manifest {
|
||||
attributes["Main-Class"] = mainClassName
|
||||
attributes["Main-Class"] = urlEncoderMainClass
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,30 +49,10 @@ tasks {
|
|||
dependsOn(fatJar)
|
||||
}
|
||||
|
||||
withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions.jvmTarget = java.targetCompatibility.toString()
|
||||
}
|
||||
|
||||
test {
|
||||
addTestListener(Rife2TestListener(project.properties["testsBadgeApiKey"]?.toString()))
|
||||
}
|
||||
|
||||
withType<Test>().configureEach {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
exceptionFormat = TestExceptionFormat.FULL
|
||||
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
|
||||
}
|
||||
}
|
||||
|
||||
withType<GenerateMavenPom>().configureEach {
|
||||
destination = file("$projectDir/pom.xml")
|
||||
}
|
||||
|
||||
clean {
|
||||
delete(deployDir)
|
||||
}
|
||||
|
||||
withType<DokkaTask>().configureEach {
|
||||
dokkaSourceSets {
|
||||
named("main") {
|
||||
|
@ -113,8 +77,8 @@ tasks {
|
|||
dependsOn(build, copyToDeploy)
|
||||
}
|
||||
|
||||
"sonar" {
|
||||
dependsOn(koverReport)
|
||||
clean {
|
||||
delete(deployDir)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +86,7 @@ publishing {
|
|||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
from(components["java"])
|
||||
artifactId = "${rootProject.name}-lib"
|
||||
artifactId = rootProject.name
|
||||
artifact(tasks.javadocJar)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue