# ConfigSlurper and subprojects

**URL:** <https://discuss.gradle.org/t/configslurper-and-subprojects/4724>\
**Category:** Old Forum Archive\
**Created:** [June 6, 2013, 9:56am UTC](https://discuss.gradle.org/t/configslurper-and-subprojects/4724 "2013-06-06T09:56:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sion\_Williams1](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@Sion\_Williams1](https://discuss.gradle.org/u/Sion_Williams1)\
**Post date:** [June 6, 2013, 9:56am UTC](https://discuss.gradle.org/t/configslurper-and-subprojects/4724/1 "2013-06-06T09:56:00Z")

</div>

I have a scenario where I want to slurp all of my config from an env.groovy file. To do that I have this task:

```gradle
ext{
 configFile = file('env.groovy')
}
  task configEnv << {
  def environment = "$env"
 project.ext.environement = "environment"
    project.ext.config = new ConfigSlurper(environment).parse(configFile.toURL())
 logger.lifecycle "Environment is set to $environment"
}

```

This works great when I only have a single project and pass in -Penv=local

I would like to extend this to my subprojects, and so set a dependsOn flag:

Parent build.gradle

```gradle
subprojects {
 ext.configFile = file('env.groovy')
     task migrateDB(dependsOn: 'configEnv') << {
  mkdir('build/sql')
  ant.taskdef(name: 'dbdeploy',
      classname: 'com.dbdeploy.AntTarget',
      classpath: (configurations.dbdeploy + configurations.ora).asPath)
  ant.dbdeploy(driver: "oracle.jdbc.OracleDriver",
       url: "jdbc:oracle:thin:@localhost:1521/$dbsid",
       userid: "$dbaUsername",
       password: "$dbaPassword",
       dir: "$dbddl",
       dbms: "ora",
       outputfile: "$buildDir/sql/run.sql")
     }
    task configEnv << {
   def environment = "$env"
  project.ext.environement = "environment"
     project.ext.config = new ConfigSlurper(environment).parse(configFile.toURL())
  logger.lifecycle "Environment is set to $environment"
 }
}

```

and the children using this config:

```gradle
migrateDB{
 ext.dbaUsername = $config.db.krill.user
 ext.dbaPassword = $config.db.krill.password
 ext.dbddl = "sql/running_orders"
 ext.dbsid = $config.db.krill.sid
}

```

Finally the env.groovy:

```gradle
environments {
     local {
         serverName = 'localVM'
  db {
    krill{
    sid = 'orcl'
    user = 'krill'
     password = 'krill'
        }
    }
 }

```

The problem is:

```gradle
$ ./gradlew migrateDB -Penv=local
  FAILURE: Build failed with an exception.
  * Where:
Build file '/media/sf_vm_shared/water/krill/build.gradle' line: 4
  * What went wrong:
A problem occurred evaluating project ':krill'.
> Could not find property '$config' on task ':krill:migrateDB'.
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  BUILD FAILED
  Total time: 3.023 secs

```

---

<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:** [June 6, 2013, 1:46pm UTC](https://discuss.gradle.org/t/configslurper-and-subprojects/4724/2 "2013-06-06T13:46:00Z")

</div>

The ‘configEnv’ task sets the ‘config’ extra property when it executes, that is in the _execution phase_. The subproject is trying to access the property in the _configuration phase_, which comes before the execution phase. One solution is to move property accesses into the execution phase by replacing ‘migrateDb { …}’ with ‘migrateDb.doFirst { … }’.

---

<div class="post-metadata">

**Author:** ![Sion\_Williams1](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@Sion\_Williams1](https://discuss.gradle.org/u/Sion_Williams1)\
**Post date:** [June 7, 2013, 12:22pm UTC](https://discuss.gradle.org/t/configslurper-and-subprojects/4724/3 "2013-06-07T12:22:00Z")

</div>

Thank you very much, Peter. You are teaching me a lot 🙂
