Domanda

I am running Maven 3.0.5 and am trying to use the maven checkstyle plugin but I am not able to get it to parse my configuration file correctly. In the reporting section of my POM, I have

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.10</version>
    <configuration>
        <propertyExpansion>suppressions.file=${basedir}/suppressions.xml</propertyExpansion>
        <configLocation>file:///${basedir}/../buildTools/checkstyle/checkstyle-5.0-checks.xml</configLocation>
    </configuration>
</plugin>

In my checkstyle.xml file, I have suppressions filter defined as

<module name="SuppressionFilter">
<!--     <property name="file" value="${checkstyle.suppressions.file}"/>
-->
   <property name="file" value="${suppressions.file}"/>
</module>

When I run the checkstyle:checkstyle goal, I am getting an error that suppressions.file is not defined. I can get this to run under either Eclipse or ant but when I try to use this with maven, I can not get the property to be set. I have also tried using the checkstyle.suppressions.file value and setting it with the propertyExpansion tag or the suppressionsFile tag.

Is there a way to do this out of Maven. The end result that I am looking for is to be able to user the same rules file in Eclipse, Ant, and Maven. This would be a common file that I would point to. At the same time, I want to be able to put a suppressions.xml file in each individual project that would allow the suppressions filter to be controlled by project.

È stato utile?

Soluzione 2

Ok, I started this by following some site that stated that if you add the configuration in the reporting section, it would be picked up by the build plugin section. This does not work. I still have more work that I want to do on this by adding the dependency for the jar file for the checks. What I am finding is the I have to spec the suppressions file even though I have it defined within the checks file. I also have to pass in the variable using the propertyExpansion that points to the internal suppression file (I wanted this one, not having to also spec the suppressions file a second time). I now have my build plugin stanza as

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.10</version>
    <configuration>
      <propertyExpansion>suppressions.file=${basedir}/suppressions.xml</propertyExpansion>
      <configLocation>file:///${basedir}/../buildTools/checkstyle/checkstyle-5.0-checks.xml</configLocation>
      <suppressionsFile>${basedir}/suppressions.xml</suppressionsFile>
    </configuration>
</plugin>

Altri suggerimenti

First i would suggest not to use absolute file names like you do via configLocation. The better solution is to use an artifact which contains the appropriate configuration file like having a separate project let's call it: checkstyle which can be versionized etc.

checkstyle
  |-- src
  |   `-- main
  |       `-- resources
  |               |-- checkstyle.xml
  |               `-- LICENSE.TXT
  `-- pom.xml


<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example.checkstyle</groupId>
  <artifactId>checkstyle</artifactId>
  <version>1.0</version>
  <name>checkstyle configuration</name>
</project>

After you have made mvn install you can use the configuration like the following:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>whatever-project</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>
  <name>My Project </name>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.10</version>
        <dependencies>
          <dependency>
            <groupId>com.example.checkstyle</groupId>
            <artifactId>checkstyle</artifactId>
            <version>1.0</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.10</version>
        <configuration>
          <configLocation>checkstyle.xml</configLocation>
          <headerLocation>LICENSE.txt</headerLocation>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top