Checkstyle: How to use an official style configuration?

Is there any way to use the style configurations that are packaged with the checkstyle jar?

For example on the command line,

java -jar checkstyle-6.1.1-all.jar -c sun_checks.xml

In my case I’d like to reference the google_checks.xml instead of copying it locally and missing updates from the official configuration.

A new feature was added in 2.2 that can help with this.

Perfect! Except sadly it appears that the checkstyle documentation is wrong, and the jars don’t include the official configurations. Off to bug them. :slight_smile:


$ java -jar checkstyle-6.1.1-all.jar -c sun_checks.xml
Error loading configuration file unable to find sun_checks.xml
Caused by: sun_checks.xml
 ... 3 more

Somewhat unrelated, but could a ‘TextResource’ be used to distribute script plugins. For example:

apply from: resources.text.fromArchiveEntry(configurations.myConfig, “path/to/plugin.gradle”)

Today you’d have to do…

apply from: resources.text.fromArchiveEntry(configurations.myConfig, “path/to/plugin.gradle”).asFile()

That should work, but you are paying the price of unpacking the file opposed to reading it directly from the stream though (as it probably should)

Checkstyle 6.2 now includes the Google and Sun style checks in the jar. However, when I run with your suggestion I receive the error,

FAILURE: Build failed with an exception.
  * What went wrong:
Expected file collection to contain exactly one file, however, it contains 9 files.
apply plugin: 'checkstyle'
  configurations {
  def versions = [
  checkstyle: '6.2',
  dependencies {
  checkstyleConfig "${versions.checkstyle}"
  checkstyle {
  toolVersion = "${versions.checkstyle}"
  config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')
1 Like

Oh, I think the problem is because of transitive dependencies. That resolves into 9 files.

     +--- antlr:antlr:2.7.7
     +--- org.antlr:antlr4-runtime:4.3
  +--- org.abego.treelayout:org.abego.treelayout.core:1.0.1
  \--- org.antlr:antlr4-annotations:4.3
     +--- commons-beanutils:commons-beanutils-core:1.8.3
  \--- commons-logging:commons-logging:1.1.1
     +--- commons-cli:commons-cli:1.2

Setting ‘transitive = false’ on the dependency resolved the issue.