6

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?

4

4 回答 4

10

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.

于 2009-02-11T05:22:59.447 回答
0

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?

于 2009-01-29T09:58:17.520 回答
0

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.

于 2009-01-29T10:11:49.990 回答
0

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

于 2012-09-04T12:34:17.377 回答