tweaks and fixes

- introduce kotlin-jvm convention
- tidy up code-quality build config
This commit is contained in:
Adam 2023-05-31 22:48:49 +02:00
parent b8a394c9ad
commit 6670346890
5 changed files with 119 additions and 89 deletions

View file

@ -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)
}
}

View file

@ -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" })
}

View file

@ -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()
}

View file

@ -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())
}
}
}
}
}