问题
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!
回答1:
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.
回答2:
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
回答3:
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>src\main\resources\checkstyle-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.
来源:https://stackoverflow.com/questions/2279819/maven-2-checkstyle-plugin-version-2-5-problem-with-configlocation