LoginSignup
5
3

More than 5 years have passed since last update.

JUnit5を利用するためのGradle設定

Posted at

GradleでJUnit5を利用するためのbuild.gradleサンプル。

build.gralde
buildscript {
    ext {
        junitPlatformVersion = '1.0.1'
        junitJupiterVersion = '5.0.1'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.junit.platform:junit-platform-gradle-plugin:${junitPlatformVersion}"
    }
}

repositories {
    mavenCentral()
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.junit.platform.gradle.plugin'

compileTestJava {
    sourceCompatibility = targetCompatibility = 9
    options.compilerArgs += '-parameters'
}

dependencies {
    // JUnit Jupiter API and TestEngine implementation
    testCompile "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
    testRuntime "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}"

    // To avoid compiler warnings about @API annotations in JUnit code
    testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'

    // Only needed to run tests in an (IntelliJ) IDE(A) that bundles an older version
    testRuntime "org.junit.platform:junit-platform-launcher:${junitPlatformVersion}"
}

task wrapper(type: Wrapper) {
    gradleVersion = '4.2.1'
    distributionType = Wrapper.DistributionType.ALL
}
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3