STS(Eclipse)でJUnit5を使用したいが、Java11ではエラーになる件
- 評価
- クリップ 0
- VIEW 1,835
Open JDK11を使用し、STS(バージョン4.4.0 2019/10/15に最新版をダウンロード)でGradleプロジェクトを作っています。
Spring Bootで簡易的なアプリを作ったところまではよいのですが、
JUnit5が以下のようなエラーが出てしまい動きません。
原因が分からず困っています。
Java1.8を使っていた時はJUnit5が利用できたのですが、Java11では利用できないのでしょうか。
以下build.gradleの設定になります。
buildscript {
ext {
springBootVersion = '2.1.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('org.junit.platform:junit-platform-gradle-plugin:1.0.0')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.junit.platform.gradle.plugin'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 11
compileJava.options.encoding = "UTF-8"
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation('org.junit.jupiter:junit-jupiter-api:5.2.0')
testImplementation('org.junit.jupiter:junit-jupiter-params:5.2.0')
testImplementation('org.junit.jupiter:junit-jupiter-engine:5.2.0')
testImplementation('org.mockito:mockito-core:2.21.0')
testImplementation('org.mockito:mockito-junit-jupiter:2.21.0')
}
どうしても同じ結果しか出て来ず困っています。
どうやらSTS(Eclipse)はgradleのタスク実行時にSTS固有の設定を読み込むようですが、そちらをJava11に設定しても結果は同様です。検索でいろいろ調べたのですが、ヒットしませんでした。
何か対応策がありましたらご教授ください。
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
0
このbuild.gradleでユニットテストが実行できるかお試しください。
buildscript {
ext {
springBootVersion = '2.1.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}')
}
}
plugins {
id 'org.springframework.boot' version '2.1.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
compileJava.options.encoding = 'UTF-8'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'org.junit:junit-bom:5.5.2'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'junit', module: 'junit'
}
testImplementation('org.junit.jupiter:junit-jupiter')
testRuntimeOnly('org.junit.platform:junit-platform-launcher') {
because 'allows tests to run from IDEs that bundle older version of launcher'
}
testImplementation('org.mockito:mockito-junit-jupiter')
}
test {
jvmArgs = [
'-ea'
, '-Dfile.encoding=UTF-8'
]
useJUnitPlatform()
}
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.36%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
質問への追記・修正、ベストアンサー選択の依頼
asahina1979
2019/10/15 07:12
古いSTSは Java11 は非対応ですけどね?
spring_boot
2019/10/15 17:14
ありがとうございます。
STSは2か月ほど前にダウンロードしたものを使用していました。
改めて最新のものでも動かしましたが同じ結果でした。
asahina1979
2019/10/15 21:22
openjdkでの起動をstsがサポートしてるのか?という問題もあるよな