ARTIFACTORY: How to fix 'Maven deploy tries to upload source jars twice' error

Products
Frog_Artifactory
Content Type
Use_Case
AuthorFullName__c
Jian Sun
articleNumber
000006665
FirstPublishedDate
2025-10-20T12:11:08Z
lastModifiedDate
2025-10-20

ARTIFACTORY: How to fix 'Maven deploy tries to upload source jars twice' error

Description 

Sometimes, when employing the mvn deploy command to upload files to JFrog Artifactory, the sources.jar file may be uploaded twice, resulting in 403 Forbidden errors.
Uploading to snapshots: https://demo.jfrogchina.com/artifactory/j-maven-local/org/jfrog/test/multi1/3.7-SNAPSHOT/multi1-3.7-20250825.085147-110-sources.jar
Uploaded to snapshots: https://demo.jfrogchina.com/artifactory/j-maven-local/org/jfrog/test/multi1/3.7-SNAPSHOT/multi1-3.7-20250825.085147-110-sources.jar (812 B at 762 B/s)
Uploading to snapshots: https://demo.jfrogchina.com/artifactory/j-maven-local/org/jfrog/test/multi1/3.7-SNAPSHOT/multi1-3.7-20250825.085147-110-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  51.877 s
[INFO] Finished at: 2025-08-25T16:51:56+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project multi1: Failed to deploy artifacts: Could not transfer artifact org.jfrog.test:multi1:jar:sources:3.7-20250825.085147-110 from/to snapshots (https://demo.jfrogchina.com/artifactory/j-maven-local): Authorization failed for https://demo.jfrogchina.com/artifactory/j-maven-local/org/jfrog/test/multi1/3.7-SNAPSHOT/multi1-3.7-20250825.085147-110-sources.jar 403 Forbidden -> [Help 1]
[ERROR]
Root Cause 
  1. 403 Forbidden - The first uploading is successful, and the second uploading fails due to the permission configuration - the user is not allowed to Delete/Overwrite the artifacts on the repository.
  2. Uploading twice - The root cause is the sources.jar is uploaded twice, due to the `maven-source-plugin` configuration being duplicated in the parent’s pom and the child’s pom.
The steps to reproduce the uploading twice issue:  
### 1. Navigate to Project Directory
```sh
wget https://github.com/jfrog/project-examples/archive/refs/heads/master.zip
unzip project-examples-master.zip
cd maven-examples/maven-example
```
### 2. Modify POM Files
**Parent POM Configuration:**
```xml
<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-sources-parent</id>
            <phase>install</phase>
            <goals>
              <goal>jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </pluginManagement>
</build>
```
**Child Module Configuration: multi1/pom.xml** 
```xml
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-source-plugin</artifactId>
      <executions>
        <execution>
          <id>attach-sources</id>
          <phase>install</phase>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
```
### 3. Execute Maven Deploy
```sh
# Environment: JDK 11, Maven 3.6.3 / 3.3.9
mvn clean deploy -s settings.xml -pl multi1 -Pdev,prod|grep  'Uploading.*sources.jar'
```

**Duplicate Upload**
```sh
Uploading to snapshots: .../multi1-3.7-20250825.085147-110-sources.jar
Uploading to snapshots: .../multi1-3.7-20250825.085147-110-sources.jar
```
Other similar issue cases: there are other configure sections may cause duplicated uploads:

User-added image 

Resolution  
1. How to fix the Artifactory 403 Forbidden issue?
- Grant the user/group to have 'Delete/Overwrite' permission on the repository where the artifacts are uploaded to .

2. How to resolve the issue of uploading source jars twice?
- Solution 1: Upgrade Maven from 3.3.9/3.6.3 to 3.9.x to fix the issue completely.
- Solution 2: Delete the `maven-source-plugin` configuration entirely in the child modules/profiles and only keep it in the parent POM's `pluginManagement` section, to avoid the duplicate configurations.