Custom distribution name from subproject name

Hi,

I am pretty new to gradle and after doing good amount searching - posting it here.
In a multi-project build, I am trying to apply distributions to all sub-projects and the custom distribution name should be same as the subproject. But i am having issues figuring out a way to do it. Below is how I was trying

Project Structure:
rootProject
- subProject1
- subSubProject1
- subSubProject2
- subProject2

Inside subProject1 build.gradle - I am tying below code

subprojects {
    apply plugin: 'distribution'

    tasks.withType(Tar) {
        compression = Compression.GZIP
        extension = 'tar.gz'
    }

    def distName = it.name
    def distNameWithResources = it.name + 'WithResources'
    distributions {
        distName {
            contents {
                into('') {
                    from("somefile.sh")
                    fileMode 0755
                }
            }
        }
        distNameWithResources {
            contents {
                into('resources') {
                    from tarTree("${rootDir}/resources/resources.tar.gz")
                }
                into('') {
                    from("somefile.sh")
                    fileMode 0755
                }
            }
        }
    }
}

But when i try this - I get below error

* What went wrong:
A problem occurred evaluating project ':subProject1'.
> No signature of method: java.lang.String.call() is applicable for argument types: (build_4lwtu0zhwpisgjzqhmd10p8kj$_run_closure1$_closure7$_closure8) values: [build_4lwtu0zhwpisgjzqhmd10p8kj$_run_closure1$_closure7$_closure8@7c0f8d06]
  Possible solutions: wait(), chars(), any(), wait(long), take(int), any(groovy.lang.Closure)

Since distName and distNameWithResources are defined variables, Groovy is trying to treat them as a callable that takes a Closure as a parameter. Two ways out of this:

  1. I know it seems weird, but make the distribution names string literals, which will then work with Gradle’s DSL magic:

     distributions {
         "${distName}" {
             ...
         }
         "${distNameWithResources}" {
             ...
         }
     }
    
  2. Use the distrbution container’s create method:

     distributions.create( distName ) {
         ...
     }
     distributions.create( distNameWithResources ) {
         ...
     }

Thanks for the response - I have tried first option above and it works for me. Thanks again.