2013-04-08 144 views
1

在我们的多模块maven(3)项目中,我们正在使用maven checkstyle插件。看起来,既然我们已经转移了番石榴依赖于我们的父POM,我们不能成功地执行的CheckStyle:CheckStyle的目标了,因为它失败,出现以下异常:maven checkstyle插件和番石榴/ google-collections依赖冲突

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle- 
plugin:2.10:checkstyle (default-cli) on project init: Execution default-cli of goal 
org.apache.maven.plugins:maven-checkstyle-plugin:2.10:checkstyle failed: An API 
incompatibility was encountered while executing org.apache.maven.plugins:maven- 
checkstyle-plugin:2.10:checkstyle: java.lang.NoSuchMethodError: 
com.google.common.collect.ImmutableSortedSet.of([Ljava/lang/Comparable;)Lcom/google 
/common/collect/ImmutableSortedSet; 
[ERROR] ----------------------------------------------------- 
[ERROR] realm = plugin>org.apache.maven.plugins:maven-checkstyle-plugin:2.10 

的原因可能是, maven checkstyle插件取决于checkstyle框架,该框架取决于google-collections框架(现在包含在google guava框架中),即checkstyle调用的方法不再是番石榴的google集合的一部分。

这里是父POM的摘录中被利用:利用番石榴框架

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.ourcompany.ourproject</groupId> 
<artifactId>ourproject</artifactId> 
<version>0.1-SNAPSHOT</version> 
<packaging>pom</packaging> 
<name>our project</name> 

<modules> 
    <module>init</module> 

... 

</modules> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <junit.version>4.11</junit.version> 
    <maven-compiler-plugin.version>3.0</maven-compiler-plugin.version> 
    <maven-surefire-plugin.version>2.14</maven-surefire-plugin.version> 
    <maven-checkstyle-plugin.version>2.10</maven-checkstyle-plugin.version> 
    <maven-pmd-plugin.version>3.0.1</maven-pmd-plugin.version> 
    <maven-resources-plugin.version>2.6</maven-resources-plugin.version> 
    <java.source.version>1.6</java.source.version> 
    <java.target.version>1.6</java.target.version> 
    <google.guava.version>14.0.1</google.guava.version> 
</properties> 

<repositories> 
    <repository> 
     <id>nexus</id> 
     <name>Internal Maven Repository</name> 
     <url>http://ourinternalmavenrepository/nexus/content/groups/public</url> 
    </repository> 

... 

</repositories> 

<build> 

    <pluginManagement> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>${maven-surefire-plugin.version}</version> 
       <executions> 
        <execution> 
         <id>default-test</id> 
         <phase>test</phase> 
         <goals> 
          <goal>test</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <source>${java.source.version}</source> 
        <target>${java.source.version}</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>${maven-compiler-plugin.version}</version> 
       <configuration> 
        <source>${java.source.version}</source> 
        <target>${java.source.version}</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-resources-plugin</artifactId> 
       <version>${maven-resources-plugin.version}</version> 
       <configuration> 
        <source>${java.source.version}</source> 
        <target>${java.source.version}</target> 
        <encoding>${project.build.sourceEncoding}</encoding> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 

... 

<distributionManagement> 
    <repository> 
     <id>deployment</id> 
     <name>Internal Releases</name> 
     <url>http://ourinternalmavenrepository/nexus/content/repositories/releases/</url> 
    </repository> 
    <snapshotRepository> 
     <id>deployment</id> 
     <name>Internal Releases</name> 
     <url>http://ourinternalmavenrepository/nexus/content/repositories/snapshots/</url> 
    </snapshotRepository> 
</distributionManagement> 
<profiles> 

... 

    <profile> 
     <id>metrics</id> 
     <repositories> 
      <repository> 
       <id>central</id> 
       <url>http://central</url> 
       <releases> 
        <enabled>true</enabled> 
       </releases> 
       <snapshots> 
        <enabled>true</enabled> 
       </snapshots> 
      </repository> 
     </repositories> 
     <pluginRepositories> 
      <pluginRepository> 
       <id>central</id> 
       <url>http://central</url> 
       <releases> 
        <enabled>true</enabled> 
       </releases> 
       <snapshots> 
        <enabled>true</enabled> 
       </snapshots> 
      </pluginRepository> 
     </pluginRepositories> 
     <build> 
      <plugins> 
       <!-- CHECKSTYLE --> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-checkstyle-plugin</artifactId> 
        <version>${maven-checkstyle-plugin.version}</version> 
        <configuration> 
         <configLocation>our_checkstyle.xml</configLocation> 
         <failsOnError>false</failsOnError> 
         <consoleOutput>true</consoleOutput> 
         <source>${java.source.version}</source> 
         <target>${java.source.version}</target> 
        </configuration> 
        <dependencies> 
         <dependency> 
          <groupId>com.ourcompany.ourproject</groupId> 
          <artifactId>init</artifactId> 
          <version>0.1-SNAPSHOT</version> 
         </dependency> 
        </dependencies> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-pmd-plugin</artifactId> 
        <version>${maven-pmd-plugin.version}</version> 
        <executions> 
         <execution> 
          <goals> 
           <goal>check</goal> 
          </goals> 
         </execution> 
        </executions> 
        <configuration> 
         <failsOnError>false</failsOnError> 
         <source>${java.source.version}</source> 
         <target>${java.source.version}</target> 
        </configuration> 
       </plugin> 
      </plugins> 
     </build> 
     <reporting> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-checkstyle-plugin</artifactId> 
        <version>${maven-checkstyle-plugin.version}</version> 
        <configuration> 
         <configLocation>our_checkstyle.xml</configLocation> 
         <targetJdk>${java.source.version}</targetJdk> 
        </configuration> 
       </plugin> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-pmd-plugin</artifactId> 
        <version>${maven-pmd-plugin.version}</version> 
        <configuration> 
         <targetJdk>${java.source.version}</targetJdk> 
        </configuration> 
       </plugin> 
      </plugins> 
     </reporting> 
    </profile> 
</profiles> 

<!-- <dependencyManagement> --> 
<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>${junit.version}</version> 
     <scope>test</scope> 
    </dependency> 

... 

    <dependency> 
     <groupId>com.google.guava</groupId> 
     <artifactId>guava</artifactId> 
     <version>${google.guava.version}</version> 
    </dependency> 

... 

</dependencies> 
<!-- </dependencyManagement> --> 

我认为利用行家的CheckStyle插件在Maven项目中是很常见的,以及。所以我真的很想知道我们在这里做错了什么;)

+1

没什么错在这里,这种情况有时=)只需添加必要依赖于'checkstyle'插件。 – 2013-04-08 08:34:58

+0

奇怪,但它的作品。非常感谢@AndrewLogvinov – zazi 2013-04-08 09:16:05

回答

2

非常感谢@AndrewLogvinov。他在这个问题的评论中提出了工作解决方案。一个只需要在谷歌的集合的依赖增加了Maven的的CheckStyle-插件的依赖关系:

<dependency> 
    <groupId>com.google.collections</groupId> 
    <artifactId>google-collections</artifactId> 
    <version>1.0</version> 
</dependency>