Maven - exclude folder from build

点点圈 提交于 2019-11-26 07:44:30

问题


Trying to exlcude a folder src/main/resources/scripts/ from my build but the following does not work:

<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>

Any ideas?


回答1:


Instead try:

<exclude>scripts/**</exclude>

The exclude is based on directory, so your construction would exclude

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



回答2:


I had a similar problem and found the following issues:

  • You may have a parent pom which already defines a configuration for the maven-compiler-plugin. For this, add combine.self="override" to the configuration tag. See Maven : Is it possible to override the configuration of a plugin already defined for a profile in a parent POM
  • It seems the plugin ignores excludes if it needs the excluded classes for the compilation: make sure you are not referencing the excluded classes from other classes which will get compiled. For example, if you exclude Foo.java, but in Bar.java you import Foo; it will (try to) compile Foo.java to compile Bar.java.

For example:

<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>



回答3:


<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>



来源:https://stackoverflow.com/questions/25262794/maven-exclude-folder-from-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!