インストール
Windows10環境にインストールする。
ダウンロード
以下の公式サイトからダウンロードする
https://gradle.org/releases/
2018/7/16時点の最新版の4.8.1をダウンロードする。
ファイルの展開と環境変数の設定
「D:\gradle-4.8.1」に展開する。
環境変数「GRADLE_HOME」を作成。
PATHに「%GRADLE_HOME%\bin」を追加する。
コマンドプロンプトで「gradle -version」を実行できたら終了。
使い方
参考サイト:https://qiita.com/vvakame/items/83366fbfa47562fafbf4
エラー対応
エラー: この文字は、エンコーディングMS932にマップできません
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
JUnit5用
bild.gradle
plugins {
id 'java'
}
repositories {
mavenCentral()
}
test {
useJUnitPlatform {
includeEngines 'junit-jupiter'
}
}
dependencies {
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0'
testCompile "commons-io:commons-io:2.6"
testCompile "org.junit.jupiter:junit-jupiter-migrationsupport:5.2.0"
testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.2.0'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
JUnit5
以下を参考にする。
https://junit.org/junit5/docs/current/user-guide/
gradle -q test -PincTags=ABC
build.gradle
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile('org.junit.jupiter:junit-jupiter-api:5.2.0')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.2.0')
testCompile "commons-io:commons-io:2.6"
}
test {
useJUnitPlatform{
if (project.hasProperty('incTags')) {
includeTags incTags
}
if (project.hasProperty('excTags')) {
excludeTags excTags
}
}
testLogging {
events "passed", "skipped", "failed"
}
reports {
html.enabled = true
}
}
task wrapper(type: Wrapper) {
description = 'Generates gradlew[.bat] scripts'
gradleVersion = '4.6'
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
Jenkins
テストが実行されない
gradleのTaskに「clean test」と最初にcleanを追加する。