How to determine the deployment url, uploadArchive task will pick at runtime

In the Build.gradle, I have defined uploadArchive task and jar in the project.

jar {
	baseName = 'GradleVersionParam'
}

uploadArchive {
    repositories {
       mavenDeployer {
            repository(url: ReleaseURL) {
                authentication(userName: Username, password: Password)
            }
            snapshotRepository(url: SnapshotURL ) {
                authentication(userName: Username, password: Password)
            }
        }
    }
}

Approach is to do validation pre and post upload, when I am executing uploadArchives, rootname for the project is ‘JAVADEMO’ and baseName is ‘GradleVersionParam’, both are different, so the artifact gets created with baseName. I am not able to be fetch baseName of the artifact in init.gradle at the global level. We have applications running on v4.1 to v6.5 of Gradle. So expectation is run init.gradle for all Gradle verions

projectsEvaluated {

    rootProject.allprojects {
    
   Upload uploadTask = (Upload) project.tasks.uploadArchives;

    gradle.addListener(new TaskExecutionListener() {

    void beforeExecute(Task task) {
if (task.name.matches("publish.*PublicationTo.*Repository") ) {
                        def publication = task.publicationInternal
                        println("Remote => $publication.artifactId $publication.groupId $publication.version  $task.repository.url")
                        groupId = "$publication.groupId"
                        artifactId = "$publication.artifactId"
                        version = "$publication.version"
                        repoURL = "$task.repository.url"
                    }

                    if (task.name.matches("uploadArchives")) {
                        uploadTask.repositories.mavenDeployer {
                            if ( pom.getGroupId() != 'unknown' ){
                                groupId = pom.getGroupId()
                            }
                            println("pom.getArtifactId()--->"+pom.getArtifactId())
                            if ( pom.getArtifactId() != 'empty-project' ) {
                                artifactId = pom.getArtifactId()
                            }
                            println("pom.getVersion--->"+pom.getVersion())
                            if ( pom.getVersion() != '0') {
                                version = pom.getVersion()
                            }

                            if ( version.contains('SNAPSHOT') ) {
                                repoURL = snapshotRepository.url
                            } else {
                                repoURL = repository.url
                            }
                        }
                    }
             }
                void afterExecute(Task task, TaskState state) {
              }
      }
}

I am not able fetch the configuration details of the uploadArchives task just before the execution time like Artifactname, version, groupId and the url where it is getting uploaded.

Expected values to fetch before the uploadArchives task execution :

ArtifactID
GroupID
version
Url

Can you please assist.