Hello,
I have been using the copy-resources file for copying a configuration file
(log4j2.xml) from a shared source directory to the "target" directory.
<!-- copy log4j2.xml to target dir -->
<resources>
<resource>
<directory>${basedir}/../common/src/main/resources</directory>
<targetPath>${project.build.directory}</targetPath>
<includes>
<include>log4j2.xml</include>
</includes>
</resource>
</resources>
The source log4j2.xml file is under source control. With the source control
system we are using (Perforce), this means it has read-only permissions unless
the user has checked it out for editing.
On the first Maven build, the file will be copied to the target directory as
expected.
Now, a change was done to the source file (usually when the user has retrieved
a new revision from the source repository). A subsequent Maven build will
attempt to replace the file in the target directory, but will fail with:
[INFO] --- maven-resources-plugin:3.3.0:resources (default-resources) @
otcam-config ---
[INFO] Copying 1 resource to C:\testsrc\myprj\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.703 s
[INFO] Finished at: 2022-12-23T09:23:42+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-resources-plugin:3.3.0:resources
(default-resources) on project otcam-config: copying
C:\testsrc\myprj\..\common\src\main\resources\log4j2.xml to
C:\testsrc\myprj\target\log4j2.xml failed with AccessDeniedException:
C:\testsrc\myprj\target\log4j2.xml -> [Help 1]
I see that in 3.2.0, the copy-resources plugin was modified to take over
permissions of the source file when copying (probably in
https://issues.apache.org/jira/browse/MRESOURCES-236 ?). But this has the,
probably unwanted, side effect that read-only files can't be replaced by
subsquent mvn calls anymore without doing a mvn clean.
If I had a Jira account, I would create a bug to get this fixed, either by
allowing read-only files to be replaced by default, or by providing an
additional option.
For now, my workaround is to use version 3.1.0 of the copy-resources plugin,
which creates the target file with write permissions, so subsequent maven
builds have no issues with replacing the file.
Can the behaviour be fixed in a future version of the copy-resources plugin, so
we don't have to stick with the old one? Either by changing the default
behaviour of the copy function to replace readonly files, or by offering
something like a "force replace" option.
Thank you!
Burkhard
[MRESOURCES-236] Copying of files with permissions broken - ASF JIRA - The
Apache Software Foundation<https://issues.apache.org/jira/browse/MRESOURCES-236>
trigger comment-preview_link fieldId comment fieldName Comment rendererType
atlassian-wiki-renderer issueKey MRESOURCES-236 Preview comment
issues.apache.org