src/main/java/org/fuin/srcgen4j/core/base/GeneratedFile.java
public final void persist() {

        if (persisted) {
            // Do nothing if already done
            return;
        }

        try {

            // Compare new and old file
            if (FileUtils.contentEquals(tmpFile, file)) {
                LOG.debug("Omitted: {} {}", getPath(), logInfo);
                if (!tmpFile.delete()) {
                    tmpFile.deleteOnExit();
                }
            } else {
                if (file.exists() && !file.delete()) {
                    throw new IOException("Wasn't able to delete file " + file);
                }
                if (!tmpFile.renameTo(file)) {
                    throw new IOException("Wasn't able to rename temporary file " + tmpFile + " to " + file);
                }
                LOG.info("Generated: {} {}", getPath(), logInfo);
            }

            persisted = true;

        } catch (final IOException ex) {
            throw new RuntimeException("Error comparing content: tmp=" + tmpFile + ", target=" + file + logInfo, ex);
        }

    }
public final void persist() {

        if (persisted) {
            // Do nothing if already done
            return;
        }

        try {

            // Compare new and old file
            if (FileUtils.contentEquals(tmpFile, file)) {
                LOG.debug("Omitted: {} {}", getPath(), logInfo);
                if (!tmpFile.delete()) {
                    tmpFile.deleteOnExit();
                }
            } else {
                if (file.exists() && !file.delete()) {
                    throw new IOException("Wasn't able to delete file " + file);
                }
                if (!tmpFile.renameTo(file)) {
                    throw new IOException("Wasn't able to rename temporary file " + tmpFile + " to " + file);
                }
                LOG.info("Generated: {} {}", getPath(), logInfo);
            }

            persisted = true;

        } catch (final IOException ex) {
            throw new RuntimeException("Error comparing content: tmp=" + tmpFile + ", target=" + file + logInfo, ex);
        }

    }
Compares the content of the temporary file with the possibly existing target file. If both are equal the temporary file is deleted.
Otherwise the old target file is deleted and the new generated file is renamed. This prevents time stamp changes for the target file
if nothing changed since the last generation.