Google Java Style + Gradle checkstyle plugin
こちらからgoogle_checks.xml
をダウンロードして${project.projectDir}/config/checkstyle/checkstyle.xml
に置きます。
サブプロジェクトを使用する場合など設定ファイルの場所を変えたい場合は、
以下のようにbuild.gradle
ファイルに指定します。
checkstyleMain.configFile = file("${rootProject.projectDir}/config/checkstyle/checkstyle.xml")
チェックしたいプロジェクトのbuild.gradle
にcheckstyleプラグインを追加しますが、
apply plugin: 'checkstyle'
このままでは以下のようなエラーが出ました。
:common-utils:checkstyleMain FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':common-utils:checkstyleMain'. > Unable to create a Checker: Property 'fileExtensions' in module Checker does not exist, please check the documentation * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 10.012 secs Property 'fileExtensions' in module Checker does not exist, please check the documentation 18:13:19: External task execution finished 'checkstyleMain'.
checkstyleを実行する際のライブラリcom.puppycrawl.tools:checkstyle
のバージョンが
XMLとあっていないのが原因だったようで、
以下の設定を追加したら正常に実行することができました。
apply plugin: 'checkstyle' checkstyle.toolVersion = '6.6
最新のcheckstyle.xmlファイルを利用する場合はtoolVersion
も最新のものを利用するのが良いようです。
最新版は"Maven Repository: com.puppycrawl.tools » checkstyle"で確認できます。
参考
java - Error using checkstyle/google_checks.xml with maven-checkstyle-plugin - Stack Overflow