You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2026/10/13 21:31:50 UTC
(maven-dependency-plugin) branch agent/mdep-458-classifier-overwrite created (now 05756c8c)
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a change to branch agent/mdep-458-classifier-overwrite
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
at 05756c8c [MDEP-458] Skip classifier-translated artifacts that are already up to date
This branch includes the following new commits:
new 05756c8c [MDEP-458] Skip classifier-translated artifacts that are already up to date
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-dependency-plugin) 01/01: [MDEP-458] Skip classifier-translated artifacts that are already up to date
Posted by sl...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch agent/mdep-458-classifier-overwrite
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit 05756c8c606381cc05ac6acb71106908719faac0
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Tue Oct 13 23:26:39 2026 +0200
[MDEP-458] Skip classifier-translated artifacts that are already up to date
---
.../invoker.properties | 18 ++++++
.../projects/mdep-458-classifier-overwrite/pom.xml | 67 ++++++++++++++++++++++
.../mdep-458-classifier-overwrite/verify.groovy | 28 +++++++++
.../AbstractDependencyFilterMojo.java | 12 ++--
.../fromDependencies/TestCopyDependenciesMojo.java | 35 +++++++++++
5 files changed, 154 insertions(+), 6 deletions(-)
diff --git a/src/it/projects/mdep-458-classifier-overwrite/invoker.properties b/src/it/projects/mdep-458-classifier-overwrite/invoker.properties
new file mode 100644
index 00000000..101be4e9
--- /dev/null
+++ b/src/it/projects/mdep-458-classifier-overwrite/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = clean process-sources
diff --git a/src/it/projects/mdep-458-classifier-overwrite/pom.xml b/src/it/projects/mdep-458-classifier-overwrite/pom.xml
new file mode 100644
index 00000000..c481b8b7
--- /dev/null
+++ b/src/it/projects/mdep-458-classifier-overwrite/pom.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>mdep-458-classifier-overwrite</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <description>copy-dependencies with a classifier must not overwrite a file that is already up to date (MDEP-458).</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>ResourceArtifact</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <id>first</id>
+ <phase>process-sources</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <classifier>client</classifier>
+ </configuration>
+ </execution>
+ <execution>
+ <id>second</id>
+ <phase>process-sources</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <classifier>client</classifier>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/projects/mdep-458-classifier-overwrite/verify.groovy b/src/it/projects/mdep-458-classifier-overwrite/verify.groovy
new file mode 100644
index 00000000..0d4f4625
--- /dev/null
+++ b/src/it/projects/mdep-458-classifier-overwrite/verify.groovy
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+assert new File( basedir, 'target/dependency/ResourceArtifact-1.0-client.jar' ).isFile()
+
+String log = new File( basedir, 'build.log' ).text
+assert log.contains( '(first)' ) && log.contains( '(second)' )
+String afterSecond = log.substring( log.indexOf( '(second)' ) )
+assert afterSecond.contains( 'already exists in destination' )
+assert !afterSecond.contains( 'Copying ResourceArtifact-1.0-client.jar' )
+
+return true
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
index a483519a..aa20037d 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
@@ -436,17 +436,17 @@ public abstract class AbstractDependencyFilterMojo extends AbstractDependencyMoj
new ClassifierTypeTranslator(artifactHandlerManager, this.classifier, this.type);
Collection<org.eclipse.aether.artifact.Artifact> coordinates = translator.translate(artifacts, getLog());
- status = filterMarkedDependencies(artifacts);
-
- // the unskipped artifacts are in the resolved set.
- artifacts = status.getResolvedDependencies();
-
- // resolve the rest of the artifacts
+ // resolve the translated artifacts
resolvedArtifacts = resolve(new LinkedHashSet<>(coordinates), stopOnFailure);
// calculate the artifacts not resolved.
unResolvedArtifacts.addAll(artifacts);
unResolvedArtifacts.removeAll(resolvedArtifacts);
+
+ // skip the translated artifacts that are already up to date in the destination: the destination file
+ // name depends on the classifier, so the decision cannot be taken on the original artifacts
+ status = filterMarkedDependencies(resolvedArtifacts);
+ resolvedArtifacts = status.getResolvedDependencies();
}
// return a bean of all 3 sets.
diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java
index 83715c63..31d0ef5f 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java
@@ -437,6 +437,41 @@ class TestCopyDependenciesMojo {
}
}
+ @Test
+ @InjectMojo(goal = "copy-dependencies")
+ void testClassifierDoesNotOverwriteUpToDateFile(CopyDependenciesMojo mojo) throws Exception {
+ mojo.classifier = "jdk14";
+ for (Artifact artifact : mojo.getProject().getArtifacts()) {
+ stubFactory.createArtifact(
+ artifact.getGroupId(),
+ artifact.getArtifactId(),
+ artifact.getVersion(),
+ artifact.getScope(),
+ artifact.getType(),
+ "jdk14");
+ }
+
+ mojo.execute();
+
+ long newer = System.currentTimeMillis() + 3_600_000L;
+ for (Artifact artifact : mojo.getProject().getArtifacts()) {
+ File copied = new File(
+ mojo.outputDirectory,
+ artifact.getArtifactId() + "-" + artifact.getVersion() + "-jdk14." + artifact.getType());
+ assertTrue(copied.exists(), copied.getAbsolutePath());
+ assertTrue(copied.setLastModified(newer));
+ }
+
+ mojo.execute();
+
+ for (Artifact artifact : mojo.getProject().getArtifacts()) {
+ File copied = new File(
+ mojo.outputDirectory,
+ artifact.getArtifactId() + "-" + artifact.getVersion() + "-jdk14." + artifact.getType());
+ assertEquals(newer / 1000, copied.lastModified() / 1000, copied.getName() + " was overwritten");
+ }
+ }
+
@Test
@InjectMojo(goal = "copy-dependencies")
void testSubPerType(CopyDependenciesMojo mojo) throws Exception {