Predefined closure unknown in buildscript block

(Andreas Schopper) #1


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

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 {



dependencies {

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

version: ‘4.9’)

} }

Regards, Schoppi

(René Groeschke) #2

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é

(Peter Niederwieser) #3

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.

(Andreas Schopper) #4

Thank you for the quick response!

@Peter, your solution works

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

Regards, Schoppi

(René Groeschke) #5

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

cheers, René