# Predefined closure unknown in buildscript block

**URL:** <https://discuss.gradle.org/t/predefined-closure-unknown-in-buildscript-block/6114>\
**Category:** Old Forum Archive\
**Created:** [April 10, 2013, 3:32pm UTC](https://discuss.gradle.org/t/predefined-closure-unknown-in-buildscript-block/6114 "2013-04-10T15:32:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![schoppi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schoppi/32/2182_2.png) [@schoppi](https://discuss.gradle.org/u/schoppi)\
**Post date:** [April 10, 2013, 3:32pm UTC](https://discuss.gradle.org/t/predefined-closure-unknown-in-buildscript-block/6114/1 "2013-04-10T15:32:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [April 10, 2013, 3:37pm UTC](https://discuss.gradle.org/t/predefined-closure-unknown-in-buildscript-block/6114/2 "2013-04-10T15:37:00Z")

</div>

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

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

```

cheers, René

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [April 10, 2013, 3:50pm UTC](https://discuss.gradle.org/t/predefined-closure-unknown-in-buildscript-block/6114/3 "2013-04-10T15:50:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![schoppi](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schoppi/32/2182_2.png) [@schoppi](https://discuss.gradle.org/u/schoppi)\
**Post date:** [April 11, 2013, 6:04am UTC](https://discuss.gradle.org/t/predefined-closure-unknown-in-buildscript-block/6114/4 "2013-04-11T06:04:00Z")

</div>

Thank you for the quick response!

@Peter, your solution works

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

Regards, Schoppi

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [April 11, 2013, 6:17am UTC](https://discuss.gradle.org/t/predefined-closure-unknown-in-buildscript-block/6114/5 "2013-04-11T06:17:00Z")

</div>

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

cheers, René
