Skip to content

Commit

Permalink
migrate junit4 subproject configuration to Kotlin DSL (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaschmid committed Dec 22, 2019
1 parent c0e5216 commit 2b1be7c
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 56 deletions.
97 changes: 97 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,101 @@ project(":core") {
}
}

project(":junit4") {
apply<GroovyPlugin>()

configure<BasePluginConvention> {
archivesBaseName = "junit4-dataprovider"
description = "A TestNG like dataprovider runner for JUnit having a simplified syntax compared to all the existing JUnit4 features."
}

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
}

configure<SourceSetContainer> {
create("integTest") {
compileClasspath += named("main").get().output + named("test").get().output
runtimeClasspath += named("main").get().output + named("test").get().output
}
}

configurations {
"integTestImplementation" {
extendsFrom(configurations["testImplementation"])
}
}

dependencies {
"api"(project(":core"))
"api"("junit:junit:${junit4Version}")

"testImplementation"("org.assertj:assertj-core:1.7.1")
"testImplementation"("org.mockito:mockito-core:2.18.3")

"integTestImplementation"("org.codehaus.groovy:groovy:2.4.7")
}

tasks {
withType<JavaCompile> {
options.compilerArgs.addAll(listOf("-Xlint:-options"))
}

named<Jar>("jar") {
manifest {
attributes(
"Automatic-Module-Name" to "com.tngtech.junit.dataprovider.junit4"
)
}
}

val integTest = register<Test>("integTest") {
group = "verification"
description = "Runs all integration tests."

ignoreFailures = isBuildOnJenkins

classpath = project.the<SourceSetContainer>()["integTest"].runtimeClasspath
testClassesDirs = project.the<SourceSetContainer>()["integTest"].output.classesDirs

dependsOn(named("integTestClasses"))
}
val touchIntegTestResultsForJenkins = register<TouchTestResults>("touchIntegTestResultsForJenkins") {
tasks(integTest)
enabled = isBuildOnJenkins
}
getByName("build").dependsOn(touchIntegTestResultsForJenkins)
}
}

// -- Custom tasks ------------------------------------------------------------
/**
* Task to touch all junit xml report files for all given {@link Test} {@code tasks}.
* This is required due to Jenkins fails if test output is created before build starts which
* could happen using Gradles up-to-date feature :(
*/
open class TouchTestResults : DefaultTask() {
@InputFiles
val tasks = mutableListOf<TaskProvider<Test>>()

fun tasks(vararg testTasks: TaskProvider<Test>) {
tasks.addAll(testTasks)
mustRunAfter(testTasks)
}

@TaskAction
fun touch() {
tasks.forEach { test ->
val testResultsDir = test.get().reports.junitXml.destination
if (testResultsDir.exists()) {
val timestamp = System.currentTimeMillis()
testResultsDir.listFiles()?.forEach { file ->
file.setLastModified(timestamp)
}
}
}
}
}

apply(from = "legacy.build.gradle")
56 changes: 0 additions & 56 deletions legacy.build.gradle
Original file line number Diff line number Diff line change
@@ -1,59 +1,3 @@
project(":junit4") {
apply(plugin: "groovy")

archivesBaseName = "junit4-dataprovider"
description = "A TestNG like dataprovider runner for JUnit having a simplified syntax compared to all the existing JUnit4 features."

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_6

sourceSets {
integTest {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}

configurations {
integTestImplementation {
extendsFrom(testImplementation)
}
}

dependencies {
api(project(":core"))
api("junit:junit:${junit4Version}")

testImplementation("org.assertj:assertj-core:1.7.1")
testImplementation("org.mockito:mockito-core:2.18.3")

integTestImplementation("org.codehaus.groovy:groovy:2.4.7")
}

tasks.withType(JavaCompile) {
options.compilerArgs += [ "-Xlint:-options" ]
}

jar {
manifest {
attributes(
"Automatic-Module-Name": "com.tngtech.junit.dataprovider.junit4"
)
}
}

task integTest(dependsOn: integTestClasses, type: Test, group: "verification", description: "Runs all integration tests.") {
ignoreFailures = isBuildOnJenkins

classpath = sourceSets.integTest.runtimeClasspath
testClassesDirs = sourceSets.integTest.output.classesDirs
}
task touchIntegTestResultsForJenkins(type: TouchTestResults) {
tasks(integTest)
enabled = isBuildOnJenkins
}
build.dependsOn(touchIntegTestResultsForJenkins)
}

configure(subprojects.findAll{ p -> p.name.startsWith("junit-jupiter") }) {
apply(plugin: "groovy")

Expand Down

0 comments on commit 2b1be7c

Please sign in to comment.