当我在本地做一个mvn clean包时,一切正常。当我在jenkins服务器上执行mvn clean包时,我会收到错误。我正在运行Jenkins 1.596,Maven 3.2.5,SonarQube 4.5.1,Maven插件2.4在Jenkins声纳设置中定义。
这是Jenkins工作的输出。
[INFO] --- sonar-maven-plugin:2.4:sonar (default-cli) @ myproject ---
[INFO] SonarQube version: 4.5.1
INFO: Work directory: /var/lib/jenkins/workspace/myporject/target/sonar
[INFO] [22:48:12.147] Base dir: /var/lib/jenkins/workspace/myproject
[INFO] [22:48:12.148] Working dir: /var/lib/jenkins/workspace/myproject/target/sonar
[INFO] [22:48:12.148] Source paths: src
[INFO] [22:48:12.148] Test paths: src/test/java
[INFO] [22:48:12.148] Binary dirs: target/classes
[INFO] [22:48:12.148] Source encoding: UTF-8, default locale: en_US
[INFO] [22:48:12.148] Index files
[ERROR] File [relative=src/test/java/com/blah/web/service.java, abs=/var/lib/jenkins/workspace/myproject/src/test/java/com/blah/web/service.java] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (default-cli) on project myproject: File [relative=src/test/java/com/blah/web/service.java, abs=/var/lib/jenkins/workspace/myproject/src/test/java/com/blah/web/service.java] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (default-cli) on project myproject: File [relative=src/test/java/com/blah/web/service.java, abs=/var/lib/jenkins/workspace/myproject/src/test/java/com/blah/web/service.java] can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
我的Sonar插件设置似乎缺少某些内容,但我不确定定义它的内容或位置。
以下是我的pom.xml
中的一些片段<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blah</groupId>
<artifactId>myproject</artifactId>
<version>99</version>
<packaging>war</packaging>
<name>myproject</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<routePath>${pom.project.build.directory}/routes</routePath>
<spring.release.version>3.2.4.RELEASE</spring.release.version>
<rabbitmq.version>3.1.4</rabbitmq.version>
<spring.amqp.version>1.2.0.RELEASE</spring.amqp.version>
</properties>
<build>
<finalName>myproject</finalName>
<sourceDirectory>src</sourceDirectory>
<scriptSourceDirectory>src/main/java</scriptSourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.8.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.1.8-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
</additionalProjectnatures>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
<classpathContainer>GROOVY_DSL_SUPPORT</classpathContainer>
</classpathContainers>
<sourceIncludes>
<sourceInclude>**/*.groovy</sourceInclude>
</sourceIncludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/integration/**/*.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
答案 0 :(得分:0)
问题似乎是您的源文件夹是测试文件夹的前缀。换句话说,如果你说你的测试文件夹是src/test/java/
,你的源文件夹应该是src/main/java
,而不是src
,因为这会导致插件两次找到同一个类,这就是导致错误
删除<sourceDirectory>src</sourceDirectory>
应该可以解决问题,因为它将使用maven的默认值(src / main / java)。当您使用它时,请同时删除testSourceDirectory
,因为您将其设置为默认值,因此您不需要它。一般来说,pom应该尽可能简单,因为maven都是关于约定优于配置