Skip to content

Commit

Permalink
add JVM Test Suite plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ToppleTheNun committed Sep 3, 2023
1 parent 29286ab commit 1f7beb2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ gradlePlugin {
implementationClass = "dev.mythicdrops.gradle.conventions.MythicDropsJavaPlatformPlugin"
tags.set(listOf("kotlin", "pixeloutlaw", "convention"))
}
create("mythicDropsConventionJvmTestSuite") {
id = "dev.mythicdrops.gradle.convention.jvm-test-suite"
displayName = "mythicDropsGradleConventionJvmSuite"
description = "Common conventions for all MythicDrops JVM Test Suite Gradle projects."
implementationClass = "dev.mythicdrops.gradle.conventions.MythicDropsJvmTestSuitePlugin"
tags.set(listOf("kotlin", "pixeloutlaw", "convention"))
}
create("mythicDropsConventionKotlinJvm") {
id = "dev.mythicdrops.gradle.convention.kotlin.jvm"
displayName = "mythicDropsGradleConventionKotlinJvm"
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/dev/mythicdrops/gradle/MythicDropsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.mythicdrops.gradle

import dev.mythicdrops.gradle.conventions.MythicDropsJavaPlatformPlugin
import dev.mythicdrops.gradle.conventions.MythicDropsJavaPlugin
import dev.mythicdrops.gradle.conventions.MythicDropsJvmTestSuitePlugin
import dev.mythicdrops.gradle.conventions.MythicDropsKotlinJvmPlugin
import dev.mythicdrops.gradle.conventions.MythicDropsMavenPublishPlugin
import dev.mythicdrops.gradle.projects.MythicDropsBasePlugin
Expand All @@ -28,6 +29,7 @@ open class MythicDropsPlugin : Plugin<Project> {
pluginManager.apply(MythicDropsBasePlugin::class)
pluginManager.apply(MythicDropsJavaPlugin::class)
pluginManager.apply(MythicDropsJavaPlatformPlugin::class)
pluginManager.apply(MythicDropsJvmTestSuitePlugin::class)
pluginManager.apply(MythicDropsKotlinJvmPlugin::class)
pluginManager.apply(MythicDropsMavenPublishPlugin::class)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.gradle.kotlin.dsl.withType
/**
* Plugin that configures Maven publications for Java Platforms.
*/
open class MythicDropsJavaPlatformPlugin : DependentPlugin("Java", "java-platform") {
open class MythicDropsJavaPlatformPlugin : DependentPlugin("Java Platform", "java-platform") {
override fun configureProject(target: Project) {
target.pluginManager.withPlugin("maven-publish") {
target.extensions.getByType<PublishingExtension>().publications.withType<MavenPublication> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_17
*/
open class MythicDropsJavaPlugin : DependentPlugin("Java", "java") {
override fun configureProject(target: Project) {
val javaExtension = target.extensions.create<MythicDropsJavaExtension>("mythicDropsJava")
javaExtension.apply {
val javaExtension = target.extensions.create<MythicDropsJavaExtension>("mythicDropsJava").apply {
// default to Java 17
javaVersion.convention(DEFAULT_JAVA_VERSION)
}
Expand All @@ -34,7 +33,7 @@ open class MythicDropsJavaPlugin : DependentPlugin("Java", "java") {
// enable and configure JaCoCo
target.pluginManager.apply(JacocoPlugin::class.java)
target.configure<JacocoPluginExtension> {
toolVersion = "0.8.8"
toolVersion = "0.8.10"
}
target.tasks.withType<JacocoReport> {
reports {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.mythicdrops.gradle.conventions

import org.gradle.api.Project
import org.gradle.api.plugins.jvm.JvmTestSuite
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.withType
import org.gradle.testing.base.TestingExtension

/**
* Plugin that configures the base JVM Test Suite to use JUnit Jupiter.
*/
open class MythicDropsJvmTestSuitePlugin : DependentPlugin("JVM Test Suite", "org.gradle.jvm-test-suite") {
@Suppress("UnstableApiUsage")
override fun configureProject(target: Project) {
target.configure<TestingExtension> {
suites.withType<JvmTestSuite> {
useJUnitJupiter()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ open class MythicDropsKotlinJvmPlugin : DependentPlugin("Kotlin JVM", "org.jetbr

// exclude files from the build directory from being linted or formatted
target.configure<KtlintExtension> {
// ktlint version that supports kotlin 1.8.0
version.set("0.48.2")
version.set("0.50.0")
filter {
exclude { entry ->
entry.file.toString().contains("generated")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import com.adarshr.gradle.testlogger.theme.ThemeType
import nebula.plugin.responsible.NebulaResponsiblePlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.withType

/**
* Plugin that applies sensible defaults to all projects. Intended for use on root and subprojects.
Expand All @@ -31,10 +29,5 @@ open class MythicDropsBasePlugin : Plugin<Project> {
showSkippedStandardStreams = false
showPassedStandardStreams = false
}

// make tests use JUnit Jupiter
target.tasks.withType<Test>() {
useJUnitPlatform()
}
}
}

0 comments on commit 1f7beb2

Please sign in to comment.