2013-07-29 78 views
30

我有一个我希望从编译中排除的java源文件夹。Maven:排除编译中的java文件

我的文件夹在qa/apitests/src/main/java/api/test/omi之下。

我在pom.xmlqa/bamtests下添加了下列条目,但它没有帮助。除了我需要做的还有一个入口吗?

<build> 
    <resources> 
     <resource> 
     <directory>src/main/java</directory> 
     <includes> 
      <include>**/*.properties</include> 
      <include>**/*.xml</include> 
      <include>**/*.xsd</include> 
      <include>**/*.csv</include> 
     </includes> 
     <excludes> 
<exclude>src/main/java/api/test/omi</exclude> 
     </excludes> 
     </resource> 
</build> 
+0

地理位置属性是用于测试属性'的src /测试/ resources''的src /主/ resources'。 – khmarbaise

+0

您在'qa/bamtests'中的项目如何在'qa/apitests'中找到源代码? – 2013-07-29 10:04:20

+0

使用相同模式排除: **/test/omi/** boskop

回答

39

使用Maven Compiler Plugin

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <configuration> 
    <excludes> 
     <exclude>**/api/test/omi/*.java</exclude> 
    </excludes> 
    </configuration> 
</plugin> 
+0

这两个主要的'*'代表什么? –

+2

**表示'任何目录'。 – 2015-06-11 14:41:43

+2

这个答案对我不起作用。看看这个http://stackoverflow.com/a/19713000/358013 – blueskin

2

如果要排除编译Java源代码,然后提到他们在Maven Compiler Plugin定义

<plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>2.0.2</version> 
     <configuration> 
      <excludes> 
       <exclude>src/main/java/api/test/omi/*.java</exclude> 
      </excludes> 
     </configuration> 
    </plugin> 
</plugins> 

资源插件只定义了所有资源,在您的最终神器捆绑。

33

添加一个排除为其他答案提示为我工作,除了路径不应包括“的src/main/java目录”:

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <configuration> 
     <excludes> 
      <exclude>com/filosync/store/StoreMain.java</exclude> 
     </excludes> 
     </configuration> 
    </plugin> 
    </plugins> 
</build> 
+0

删除src/main /是如此真实! – Dudi

11

对于任何需要排除测试源<exclude>标签会不行。您需要使用<testExclude>代替:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.3</version> 
    <configuration> 
     <testExcludes> 
     <testExclude>**/PrefixToExclude*</testExclude> 
     </testExcludes> 
    </configuration> 
    </plugin> 
1

顶部投票答案工作正常,但它不允许强制排除时/正在使用不排除那些排除类/班。

解决方法使用maven-antrun-plugin

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.8</version> 
    <executions> 
     <execution> 
      <phase>process-classes</phase> 
      <goals> 
       <goal>run</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <tasks> 
      <delete dir="target/classes/folder/to/exclude"/> 
     </tasks> 
    </configuration> 
</plugin>