This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 87ff342a16020736e92666cf7dd94f54a3af6d2b
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Mon Dec 15 12:20:38 2025 +0100

    Use hard links of artifact files in project local repository instead of 
copying the files (#11550)
    If the hard link cannot be created, fallback on a copy as before.
---
 .../main/java/org/apache/maven/ReactorReader.java  | 36 ++++++++++++++++------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java 
b/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java
index fdca07ee80..db4882e386 100644
--- a/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java
+++ b/impl/maven-core/src/main/java/org/apache/maven/ReactorReader.java
@@ -453,15 +453,29 @@ private void installIntoProjectLocalRepository(Artifact 
artifact) {
         Path target = getArtifactPath(
                 artifact.getGroupId(), artifact.getArtifactId(), 
artifact.getVersion(), classifier, extension);
         try {
-            LOGGER.info("Copying {} to project local repository", artifact);
-            Files.createDirectories(target.getParent());
-            Files.copy(
-                    artifact.getPath(),
-                    target,
-                    StandardCopyOption.REPLACE_EXISTING,
-                    StandardCopyOption.COPY_ATTRIBUTES);
+            // Log nothing as creating links should be very fast.
+            Path source = artifact.getPath();
+            if (!(Files.isRegularFile(target) && Files.isSameFile(source, 
target))) {
+                Files.createDirectories(target.getParent());
+                try {
+                    Files.deleteIfExists(target);
+                    Files.createLink(target, source);
+                } catch (UnsupportedOperationException | IOException 
suppressed) {
+                    LOGGER.info("Copying {} to project local repository.", 
artifact);
+                    try {
+                        Files.copy(
+                                source,
+                                target,
+                                StandardCopyOption.REPLACE_EXISTING,
+                                StandardCopyOption.COPY_ATTRIBUTES);
+                    } catch (IOException e) {
+                        e.addSuppressed(suppressed);
+                        throw e;
+                    }
+                }
+            }
         } catch (IOException e) {
-            LOGGER.error("Error while copying artifact to project local 
repository", e);
+            LOGGER.error("Error while copying artifact " + artifact + " to 
project local repository.", e);
         }
     }
 
@@ -481,9 +495,11 @@ private Path getArtifactPath(
                 .resolve(artifactId)
                 .resolve(version)
                 .resolve(artifactId
-                        + "-" + version
+                        + '-'
+                        + version
                         + (classifier != null && !classifier.isEmpty() ? "-" + 
classifier : "")
-                        + "." + extension);
+                        + '.'
+                        + extension);
     }
 
     private Path getProjectLocalRepo() {

Reply via email to