在我们的多模块maven(3)项目中,我们正在使用maven checkstyle插件。看起来因为我们已经将guava依赖关系转移到了我们的父pom,我们无法再成功执行checkstyle:checkstyle目标,因为它失败并出现以下异常:
[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调用的方法不属于番石榴中的谷歌收藏品了。
以下是正在使用的父母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> -->
我认为在maven项目中使用maven checkstyle插件非常常见,并且使用番石榴框架。所以我真的很想知道我们在这里做错了什么;)
答案 0 :(得分:2)
非常感谢@AndrewLogvinov。他在对这个问题的评论中提出了工作解决方案。只需要将google-collections依赖项添加到maven-checkstyle-plugin的依赖项中:
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>