Publish task publishing jar twice gradle version 4.4.1

When I run publish task, my jar is getting uploaded twice.

:ProjectA:generatePomFileForMavenPublication
:ProjectA:publishMavenPublicationToMaven2Repository
Upload ProjectA.jar
Upload ProjectA.jar.sha1
Upload ProjectA.jar.md5
Upload ProjectA.pom
Upload ProjectA.pom.sha1
Upload ProjectA.pom.md5
:ProjectA:publishMavenPublicationToMavenRepository
Upload ProjectA.jar
Upload ProjectA.jar.sha1
Upload ProjectA.jar.md5
Upload ProjectA.pom
Upload ProjectA.pom.sha1
Upload ProjectA.pom.md5

:ProjectA:publish

The publish task depends on all of the remote publishing tasks created. The task output shows the same publication being published to different repositories. This suggests that your build script has configured more than one repository for publishing, even if it’s really the same repository behind the scenes. It’s impossible to help with anything additional as you haven’t shared any of the build script.

Do you know why tasks publishMavenPublicationToMaven2Repository and publishMavenPublicationToMavenRepository are being called?

Both are loading to same repository not different repository.

Adding some of my build.gradle.

project.ext {
		mvnRepoUrl = (System.properties["org.gradle.project.version"] != null) ? 
				'https://company.com/nexus/content/repositories/releases/' :
				'https://company.com/nexus/content/repositories/snapshots/'
				
		repoUsername = "user"
		repoPassword = "password"
	}

publishing{
    publications{
        maven(MavenPublication){
            from components.java
        }
    }
      repositories{
        maven{
            url "$project.ext.mvnRepoUrl"
              credentials {
                username = "$project.ext.repoUsername"
                password = "$project.ext.repoPassword"
            }
        }
    }

}

The publish task is a lifecycle task. It doesn’t actually publish anything, but has a dependency on each publishing task created by the maven-publish plugin. If you run publish, you are requesting for ALL remote publishing tasks to be executed.

Nothing stops you from creating multiple repositories in the domain model that are really the same physical repository. The code added from your build.gradle only contains one repository and there is only one remote publishing task created if used in isolation. The code that’s creating the second repository may be in a different section of the build.gradle (or a plugin, init script, etc.).

If you want to use the publish lifecycle task that publishes everything instead of just specifying the one publishing task that you want (i.e. publishMavenPublicationToMavenRepository), you will need to identify where the additional repository is created.

Thank you for your help.