How to stop Maven from overwriting resource files

纵然是瞬间 提交于 2020-01-13 11:10:13

问题


I have the default maven structure:

main
--java
--resources
--webapp

I see that every mvn compile copies resources even though they were not changed. What should I do to make build copy only changed files?

<build>
         <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

        </plugins>
    </build>
    <dependencies>
        ...
    </dependencies>

    <properties>
        <maven.resources.overwrite>false</maven.resources.overwrite>
    </properties>

Here is the output in debug mode:

[INFO] Using 'cp1252' encoding to copy filtered resources.
[DEBUG] resource with targetPath null
directory C:\core\src\main\resources
excludes []
includes []
[DEBUG] ignoreDelta true
[INFO] Copying 190 resources
[DEBUG] file batch.bat has a filtered file extension
[DEBUG] copy C:\core\src\main\resources\batch.bat to C:\core\target\classes\batch.bat
[DEBUG] file DataObject.hbm.xml has a filtered file extension
[DEBUG] copy C:\core\src\main\resources\com\data\DataObject.hbm.xml to C:\core\target\classes\com\data\DataObject.hbm.xml

回答1:


Use the property -Dmaven.resources.overwrite=false on the Maven command. See the overwrite parameter of the resources:resources goal.

However the documentation mentions this is the default behavior so check if this parameter is set to true somewhere in your project configuration.

EDIT:

As mentioned in the comments, it seems that even though the log indicates copying, in fact the files are not being changed (the timestamps remain the same when maven.resources.overwrite is false).




回答2:


Be aware:

The maven-resources-plugin ignores the overwrite flag if filtering resources is activated.



来源:https://stackoverflow.com/questions/33700877/how-to-stop-maven-from-overwriting-resource-files

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