如何在Gradle子项目中指定配置顺序?

时间:2017-04-15 04:48:49

标签: gradle

settings.gradle是:

rootProject.name = 'snth'

include 'snth-proto-definition'
include 'snth-server'
include 'snth-client-guice'

snth-server/build.gradle有:

sourceSets {
  main {
    java {
      srcDir "${project(':snth-proto-definition').protobuf.generatedFilesBaseDir}/server/java"
    }
  }
}

snth-client/build.gradle有:

sourceSets {
  main {
    java {
      srcDir "${project(':snth-proto-definition').protobuf.generatedFilesBaseDir}/client/java"
    }
  }
}

但是,snth-server-guice/build.gradle处理正常,snth-client-guice/build.gradle错误:

FAILURE: Build failed with an exception.

* Where:
Build file 'snth/snth-client-guice/build.gradle' line: 14

* What went wrong:
A problem occurred evaluating project ':snth-client-guice'.
> Could not find property 'protobuf' on project ':snth-proto-definition'.

如何确保project(':snth-proto-definition').protobuf在使用之前已定义?

1 个答案:

答案 0 :(得分:0)

Configuration time dependencies表示使用evaluationDependsOn可以更精细地控制子模块的配置顺序。例如:

evaluationDependsOn(':snth-proto-definition')