[MSOURCES-140] improve message when lifecycle run twice
diff --git a/src/it/MSOURCES-121/invoker.properties b/src/it/MSOURCES-121/invoker.properties
index c43b263..2668a60 100644
--- a/src/it/MSOURCES-121/invoker.properties
+++ b/src/it/MSOURCES-121/invoker.properties
@@ -14,4 +14,4 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-invoker.buildResult = success
+invoker.buildResult = failure
diff --git a/src/it/MSOURCES-121/pom.xml b/src/it/MSOURCES-121/pom.xml
index 26c61ac..975b8c2 100644
--- a/src/it/MSOURCES-121/pom.xml
+++ b/src/it/MSOURCES-121/pom.xml
@@ -57,6 +57,9 @@
             <goals>
               <goal>jar-no-fork</goal>
             </goals>
+            <configuration>
+              <finalName>${project.build.finalName}-secondary</finalName>
+            </configuration>
           </execution>
         </executions>
       </plugin>
diff --git a/src/it/MSOURCES-121/verify.groovy b/src/it/MSOURCES-121/verify.groovy
new file mode 100644
index 0000000..e58ef75
--- /dev/null
+++ b/src/it/MSOURCES-121/verify.groovy
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+File buildLog = new File( basedir, 'build.log' )
+
+assert buildLog.text =~ /\[ERROR\] Artifact org.apache.maven.its.sources:jar-no-fork:java-source:sources:1.0-SNAPSHOT already attached to a file target.jar-no-fork-1.0-SNAPSHOT-sources.jar: attach to target.jar-no-fork-1.0-SNAPSHOT-secondary-sources.jar should be done with another classifier/
diff --git a/src/it/MSOURCES-140/invoker.properties b/src/it/MSOURCES-140/invoker.properties
new file mode 100644
index 0000000..54abe94
--- /dev/null
+++ b/src/it/MSOURCES-140/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.buildResult = success
+invoker.goals = package clean install
diff --git a/src/it/MSOURCES-140/pom.xml b/src/it/MSOURCES-140/pom.xml
new file mode 100644
index 0000000..c22d234
--- /dev/null
+++ b/src/it/MSOURCES-140/pom.xml
@@ -0,0 +1,55 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.sources</groupId>
+  <artifactId>jar-no-fork</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <name>Test for multiple attachments of one file caused by  multiple runs in one session</name>
+  <description>mvn package clean install should not fail</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <goals>
+              <goal>jar-no-fork</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/MSOURCES-140/src/main/java/MyClass.java b/src/it/MSOURCES-140/src/main/java/MyClass.java
new file mode 100644
index 0000000..4945381
--- /dev/null
+++ b/src/it/MSOURCES-140/src/main/java/MyClass.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+public class MyClass
+{
+
+}
diff --git a/src/it/MSOURCES-140/src/main/resources/main.properties b/src/it/MSOURCES-140/src/main/resources/main.properties
new file mode 100644
index 0000000..00ae6c0
--- /dev/null
+++ b/src/it/MSOURCES-140/src/main/resources/main.properties
@@ -0,0 +1,17 @@
+# 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.
+
diff --git a/src/it/MSOURCES-140/src/test/java/MyTest.java b/src/it/MSOURCES-140/src/test/java/MyTest.java
new file mode 100644
index 0000000..9d124be
--- /dev/null
+++ b/src/it/MSOURCES-140/src/test/java/MyTest.java
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+public class MyTest
+{
+
+}
diff --git a/src/it/MSOURCES-140/src/test/resources/test.properties b/src/it/MSOURCES-140/src/test/resources/test.properties
new file mode 100644
index 0000000..00ae6c0
--- /dev/null
+++ b/src/it/MSOURCES-140/src/test/resources/test.properties
@@ -0,0 +1,17 @@
+# 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.
+
diff --git a/src/it/MSOURCES-140/verify.groovy b/src/it/MSOURCES-140/verify.groovy
new file mode 100644
index 0000000..8cc6491
--- /dev/null
+++ b/src/it/MSOURCES-140/verify.groovy
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+File buildLog = new File( basedir, 'build.log' )
+
+assert buildLog.text =~ /\[INFO\] Artifact org.apache.maven.its.sources:jar-no-fork:java-source:sources:1.0-SNAPSHOT already attached to target.jar-no-fork-1.0-SNAPSHOT-sources.jar: ignoring same re-attach \(same artifact, same file\)/
diff --git a/src/main/java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java b/src/main/java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java
index 54d11a5..284d2f1 100644
--- a/src/main/java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java
@@ -20,6 +20,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -306,17 +307,22 @@
             if (attach) {
                 boolean requiresAttach = true;
                 for (Artifact attachedArtifact : project.getAttachedArtifacts()) {
-                    Artifact previouslyAttached = getPreviouslyAttached(attachedArtifact, project, getClassifier());
-                    if (previouslyAttached != null) {
-                        if (!outputFile.equals(previouslyAttached.getFile())) {
-                            getLog().error("Artifact already attached to a file " + previouslyAttached.getFile()
-                                    + ": attach to " + outputFile + " should be done with another classifier");
+                    Artifact previouslyAttachedArtifact =
+                            getPreviouslyAttached(attachedArtifact, project, getClassifier());
+                    if (previouslyAttachedArtifact != null) {
+                        File previouslyAttachedFile = previouslyAttachedArtifact.getFile();
+                        // trying to attache the same file/path or not?
+                        if (!outputFile.equals(previouslyAttachedFile)) {
+                            getLog().error("Artifact " + previouslyAttachedArtifact.getId()
+                                    + " already attached to a file " + relative(previouslyAttachedFile) + ": attach to "
+                                    + relative(outputFile) + " should be done with another classifier");
                             throw new MojoExecutionException("Presumably you have configured maven-source-plugin "
                                     + "to execute twice in your build to different output files. "
                                     + "You have to configure a classifier for at least one of them.");
                         }
                         requiresAttach = false;
-                        getLog().info("Artifact already attached: ignoring re-attach");
+                        getLog().info("Artifact " + previouslyAttachedArtifact.getId() + " already attached to "
+                                + relative(outputFile) + ": ignoring same re-attach (same artifact, same file)");
                     }
                 }
                 if (requiresAttach) {
@@ -330,6 +336,11 @@
         }
     }
 
+    private String relative(File to) {
+        Path basedir = project.getBasedir().getAbsoluteFile().toPath();
+        return basedir.relativize(to.getAbsoluteFile().toPath()).toString();
+    }
+
     private Artifact getPreviouslyAttached(Artifact artifact, MavenProject checkProject, String classifier) {
         return artifact.getType().equals(getType())
                         && artifact.getGroupId().equals(checkProject.getGroupId())