Build logic for subprojects


(Sion Williams) #1

I’m using the example below where bluewhale and krill are schemas in an oracle database.

water/
  build.gradle
  settings.gradle
  bluewhale/
    build.gradle
  krill/
    build.gradle

I want to set the build logic in the parent build.gradle (water), but inherit different properties from each of the subprojects:

Parent:

subprojects {
   repositories {
  mavenCentral()
 }
   configurations {
   ora
   dbdeploy
 }
   dependencies {
  // oracle db
  ora "com.oracle:ojdbc6:11.2.0.2.0"
      // DB Deploy
  dbdeploy "com.dbdeploy:dbdeploy-parent:3.0M3"
 }
    migrateDB << {
   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/orcl",
       userid: $dbaUsername,
       password: $dbaPassword,
       dir: $dbddl)
 }
}

Child:

task migrateDB.doFirst{
  project.ext.dbaUsername = "krill"
  project.ext.dbaPassword = "krill"
  project.ext.dbddl = "krill/src/main/sql/ddl"
}

But I get the following error:

$ ./gradlew :krill:migrateDB --s
The Project.childrenDependOnMe() method has been deprecated and is scheduled to be removed in Gradle 2.0.
  FAILURE: Build failed with an exception.
  * Where:
Build file '/media/sf_vm_shared/water/build.gradle' line: 27
  * What went wrong:
A problem occurred evaluating root project 'water'.
> Could not find property 'migrateDB' on project ':bluewhale'.
  * Try:
Run with --info or --debug option to get more log output.
  * Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'water'.
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127)
        at org.gradle.configuration.BuildScriptProcessor.execute(BuildScriptProcessor.java:36)
        at org.gradle.configuration.BuildScriptProcessor.execute(BuildScriptProcessor.java:23)
        at org.gradle.configuration.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
        at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
        at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:465)
        at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:76)
        at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:31)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
        at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:48)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.Main.main(Main.java:39)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: groovy.lang.MissingPropertyException: Could not find property 'migrateDB' on project ':bluewhale'.
        at org.gradle.api.internal.AbstractDynamicObject.propertyMissingException(AbstractDynamicObject.java:43)
        at org.gradle.api.internal.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:35)
        at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeDynamicObject.java:94)
        at org.gradle.api.internal.project.DefaultProject_Decorated.getProperty(Unknown Source)
        at build_5cio0n6q7s1tsj9kta5u4ea53a$_run_closure5.doCall(/media/sf_vm_shared/water/build.gradle:27)
        at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:58)
        at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:133)
        at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:94)
        at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:853)
        at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:858)
        at org.gradle.api.internal.project.AbstractProject.subprojects(AbstractProject.java:841)
        at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)
        at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)
        at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
        at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:83)
        at build_5cio0n6q7s1tsj9kta5u4ea53a.run(/media/sf_vm_shared/water/build.gradle:26)
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
        ... 33 more
    BUILD FAILED

As per normal I’m sure this is something I am doing wrong, but any help would be greatly appreciated.


(Peter Niederwieser) #2

The task has to be introduced by the parent. Hence replace ‘migrateDb <<’ with ‘task migrateDb <<’. Also, the children should just configure the task, and should declare extra properties for the task (not the project). Hence:

migrateDB {
  ext.dbaUsername = "krill"
  ext.dbaPassword = "krill"
  ext.dbddl = "krill/src/main/sql/ddl"
}

(Sion Williams) #3

Thank you very much. This has fixed my problem :slight_smile:


(Sion Williams) #4

One additional note is that I didnt need to put the krill directory in the path as the task executed relative to the krill project, not water.

migrateDB {
  ext.dbaUsername = "krill"
  ext.dbaPassword = "krill"
  ext.dbddl = "src/main/sql/ddl"
}