English 中文(简体)
Maven 2 checkstyle plugin version 2.5 - Problem with configLocation
原标题:

I am using checkstyle plugin in maven 2. I now want to switch my config file, from the default one to a) an online file, or b) a local file. I tried the following two things, which both didnt work. Any suggestions?

A) Local file, which is directly in my project folder next to the pom.xml

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

B) Remote file, that is stored on a server

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <configuration>
        <configLocation>http://stud.hs-heilbronn.de/~nischmid/development/checkstyle-config.xml</configLocation>
    </configuration>
</plugin>

Both cases result in an error like this:

[INFO] An error has occurred in Checkstyle report generation. Embedded error: Failed during checkstyle execution Could not find resource file:checkstyle.xml .

Any help would be appreciated!

最佳回答

I ve seen several issues related to configLocation in Jira with the version 2.5 of the plugin (like MCHECKSTYLE-129 or MCHECKSTYLE-131), both a) and b) just work fine with the version 2.4.

So, unless you re using Maven 3, I suggest to rollback to 2.4 for now:

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

or

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <version>2.4</version>
  <configuration>
    <configLocation>http://stud.hs-heilbronn.de/~nischmid/development/checkstyle-config.xml</configLocation>
  </configuration>
</plugin>

As a side note, for a multi-modules build, have a look at the Multimodule Configuration.

问题回答

I ve been trying to use version 3.0.1 of the Checkstyle plugin and found configLocation has no effect. Tried the approach above, but still no luck.

To summarise, the answer above probably does work, but you might need to set a property checkstyle.config.location.

Using -X to get debug output, I saw:

[DEBUG]   (f) configLocation = config/sun_checks.xml

Scrolling further back in the log, it looks like configLocation isn t being set:

<configLocation default-value="config/sun_checks.xml">${checkstyle.config.location}</configLocation>

Based on that message, I set the property in the global <properties> as follows:

<checkstyle.config.location>${basedir}/config/checkstyle-configuration.xml</checkstyle.config.location>

This worked, but caused the plugin to throw an exception. After some Googling, I added the following to the checkstyle configuration file:

<module name="Checker">
  ...
  <module name="TreeWalker">
    ...
    <property name="cacheFile" value=""/>

For completeness, the last step came from the following Jira, marked as resolved in 2.8. The difference is it seems to work with an empty value, avoiding the need to set up a ${cachefile} property:

http://jira.codehaus.org/browse/MCHECKSTYLE-159

Maybe helpful for someone else who needs to still find a workaround. By the way i had the same problem and the file is suppose to be searched in /classes/.xml or folders from here. But since it is looking directly after the project folder i included

<configuration>
<configLocation>srcmain
esourcescheckstyle-checker-dev.xml</configLocation>
</configuration>

Note: configLocation has L caps

Also you can define a global variable in environment and use here Note: This is only a workaround, it needs to work as stated in the above lines.





相关问题
Derby gets stuck closing?

I ve got unit tests (in maven) that use derby. At the end of the test run, there is a very long pause, with these log messages before the pause. INFO: Closing Hibernate SessionFactory Nov 16, 2009 8:...

Execute goal on parent after children complete

I have a multi-module maven project (several levels of nesting). Normally, when I execute a maven build (like mvn install or whatever), maven will run all the goals for the parent project before ...

Including dependencies in a jar with Maven

Is there a way to force maven(2.0.9) to include all the dependencies in a single jar file? I have a project the builds into a single jar file. I want the classes from dependencies to be copied into ...

Java Equivalent of distcc

Distcc makes it easy to distribute a C or C++ compile job across a number of machines, and is a godsend for working with large, frequently-built codebases. An increasing number of our large projects ...

Maven Assembly Problem

I have a maven multiple-module project, which is giving me headaches in the assembly:assembly phase. I have a module which has an assembly defined in it which works fine when I invoke mvn assembly:...

热门标签