简体   繁体   English

如何在评估子项目之前执行Gradle任务

[英]How to execute a Gradle task before subprojects are evaluated

I've set up a Gradle task to auto generate one of the subprojects of my Gradle build on which another depends (reason for doing this: long story involving Apache Cordova!). 我已经设置了一个Gradle任务来自动生成我的Gradle构建的一个子项目,而另一个子项目取决于(这样做的原因:涉及Apache Cordova的长篇故事!)。 So the root build.gradle contains this autogenerate task that creates a "CordovaLib" sub project. 因此,根build.gradle包含此自动生成任务,该任务创建“CordovaLib”子项目。 The build.gradle in the other sub project (that isn't autogenerated) depends on CordovaLib: 另一个子项目中的build.gradle(不是自动生成的)取决于CordovaLib:

dependencies {
    compile project(':CordovaLib')
}

Is there a way to execute the autogenerate task before the non-generated subproject's build.gradle is evaluated (specifically the above line)? 有没有办法在评估非生成子项目的build.gradle之前执行自动生成任务(特别是上面的行)? I'm using Gradle 1.11 on JDK 1.7 and as it currently stands I can't even run gradle tasks without it failing due to the missing project. 我正在JDK 1.7上使用Gradle 1.11,因为它目前的情况下我甚gradle tasks无法运行gradle tasks而不会因为缺少项目而失败。

You can use init script to gradle to achieve this. 您可以使用init脚本来进行gradle来实现此目的。

https://gradle.org/docs/current/userguide/init_scripts.html https://gradle.org/docs/current/userguide/init_scripts.html

It isn't possible to execute a task before build files have been evaluated, at least not without complications such as one build executing another build using a GradleBuild task. 在评估构建文件之前不可能执行任务,至少不是没有复杂性,例如一个构建使用GradleBuild任务执行另一个构建。 You are likely better off checking the generated project in to source control, or finding a solution that doesn't involve generating build scripts. 您可能最好将生成的项目检入源代码控制,或者找到不涉及生成构建脚本的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM