Checkstyle not working

I am new to maven and chekstyle so I need to ask some question ... I want to use checkstyle in my maven based project, so in mine pom.xml

I add the dependency

<dependency>
   <groupId>checkstyle</groupId>
   <artifactId>checkstyle</artifactId>
   <version>2.4</version>
</dependency>

      

and also I added an entry to the plugin tag:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <version>2.4</version>
  <configuration>
    <enableRulesSummary>true</enableRulesSummary>
    <configLocation>checkstyle.xml</configLocation>
  </configuration>
</plugin>

      

But when I run my maven build using the command mvn clean install

, checkstyle does nothing. And since I don't have it checkstyle.xml

on my system yet, shouldn't I be complaining about the bug?

What other configuration am I missing?

+2


a source to share


1 answer


I want to use checkstyle in my maven based project, so in my pom.xml I add the dependency (...)

You don't need to add this dependency, you just need to declare the plugin (the plugin declares its own dependencies).

(...) But when I run my maven build with mvn clean install command, checkstyle does nothing.

Yes, because you only declared the plugin, you did not tie the target check

to the lifecycle phase, so a normal build does not trigger the checkstyle plugin. If you want to checkstyle:check

run as part of your build, you need to declare the target check

inside the run (it binds to the phase by default verify

). Something like that:



<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <!-- Lock down plugin version for build reproducibility -->
  <version>2.5</version>
  <configuration>
    <consoleOutput>true</consoleOutput>
    <configLocation>checkstyle.xml</configLocation>
    ...
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>check</goal>
      </goals>
    </execution>
  </executions>
</plugin>

      

Now the call to any phase, including verify

checkstyle is called.

And since there is no checkstyle.xml on my system yet, shouldn't I be complaining about the error?

It will be ... when called (either explicitly with mvn checkstyle:check

, or as part of an assembly if you change the setting as suggested).

+7


a source







All Articles