実現したいこと
題名の通り、Gradleのマルチプロジェクトで「reportOn」メソッドを使わずに、サブプロジェクトのテスト結果を集約したテスト結果レポートをルートプロジェクト配下のフォルダに出力したいです。
前提
- Java17
- Gradle Wrapper7.5.1
Gradleのマルチプロジェクト構成でJavaのアプリ開発を行っています。
プロジェクト構成は以下の通りです。
root |--- buildSrc |--- batch |--- common |--- webapp |--- webservice
各プロジェクトのbuild.gradle
は以下のようになっています。
(関係なさそうなところは省略しています)
root\buildSrc\src\main\groovy\java-common.gradle
groovy
1plugins { 2 id 'java' 3 id 'eclipse' 4 id 'project-report' 5 id 'org.springframework.boot' 6 id 'io.spring.dependency-management' 7} 8 9sourceCompatibility = 17 10targetCompatibility = 17 11 12[compileJava, compileTestJava]*.options*.encoding = "UTF-8" 13 14group = 'com.example' 15 16repositories { 17 mavenCentral() 18} 19 20dependencies { 21 // Spring 22 implementation 'org.springframework.boot:spring-boot-starter-web' 23 testImplementation 'org.springframework.boot:spring-boot-starter-test' 24 25 // JUnit 26 testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1' 27 28 // Mockito 29 testImplementation 'org.mockito:mockito-core:4.8.1' 30 testImplementation 'org.mockito:mockito-inline:4.8.1' 31} 32 33tasks.named('test') { 34 useJUnitPlatform() 35 36 testLogging { 37 showStandardStreams false 38 events 'failed' 39 exceptionFormat 'full' 40 } 41 systemProperty "file.encoding", "UTF-8" 42 jvmArgs = ['--add-opens=java.base/java.util=ALL-UNNAMED'] 43} 44 45test { 46 // Test Result Reports are output from all projects at once. 47 reports.html.required = false 48} 49 50// Create a Test Result Report 51// gradlew testReport 52task testReport(type: TestReport) { 53 destinationDirectory = file("${rootDir}/build/reports/allTests") 54 reportOn files("${rootDir}/batch/build/test-results/test/binary", 55 "${rootDir}/common/build/test-results/test/binary", 56 "${rootDir}/webapp/build/test-results/test/binary", 57 "${rootDir}/webservice/build/test-results/test/binary") 58}
root\batch\build.gradle
groogy
1plugins { 2 id 'java-common' 3} 4 5dependencies { 6 implementation project(":common") 7}
root\common\build.gradle
groovy
1plugins { 2 id 'java-common' 3 id 'java-library' 4} 5 6dependencies { 7 // Spring 8 developmentOnly 'org.springframework.boot:spring-boot-devtools' 9 api 'org.springframework.boot:spring-boot-starter-validation' 10}
root\webapp\build.gradle
groovy
1plugins { 2 id 'java-common' 3} 4 5dependencies { 6 implementation project(":common") 7}
root\webservice\build.gradle
groovy
1plugins { 2 id 'java-common' 3} 4 5dependencies { 6 implementation project(":common") 7}
上記の通り、現在の実装では、「reportOn」メソッドを使用して、サブプロジェクトのテスト結果を1つのテスト結果レポートに集約して出力しています。
しかし、ビルド時に以下の警告メッセージが出るので、今後Gradle Wrapperのバージョンを上げることも検討しているため
警告の対応をしようとしていますがうまくいっていません。
発生している問題・警告メッセージ
The TestReport.reportOn(Object...) method has been deprecated. This is scheduled to be removed in Gradle 8.0. Please use the testResults method instead. See https://docs.gradle.org/7.5.1/dsl/org.gradle.api.tasks.testing.TestReport.html#org.gradle.api.tasks.testing.TestReport:testResults for more details.
試したこと
Gradle's TestReport classの実装を確認して、「testResults」プロパティを変更することができれば、やりたいことが実現できるのではないか?と思いましたが、「testResults」プロパティはReadOnlyなプロパティで変更できませんでした。
警告メッセージ内にある、URLにアクセスして、「binaryResultsDirectory」に値を指定すればよいのか?と思ったので、以下のように設定を一部修正してみましたが、テストレポート自体出力されなくなってしまいました・・・
root\buildSrc\src\main\groovy\java-common.gradle
groovy
1test { 2 // Test Result Reports are output from all projects at once. 3 reports.html.required = false 4 5 // add this property 6 tasks.test.binaryResultsDirectory = file("${rootDir}/build/test-results/test/binary") 7} 8 9// Create a Test Result Report 10// gradlew testReport 11task testReport(type: TestReport) { 12 destinationDirectory = file("${rootDir}/build/reports/allTests") 13 // reportOn files("${rootDir}/batch/build/test-results/test/binary", 14 // "${rootDir}/common/build/test-results/test/binary", 15 // "${rootDir}/webapp/build/test-results/test/binary", 16 // "${rootDir}/webservice/build/test-results/test/binary") 17}
設定方法が誤っていると思われますが、公式のドキュメントを参照してみてもよく分からなかったので、
「こういうの試してみたら?」みたいなのでも良いのでアドバイス頂けたら嬉しいです。
よろしくお願いいたします。

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。