Gradle模块构建顺序 [英] Gradle Module Build Order

查看:437
本文介绍了Gradle模块构建顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Gradle根项目P,其中有两个子项目P:fooP:bar.自然地,Gradle按照字母顺序构建它们:barfoo.但是,当我在P根目录中说gradle build时,首先需要构建foo.这是因为bar依赖于foo发布到本地Maven存储库的AAR(Android库)工件. barfoo都是此类Android库项目.

I have a Gradle root project P with two subprojects P:foo and P:bar. Naturally, Gradle builds them in alphabetical order: bar, foo. But I need foo to be built first when I say gradle build in the P root directory. This is because bar depends on the AAR (Android library) artifact that foo publishes to the local Maven repository. Both bar and foo are such Android-library projects.

这似乎是一个简单的问题,但我无法弄清楚.我阅读了有关evaluationDependsOn的内容,因此在bar/build.gradle中,我在第一行中说:evaluationDependsOn "foo:". las,这似乎没有任何效果.这个Gradle功能最终会被破坏吗?

This looks like an easy problem, but I can't figure it out. I read about evaluationDependsOn, so in bar/build.gradle, I say in the first line: evaluationDependsOn "foo:". Alas, this does not seem to have any effect. Is this Gradle feature broken in the end?

使用compile project,我可以强制首先构建foo,但是那样会将编译后的类直接添加到bar中,这是我不想要的.

Using compile project, I could enforce foo to be built first, but that would add the compiled classes directly to bar, which I don't want.

所以我被卡住了.我可以将foo重命名为aaa_foo,我所有的问题都将消失,但是我犹豫是否将其称为解决方案.

So I'm stuck. I could rename foo to aaa_foo and all my problems would be gone, but I hesitate to call that a solution.

推荐答案

好的,让我自己回答这个问题.我想我找到了一个不错的解决方案.

Okay, so let me answer this question myself. I think I found a decent solution.

Gradle中的项目依赖项通常用compile project表示,它不仅构建另一个项目,而且还将另一个项目的类添加到当前项目的类路径中.如果只想确保在您之前构建了另一个项目,则可以使用任务依赖项.

A project dependency in Gradle is usally expressed by means of compile project, which not only builds the other project but also adds the other project's classes to the classpath of the current project. If you only want to make sure another project is built before yours, you can use a task dependency.

在我的Android环境中,我说bar/build.gradle

In my Android environment, in bar/build.gradle, I say

preBuild.dependsOn ":foo:build"

一切都很好.现在,foo始终在bar之前构建.

and all is well. Now foo is always built before bar.

这篇关于Gradle模块构建顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆