【问题标题】:Maven - exclude folder from buildMaven - 从构建中排除文件夹
【发布时间】:2014-10-05 10:24:17
【问题描述】:

尝试从我的构建中排除文件夹 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>

有什么想法吗?

【问题讨论】:

    标签: maven maven-compiler-plugin


    【解决方案1】:

    改为尝试:

    <exclude>scripts/**</exclude>
    

    排除是基于目录的,所以你的构造会排除

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

    【讨论】:

    • 感谢您的建议,但这似乎对我不起作用。
    • 你先做了mvn clean吗?顺便说一句,它对仅编译 .java 文件的 manven-compiler-plugin 没有影响。 maven-resources-plugin 负责将这些文件复制到类路径中。
    • maven.apache.org/plugins/maven-resources-plugin/examples/… 为您提供了适当的示例。 ** 只匹配目录,如果是文件,我希望它是 scripts/**/*
    • 再一次,没有喜悦。我正在做一个mvn clean,然后是一个mvn compile
    • 你会认为我是个白痴......我完全看错了项目......你的建议有效。谢谢
    【解决方案2】:

    我遇到了类似的问题,发现如下问题:

    例如:

    <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.6.0 版本中排除单个文件对我不起作用
    • 这会在当前版本的 maven 和插件上产生构建错误
    • 我的 pom 没有 excludes 节点。在这个答案中,在上下文中查看 sn-p 很有帮助。
    【解决方案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>
    

    【讨论】:

    • 在阅读了一个有 40 多票的问题后,我终于找到了一个可行的问题(The Kumar)!谢谢!
    【解决方案4】:

    非常简单,不需要添加其他插件:

    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>
    

    【讨论】:

      猜你喜欢
      • 2017-12-28
      • 2017-07-13
      • 1970-01-01
      • 2014-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      相关资源
      最近更新 更多