Maven 2 Checkstyle configLocation
-
20-08-2019 - |
Question
i have a project which has as maven dependency a jar file which includes a xml file where i stored my rules for checkstyle. I thought it would be ok to just use this configuration: <configLocation>mycheckstyle.xml</configLocation>. My understanding is that the file should be searched on the classpath and my jar file is a Maven dependency so it should be found, however i get a resource not found exception. Any suggestions? Thanks in advance..
kuku
Solution
Try adding a dependencies section to your plugin configuration.
E.g.,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.example.whizbang</groupId>
<artifactId>build-tools</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
See Maven Checkstyle Plugin - Multimodule Configuration for more information.
OTHER TIPS
As explained in the Checkstyle plugin page,
configLocation :
Specifies the location of the XML configuration to use.
Potential values are a filesystem path, a URL, or a classpath resource.
I never did that on my project...
Are you sure that the JAR containing the XML file is in the classpath when the checkstyle plugin is starting?
I'm having a parent which specifies the checkstyle plugin and has in its resource folder the appropriate mycheckstyle.xml. I use the maven assembly plugin to make a jar of my parents resource folder and define that jar as a dependency in my child. So when the child inherits the checkstyle plugin + it's configuration from the parent it should be able to find the mycheckstyle.xml. I have followed the instructions on the checkstyle plugin page but it didn't work.
If you have a local maven repository for your self-created and compiled checks, please be aware to not forget defining
<repositories>
<repository>
<id>my local repository</id>
<url>file:${basedir}/.m2artifacts</url>
</repository>
<!-- ... -->
</repositories>
but also
<pluginRepositories>
<pluginRepository>
<id>my local repository</id>
<url>file:${basedir}/.m2artifacts</url>
</pluginRepository>
<!-- ... -->
</pluginRepositories>
otherwise the plugin dependency will just look in central maven repo but will not find your local JAR file with your check-classes