Maven - 从构建中排除文件夹

时间:2014-08-12 11:11:09

标签: maven maven-compiler-plugin

尝试从我的构建中排除文件夹src/main/resources/scripts/但以下内容不起作用:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>src/main/resources/scripts/</exclude>
            </excludes>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <excludes>
                    <exclude>src/main/resources/scripts/</exclude>
                </excludes>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

有什么想法吗?

4 个答案:

答案 0 :(得分:46)

而是尝试:

<exclude>scripts/**</exclude>

排除基于目录,因此您的构造将排除

src/main/resources/src/main/resources/scripts

答案 1 :(得分:5)

我遇到了类似问题并发现了以下问题:

  • 您可能有一个已定义maven-compiler-plugin配置的父pom。为此,请将combine.self="override"添加到configuration标记。请参阅Maven : Is it possible to override the configuration of a plugin already defined for a profile in a parent POM
  • 如果需要编译的排除类,插件似乎忽略了排除:确保您没有引用其他将被编译的类中的排除类。例如,如果您排除Foo.java,但在Bar.java import Foo; Foo.java,它将(尝试)编译Bar.java以编译<profiles> <profile> <id>myId</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration combine.self="override"> <excludes> <exclude>**/some/full/directory/*</exclude> <exclude>**/some/single/File.java</exclude> </excludes> </configuration> </plugin> </plugins> </build> </profile>

例如:

{{1}}

答案 2 :(得分:2)

<profiles>
    <profile>
        <id>readBuild</id>
        <build>
             <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration >
                    <excludes>
                        <exclude>**/com/pyramid/controllers/EntitlementWriteController.java</exclude>
                        <exclude>**/com/pyramid/controllers/ProductWriteController.java</exclude>
                    </excludes>
                     <testExcludes>
                      <testExclude>**/com/pyramid/controllers/EntitlementWriteControllerTest.java</testExclude>
                       <testExclude>**/com/pyramid/controllers/ProductWriteControllerTest.java</testExclude>
                    </testExcludes>
                </configuration>
            </plugin>
        </plugins>
            <directory>yourDirectory</directory>
        </build>
    </profile>

答案 3 :(得分:0)

非常简单,您无需添加其他插件:

https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html

        <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <excludes>
                        <exclude>application.properties</exclude>
                    </excludes>
                </resource>
            </resources>
        </build>