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項目中是很常見的,以及。所以我真的很想知道我們在這裏做錯了什麼;)
沒什麼錯在這裏,這種情況有時=)只需添加必要依賴於'checkstyle'插件。 – 2013-04-08 08:34:58
奇怪,但它的作品。非常感謝@AndrewLogvinov – zazi 2013-04-08 09:16:05