Bogus file copy for onlyIfModified=true

Open
#684 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@arturobernalg is already working on this.

Since Nov 19, 2026.

  • #690 by @arturobernalg — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
65/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
java
Domain
build-system

Research direction

Start with AbstractWarPackagingTask.copyFile, which the issue identifies as comparing the source and destination modification times when onlyIfModified is true. Check the existing tests for this copy behavior and reproduce the case with files whose contents differ but modification times match. Done when changed content is copied despite equal timestamps and the relevant tests pass.

Written by the indexing model from the issue text.

Description

bug
Affected version

3.5.1, possibly others

Bug description

While analysing a weird race-condition during WAR packaging, I might have discovered the responsible cause.

Symptom: On some builds, the WAR is badly packaged because modified files are not copied from the overlay to the target directory.
This seems to happen, when the overlay file has the same modify time as the target, although having been changed in the build process.

Analysis showed, that the modified overlay file is sometimes not copied, because the modification time is the same as the target file, although the file content differs.
Digging deeper revealed, that the modification timestamp has a granularity of 1 sec on the underlying filesystem (Apple HFS). So when the file modification and packaging actually run within a second, the file copy might be surpressed!

Responsible for that seems this method in AbstractWarPackagingTask:

protected boolean copyFile(
            WarPackagingContext context, File source, File destination, String targetFilename, boolean onlyIfModified)
            throws IOException {
        context.addResource(targetFilename);

        BasicFileAttributes readAttributes = Files.readAttributes(source.toPath(), BasicFileAttributes.class);
        if (onlyIfModified
                && destination.lastModified()
                        >= readAttributes.lastModifiedTime().toMillis()) {
            context.getLog().debug(" * " + targetFilename + " is up to date.");
            return false;
        } else {
...

Although the lastModifiedTime attribute is compared in millis, it effectively only compares in seconds, when the underlying FS hasn't that granularity. This even disregards a difference in file size.

Dominant language
Java
Stars
48
Forks
103
Avg merge
11h 20m
Merged PRs (30d)
15

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/maven-war-plugin

All issues in apache/maven-war-plugin

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.