Skip to content

Commit

Permalink
Use new gradle jvm-test-suite plugin (#773)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeroen van Erp <jeroen@hierynomus.com>
  • Loading branch information
hierynomus authored Jul 6, 2023
1 parent 9b7ef85 commit f668b29
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Release
run: ./gradlew release -Prelease.disableChecks -Prelease.pushTagsOnly -Prelease.customUsername=${{ github.actor }} -Prelease.customPassword=${{ github.token }}
run: ./gradlew clean publishToSonatype closeAndReleaseSonatypeStagingRepository
env:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNINGKEY }}
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.SIGNINGKEYID }}
Expand Down
110 changes: 61 additions & 49 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.text.SimpleDateFormat

plugins {
id "java"
id "jvm-test-suite"
id "groovy"
id "jacoco"
id "maven-publish"
Expand Down Expand Up @@ -46,25 +47,10 @@ compileJava {
configurations.implementation.transitive = false

dependencies {

implementation SLF4J_API
implementation BCPROV_JDK15ON
implementation MBASSADOR
implementation ASN_ONE
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.7.0")

testImplementation GROOVY_ALL
testRuntimeOnly CGLIB_NODEP
testRuntimeOnly OBJENESIS
testImplementation SPOCK_CORE
testImplementation COMMONS_IO
testRuntimeOnly LOGBACK_CLASSIC
}

tasks.withType(Test) {
useJUnitPlatform()
}

license {
Expand Down Expand Up @@ -99,39 +85,71 @@ if (JavaVersion.current().isJava8Compatible()) {
}
}

configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntime.extendsFrom testRuntime
}
testing {
suites {
configureEach {
useJUnitJupiter()
dependencies {
implementation SLF4J_API
implementation GROOVY_ALL
runtimeOnly CGLIB_NODEP
runtimeOnly OBJENESIS
implementation SPOCK_CORE
implementation COMMONS_IO
runtimeOnly LOGBACK_CLASSIC
}

sourceSets {
integrationTest {
groovy {
compileClasspath += sourceSets.main.output + sourceSets.test.output
runtimeClasspath += sourceSets.main.output + sourceSets.test.output
srcDir file('src/it/groovy')
targets {
all {
testTask.configure {
testLogging {
exceptionFormat = 'full'
}
include "**/*Test.*"
include "**/*Spec.*"
afterSuite { descriptor, result ->
def indicator = "\u001B[32m✓\u001b[0m"
if (result.failedTestCount > 0) {
indicator = "\u001B[31m✘\u001b[0m"
}
logger.lifecycle("$indicator Test ${descriptor.name}; Executed: ${result.testCount}/\u001B[32m${result.successfulTestCount}\u001B[0m/\u001B[31m${result.failedTestCount}\u001B[0m")
}
}
}
}
}
resources.srcDir file('src/it/resources')
}
}

task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
test {
sources {
groovy {
srcDirs = ['src/test/groovy']
}
}
}

tasks.withType(Test) {
testLogging {
exceptionFormat = 'full'
}
include "**/*Test.*"
include "**/*Spec.*"
afterSuite { descriptor, result ->
def indicator = "\u001B[32m✓\u001b[0m"
if (result.failedTestCount > 0) {
indicator = "\u001B[31m✘\u001b[0m"
integrationTest(JvmTestSuite) {
dependencies {
implementation project()
}

sources {
groovy {
srcDirs = ['src/it/groovy']
}

resources {
srcDirs = ['src/it/resources']
}
}

targets {
all {
testTask.configure {
shouldRunAfter(test)
}
}
}
}
logger.lifecycle("$indicator Test ${descriptor.name}; Executed: ${result.testCount}/\u001B[32m${result.successfulTestCount}\u001B[0m/\u001B[31m${result.failedTestCount}\u001B[0m")
}
}

Expand Down Expand Up @@ -235,13 +253,7 @@ task stopItestContainer(type: DockerStopContainer) {
project.tasks.integrationTest.dependsOn(startItestContainer)
project.tasks.integrationTest.finalizedBy(stopItestContainer)

task forkedUploadRelease(type: GradleBuild) {
buildFile = project.buildFile
tasks = ["clean", "publishToSonatype", "closeAndReleaseSonatypeStagingRepository"]
}

project.tasks.release.dependsOn([project.tasks.integrationTest, project.tasks.build])
project.tasks.release.finalizedBy(project.tasks.forkedUploadRelease)

project.tasks.jacocoTestReport.dependsOn(project.tasks.test)
project.tasks.check.dependsOn(project.tasks.jacocoTestReport)

0 comments on commit f668b29

Please sign in to comment.