Gradle仅构建一个模块

我有一个多模块的Gradle构建。我想使用root执行一个模块的目标。 例如:

gradle build -Pmodule=ABC
gradle jar -Pmodule=ABC
gradle test -Pmodule=ABC
gradle compileJava -Pmodule=ABC
gradle customTask -Pmodule=ABC
etc.

因此,每个目标都可以从指定模块的根运行。 有没有一个简单的方法可以做到这一点?

谢谢!

134289 次浏览

Found a quick way

gradle build -p moduleA

moduleA is the module's directory.

Above command builds a moduleA and all its submodules, and moduleA should be its path

To execute a task of a specific subproject, specify its task path. For example:

gradle :ABC:build

The leading : stands for the root project. ABC is the subproject, and build a task in that project.

enter image description here

If your IDE is Android Studio ,there is a simple way.Just choose the module folder you want to compile ,then click Build and choose Make Module 'your module folder'.

On Mac OS, the only variant which is working with me :

./gradlew  ABC:build

ABC is the name of module

( It might be working on Linux too )

In Android Studio, if you need to generate a signed bundle or apk, you can choose the needed module in Module select field: Build > Generate Signed Bundle or APK > choose Android App Bundle or APK > Module

choice