For the multi-project build, UploadArchives task at sub-proj level is failing

I am trying to fetch repository URL for some validation purpose in init.gradle script before uploadArchives task is getting executed. I can see repository object results to NULL before executing `:sub-project:uploadArchives" task. So try to store url which I get from the root-project. But still getting below error

Running uploadArchives task

./gradlew -PSnapshotURL=https://xxxxxxxxxxx/snapshots -PReleaseURL=https://xxxxxxxxxxx/releases build uploadArchives


Execution failed for task ':sub-project:uploadArchives'.
> Could not publish configuration 'archives'
   > Must specify a repository for deployment

If init.gradle is not executed, then multi-project uploads works fine for all sub-projects. Am I missing anything in below init.gradle script, I am not modifying anything except reading property values at run-time through init.gradle script.

gradle.addListener(new TaskExecutionListener() {
//The listener is notified of events which occur during the execution of the build.
    def groupId = ""
    def artifactId = ""
    def version = ""
    def gav = ""
    def slurper = new groovy.json.JsonSlurper()
    def result = ""

    void beforeExecute(Task task) {
    //This method is called immediately before a task is executed.
        Project project = task.getProject()
        groupId =
        artifactId =
        version = project.version
        Upload uploadTask = project.getTasks().withType(Upload.class).findByName("uploadArchives")

        // match if the task name is 'uploadArchives' from "maven" plugin
        // check for uploadTask is not NULL. In rootprojects, uploadArchives task outputs might not be defined.
        if ("uploadArchives") && uploadTask != null ) {

            uploadTask.repositories.mavenDeployer {
                if ( pom.getGroupId() != 'unknown' ){
                    groupId = pom.getGroupId()

                if ( pom.getArtifactId() != 'empty-project' ) {
                    artifactId = pom.getArtifactId()

                if ( pom.getVersion() != '0') {
                    version = pom.getVersion()
                def versionStr=version.toString()
                if ( versionStr.contains('SNAPSHOT') ) {
                    if (snapshotRepository) {
                        println("snapshotRepository.url -->"+snapshotRepository.url)
                        repoURL = snapshotRepository.url
                    else {

                } else {
                    if (repository) {
                        println("repository.url -->"+repository.url)
                        repoURL = repository.url
                    else {


Hi @Andreas Axelsson , I can see you have answered question related to uploadArchive task before. Can you please help here

Issue was resolved by checking the uploadTask.repositories array is empty or not