Predefined closure unknown in buildscript block

Hello,

this build-script source will raise this error: > Could not find property ‘reposClosure’ on repository container. (All properties for the reposClosure are dfined in gradle.properties.)

What is the reason for that?

apply plugin: ‘java’ apply plugin: ‘maven’

def reposClosure = {credentials {

username “${nexusUser}”

password “${nexusPassword}”

}

url “http://$nexusServer:$nexusPort/nexus/content/groups/public”

}

buildscript {

repositories {

maven(reposClosure)

}

dependencies {

classpath(group: ‘net.sf.proguard’, name: ‘proguard-gradle’,

version: ‘4.9’)

} }

Regards, Schoppi

You run into a scoping issue with your custom closure. You might want to set the delegate of the closure manually to project or you just change your code snippet

...
def reposClosure = {credentials {
     username "${project.nexusUser}"
     password "${project.nexusPassword}"
 }
 ...

cheers, René

The ‘buildscript’ block contains information necessary to evaluate (even compile) the (rest of the) build script. Therefore it gets evaluated before, and separate from, the rest of the build script. It can’t see the rest of the build script, but the rest of the build script can see it. Hence you’ll have to turn things around. Alternatively, something like ‘repositories.add(buildscript.repositories[0])’ should also work.

Thank you for the quick response!

@Peter, your solution works

@Renè: Your suggestion doesn’t work, maybe I understood it wrong.

Regards, Schoppi

@schoppi sorry, my fault. I missed the fact that you try to configure buildscript here.

cheers, René