code: private boolean copyArtifactIfRequired(Artifact artifactToCopy, Path destinationDirectory) throws MojoExecutionException {
          for (String ignoredArtifact : ignoredArtifacts) {
              Artifact artifactToIgnore = getArtifactResult(new DefaultArtifact(ignoredArtifact));
              if (artifactToCopy.getFile().getName().equals(artifactToIgnore.getFile().getName())) {
                  getLog().debug(artifactToCopy.getFile().getName() + " has not been copied over because it is in the ignore list.");
                  return false;
              }
          }
          try {
              for (Iterator<Artifact> iterator = copiedArtifacts.iterator(); iterator.hasNext(); ) {
                  Artifact alreadyCopiedArtifact = iterator.next();
                  if (artifactsAreMatchingTypes(alreadyCopiedArtifact, artifactToCopy)) {
                      if (isArtifactIsOlderThanArtifact(alreadyCopiedArtifact, artifactToCopy)) {
                          Path artifactToDelete = Paths.get(destinationDirectory.toString(), alreadyCopiedArtifact.getFile().getName());
                          getLog().debug(String.format("Deleting file:'%s'", artifactToDelete));
                          // We delete the old artifact and remove it from the list of copied artifacts, the new artifact will be copied below
                          Files.deleteIfExists(artifactToDelete);
                          iterator.remove();
                          break;
                      } else {
                          return false;
                      }
                  }
              }
              Path desiredArtifact = Paths.get(destinationDirectory.toString(), artifactToCopy.getFile().getName());
              if (!desiredArtifact.toFile().exists()) {
                  getLog().debug(String.format("Copying: %s to %s", desiredArtifact.toString(), destinationDirectory.toString()));
                  Files.copy(Paths.get(artifactToCopy.getFile().getAbsolutePath()), desiredArtifact);
              }
          } catch (IOException | InvalidVersionSpecificationException e) {
              throw new MojoExecutionException(e.getMessage(), e);
          }
          copiedArtifacts.add(artifactToCopy);
  
          return true;
      }
docs: Copy an Artifact to a directory
  
  @param artifactToCopy       Artifact that needs to be copied.
  @param destinationDirectory Directory to copy the artifact to
  @return true if artifact copied, false if artifact not copied
  @throws MojoExecutionException Unable to copy file or resolve dependency, or unable to find artifact or unable to parse Artifact version