46

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?

Cheetah
  • 13,785
  • 31
  • 106
  • 190

4 Answers4

66

Instead try:

<exclude>scripts/**</exclude>

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

src/main/resources/src/main/resources/scripts
Robert Scholte
  • 11,889
  • 2
  • 35
  • 44
  • 2
    Thanks for the suggestion but this doesn't seem to work for me. – Cheetah Aug 12 '14 at 11:18
  • 3
    Did you do a `mvn clean` first? Btw, it has no effect on the manven-compiler-plugin, which only compiles .java files. The maven-resources-plugin is responsible for copying these files to the classpath. – Robert Scholte Aug 12 '14 at 11:21
  • 4
    http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html gives you proper examples. `**` only matches the directories, in case of files, I'd expect it to be `scripts/**/*` – Robert Scholte Aug 12 '14 at 12:29
  • Again, no joy. I am doing a `mvn clean`, then a `mvn compile`. – Cheetah Aug 12 '14 at 14:06
  • please execute `mvn clean process-resources -X` and pastebin.com the results? – Robert Scholte Aug 12 '14 at 14:11
  • 7
    You're going to think I am an idiot...I was looking at the wrong project entirely...your suggestion works. Thanks – Cheetah Aug 13 '14 at 19:07
9

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>
Community
  • 1
  • 1
codemonkey
  • 121
  • 1
  • 2
7
<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>

kumar
  • 441
  • 4
  • 9
6

It's so very simple and you not need add other plugin:

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>
Israel Perales
  • 2,192
  • 2
  • 25
  • 30
  • Sorry, you completely misunderstood what question was about.. – Pawel Feb 16 '22 at 15:01
  • i have two up votes – Israel Perales Feb 16 '22 at 19:46
  • This should actually be the correct and accepted answer. If you want to exclude folders/ files from the resources folder, you use the maven-resources-plugin for this. See https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html for a full reference. – Walnussbär Feb 07 '23 at 10:57