JUnit "5 / Jupiter / Platform" snapshot console launcher task

While core support is being discussed in #19487, I came up with this hand-crafted task set, that makes the default test task depend on a test plan execution.

repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}

configurations {
    jupiter
}

dependencies {
    jupiter 'org.junit.platform:junit-platform-console:1.0.0-SNAPSHOT'
    jupiter 'org.junit.jupiter:junit-jupiter-engine:5.0.0-SNAPSHOT'
}

task downloadJupiter(type: Copy) {
    from configurations.jupiter
    into "$buildDir/jupiter"
}

task runJupiter(type: JavaExec) {
    jvmArgs '-ea'
    classpath = project.sourceSets.test.runtimeClasspath + fileTree(dir: "$buildDir/jupiter", include: '*.jar')
    main 'org.junit.platform.console.ConsoleLauncher'
    args '--scan-class-path'
    args "--reports-dir=$buildDir/jupiter-results"
}

runJupiter.dependsOn downloadJupiter
test.dependsOn runJupiter

Maybe, somebody finds it useful and can improve this work-around. Thanks for feedback.

No need for the download task and custom config, you can just do

dependencies {
    testRuntime 'org.junit.platform:junit-platform-console:1.0.0-SNAPSHOT'
    testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.0-SNAPSHOT'
}

...

classpath = project.sourceSets.test.runtimeClasspath

Thanks, Stefan. It’s working like a charm. Here’s the result, using test.reportsDir as well:

dependencies {
    testRuntime 'org.junit.platform:junit-platform-console:1.0.0-SNAPSHOT'
    testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.0-SNAPSHOT'
}

task runJupiter(type: JavaExec) {
    jvmArgs '-ea'
    classpath = project.sourceSets.test.runtimeClasspath
    main 'org.junit.platform.console.ConsoleLauncher'
    args '--scan-class-path'
    args '--hide-details'
    args "--reports-dir=$project.testReportDir"
}

test.dependsOn runJupiter