Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between gradle assemble and gradle build tasks?

If I am not wrong gradle assemble does run gradle assembleDebug and gradle assembleRelease, but I believe gradle build also does the same, so what are the different between them both?

like image 638
Humble Student Avatar asked May 25 '17 16:05

Humble Student


People also ask

What is Gradle build task?

Gradle Tasks In Gradle, Task is a single unit of work that a build performs. These tasks can be compiling classes, creating a JAR, Generating Javadoc, and publishing some archives to a repository and more. It can be considered as a single atomic piece of work for a build process.

What does Gradlew assemble do?

Assemble is for creating artifacts (eg WAR or JAR) from the various components, classpaths, resource files, etc.

What is assemble task?

Assemble is a lifecycle task with no actions attached. Lifecycle tasks often combine other tasks and are useful to run in your development workflow. The purpose of assemble is to combine all tasks which produce a distribution or artifact into a single task.

Does Gradle assemble run tests?

By default, Gradle will run all tests that it detects, which it does by inspecting the compiled test classes. This detection uses different criteria depending on the test framework used. For JUnit, Gradle scans for both JUnit 3 and 4 test classes.


5 Answers

assemble will build your artifacts, and build will assemble your artifacts with additional checks.

build depends on assemble, so build is sort of a superset of assemble

You can have a look on the tasks that will be executed by using the --dry-run flag. e.g.

gradlew build --dry-run

You will see that apart from assemble also lint and test will be executed.

like image 129
David Medenjak Avatar answered Oct 03 '22 23:10

David Medenjak


From gradle tasks --all:

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.

build is effectively assemble + check (and check is test + any linting tasks).

like image 41
Laurence Gonsalves Avatar answered Oct 04 '22 00:10

Laurence Gonsalves


It's true that according to gradle tasks it looks like the build is a superset of assemble, including tests. But(!) from my short experience it really looks like it's not the case.

So I ran those 2 commands in the command line using the gradle wrapper with --scan flag after running clean every time. This is the comparison:

  1. Desired built files:
    • After running assembleDebug I got all the built files i wanted - *.apk and *.aar files.
    • After running buildDebug I didn't have any of those files.
  2. Amount of tasks ran according to the scans:
    • assembleDebug - 109 tasks
    • buildDebug - 91 tasks
  3. Amount of dependencies according to the scan:
    • assembleDebug - 172 from 20 configurations
    • buildDebug - 104 from 18 configurations
    • It seems like the reason they differ is that in assembleDebug in 2 of my 3 sub projects (which are java libraries, not app) there is one more configuration, called lintClassPath. This configuration is missing in buildDebug.
  4. Another point to mention is that when I searched in the tasks list, it seemed like buildDebug didn't call assembleDebug task and assembleDebug didn't call buildDebug tasks.
  5. And the last interesting thing to mention in this context is that when I ran build from the Android Studio (Build -> Make Project), I see in my scan that the command that actually ran was the assembleDebug. More specifically, it ran :app:assembleDebug.

As you can see, I don't really understand the differences myself, but this is what I found out. If someone can explain it to me and the other users reading here, it could be awesome :) Thanks!

like image 29
Doron Go Avatar answered Oct 04 '22 00:10

Doron Go


There is conflicting information about whether build is supposed to depend on assemble.

On one hand, Understanding Gradle: the Build Lifecycle shows a graph of task dependencies from where build and assemble are independent: Directed acyclic graph for the Java plug-in tasks from the book Gradle Recipes for Android.

In contrast, the Gradle user guide for Java plugin shows that build depends on assemble, at least for Java projects:

Java plugin - tasks

This contradicts the graph from "Understanding Gradle." So perhaps the Android plugin implements build/assemble tasks differently from the Java plugin? Or, this behavior changed in some version of Gradle.

like image 38
Colin D Bennett Avatar answered Oct 03 '22 23:10

Colin D Bennett


Assemble will build your artifacts, and build will assemble your artifacts with additional checks.

What additional checks? I run the tasks so you don't have to:

:app:lint SKIPPED       
:app:bundleDebugClasses SKIPPED     
:app:kaptGenerateStubsDebugUnitTestKotlin SKIPPED       
:app:kaptDebugUnitTestKotlin SKIPPED        
:app:compileDebugUnitTestKotlin SKIPPED     
:app:preDebugUnitTestBuild SKIPPED      
:app:javaPreCompileDebugUnitTest SKIPPED        
:app:compileDebugUnitTestJavaWithJavac SKIPPED      
:app:processDebugUnitTestJavaRes SKIPPED        
:app:testDebugUnitTest SKIPPED      
:app:bundleReleaseClasses SKIPPED       
:app:kaptGenerateStubsReleaseUnitTestKotlin SKIPPED     
:app:kaptReleaseUnitTestKotlin SKIPPED      
:app:compileReleaseUnitTestKotlin SKIPPED       
:app:preReleaseUnitTestBuild SKIPPED        
:app:javaPreCompileReleaseUnitTest SKIPPED      
:app:compileReleaseUnitTestJavaWithJavac SKIPPED        
:app:processReleaseUnitTestJavaRes SKIPPED      
:app:testReleaseUnitTest SKIPPED        
:app:test SKIPPED       
:app:check SKIPPED      
:app:build SKIPPED

As you can see, build does execute more tasks than assemble. Like lint, test, and check tasks.

You can refer the full tasks here The original text is build task while the changed text is assemble task.

Project used: Android Sunflower GitHub

like image 32
aldok Avatar answered Oct 04 '22 01:10

aldok