What are the differences between
./gradlew :app:dependencies
and
./gradlew :app:androidDependencies
?
All I've been able to notice is that androidDependencies includes .jar and .aar in the output graph. Why is this the case and is there a way to include these files in the dependency output via dependencies?
You can run ./gradlew :app:tasks to see a short description of each Gradle task that is runnable in the :app project. The description that I see for each of the androidDependencies and dependencies Gradle tasks is as follows:
androidDependencies - Displays the Android dependencies of the project.
dependencies - Displays all dependencies declared in project ':app'.
Sadly, the descriptions here don't do a great job of differentiating between the two Gradle tasks. However, on running each of the two Gradle tasks, I see two differences in the output, as follows:
The androidDependencies task calls out whether the library is packaged as an aar or a jar. The dependencies task does not offer this information. (You have already called this difference out in your question.)
The androidDependencies task prints a flattened list of the project's dependencies. The dependencies task, on the other hand, prints a nested graph of the project's dependencies.
A further difference between the two tasks is that you can provide a --configuration option to the dependencies task to restrict its output to a single configuration. For example, if you run ./gradlew :app:dependencies --configuration debugCompileClasspath, this will only display the dependencies for the debugCompileClasspath configuration. The --configuration option is not available for the androidDependencies task.
Related
I have multiple modules in my android project. I have one Gradle file which having code for ktlint. I applied that Gradle file to every module by writing this in the project Gradle file.
subprojects { subProject ->
apply from: "$project.rootDir/commonFiles/gradleScript/kotlin-code-quality.gradle"
}
now the problem is I can run ktlint on each module by giving their name in command like this.
Running ktlint for cache module.
./gradlew :cache:ktlint
but I need to run all modules ktlint at once.
Here is my open-source repository and pull request on which I need to perform ktlint action.
Sorry, it's my bad. ./gradlew ktlint will always run on multimodule. I had some lint checks fail in the app module. I thought it is running only on the app module.
but when I fixed the app module's lint and ran the ./gradlew ktlint. it jumped to the cache module.
I hope it helps you Thanks.
I have a grade project in Android Studio that contains several modules; each module containing an Android application or service. The applications/modules have no dependencies on each other.
Project
- module1
- module2
- etc...
I would like to build and install all of the apps with the push of a button. Is there a way to create a gradle task, for the project, that will compile and install each of modules/apps? If not, what would be the best approach to build and deploy the applications together?
I was able to get all modules/projects to work with the following gradle task in the root project:
task _installEverything{
subprojects { sp ->
println("Building and Installing: " + sp.name)
dependsOn(':' + sp.name + ':installDebug')
}
}
The task 'installDebug' can be used to compile and install each application; this task needs to be called in a Lazy dependsOn because the task does not exist when the root projects build script is compiled. This way, the following tasks will be called:
:app1:installDebug
:app2:installDebug
etc...
I want to run a gradle task that fetches additional sources and sets them up before gradle tries to resolve dependencies.
In build.gradle there is a task that fetches a sub project's source code. The task needs to be run before Gradle tries to resolve dependencies, because the sub project is part of the dependencies. The task involves fetching sources from a remote repository and replacing a few build.gradle files to make the build possible.
What happens now is that:
I run the task.
Gradle tries to resolve dependencies before actually running the task.
It fails because one of the dependencies requires the sub project (the sources that my task is supposed to fetch).
Of course, resolving dependencies is part of the "Configuration" build phase, so it's pretty clear why the task is run after. The question is how to make it run before.
Of course I can make it work if I replace my gradle task with a separate bash script and run it manually before gradle does anything. However, that would mean that I duplicate some variables in the gradle and the bash scripts (like version names and git tag names). Those variables are used for other purposes in gradle, and having them in two places is bad. There are other reasons I want to avoid that, one of them being - using a bash script would mean that gradle fails at doing our build from start to finish...
Firstly you are incorrect that resolving dependencies is part of the "Configuration" phase. If you make use of the lazy evaluation of FileCollection then it will actually be resolved in the execution phase. A configuration will be resolved the first time that resolve() is invoked. Please see the javadoc for the methods which cause a Configuration to be resolved. AFAIK the core gradle code won't resolve a configuration in the "Configuration" phase but your custom code may cause this (I suggest you refactor if this is the case)
You can do something like this:
dependencies {
// this is lazy evaluated
compile fileTree(dir: "$buildDir/dynamicJars", include: "*.jar")
}
task getDynamicJars(type: Copy) {
from zipTree('path/to/somefile.zip')
into "$buildDir/dynamicJars"
}
compileJava.dependsOn getDynamicJars
When I ran ./gradlew clean for my Android project, the task failed for not resolving all dependencies. The complaints came from the gradle task _debugCompile.
I can verify some of the local dependencies didn't exist which failed the dependencies resolving process, but I'm still curious about why the clean task would check for dependencies while not building the project.
Shouldn't it just delete some directories as mentioned in the following link?
https://docs.gradle.org/current/userguide/java_plugin.html#sec:clean
Is there any gradle built-in task that could just clean the build folder without checking dependency?
Thanks!
Gradle already resolves dependencies during its configuration phase which precedes the execution phase, see The Build Lifecycle (it downloads dependencies only once they are needed, though). However, dependencies being out of date does not make resolution fail. If resolution fails that dependency is likely not available online anymore. If you still have the dependency in your Gradle cache you might be able to work around this by specifying the --offline switch:
$ ./gradlew --offline clean
I'm using Android Studio 1.3.2 on Mac.
Gradle version is listed as 2.2.1, Android Plugin version 1.3.1.
I have applied the FindBugs Gradle plugin, and I've created a task that successfully runs the analysis on the directory 'build/intermediates/classes'.
To trigger this task on Gradle Sync, I've added it as a dependency to the preBuild task, like this:
preBuild.dependsOn findBugs
The problem with this dependency is that, at time of preBuild, the generated class files are either non-existent (first sync) or stale (remaining from previous sync). Basically, I want my task to run immediately after the 'build/intermediates/classes' directory is created, or when the files there are refreshed as part of the 'Sync' operation.
Looking at the tasks available, I can see the 'clean' task has the following description:
clean - Deletes the build directory.
However, none of the other tasks I see describe the directory's creation. My first thought was "Well, it's got to be the build task, right?". Unfortunately, as usual, it's not that simple (pressing gradle 'sync' button, does not trigger my task when I've added it as a dependency to the 'build' task). Is no such task available? If so, which task would best suit what I'm trying to achieve?
You can see all tasks using ./gradlew tasks
The build task is the main one. It builds everything, generates APKs and runs all checks.
I recommend you adding the following to the build.gradle file:
check.dependsOn 'findbugs'
So when you run the check task, it will execute findbugs as well.
Then also set a dependency on findBugs for the compilation task:
task findbugs(type: FindBugs, dependsOn: 'compileDebugSources') {...}
This will compile the source in case you run findbugs without previously compiling it.