How to show Gradle module dependency tree - android

I tried using
./gradlew androidDependencies
but that shows all dependencies. I just want to see only module dependencies, e.g. as defined in all build.gradles
dependencies {
implementation project(':moduleA')
implementation project(':moduleB')
implementation project(':moduleC')
}

You mean like
gradle moduleA:dependencies
This should show the dependencies related to moduleA
For the whole dependencies Tree with no module selected
gradle dependencies

https://github.com/vanniktech/gradle-dependency-graph-generator-plugin
You can use this plugin to create "your project module dependency graph"
./gradlew generateProjectDependencyGraph
or "whole dependency graph".
./gradlew generateDependencyGraph

Related

Are Gradle Buildscript Classpath Dependencies Shipped with Android App?

Gradle has multiple dependency configurations. I know that compile, implementation, api dependencies are shipped with the library/app; while compileOnly, testCompile, and testImplementation dependencies are not. What about the classpath dependencies in the top-level buildscript, are those dependencies included in the AAR/APK?
For E.g. Dokka (https://github.com/Kotlin/dokka) library, this only needs to be added as buildscript.classpath dependency, will dokka be included in the library aar file?
I tried searching in the Gradle docs but could not find an answer to my question. I am ssuming that it should not be shipped with the app/library.

How to add runtime requirement without bundling it with the application distributables?

I want to use Firebase and Play services libraries. As far as I understand it is ok to depend on this library and use it's functionality if it's already present on the device or require to download it, but due to the licensing I can not distribute this libraries bundled with my application.
My question:
How do I declare dependency and have 100% certainty that it is not bundled but will be provided on the phone?
Before this way of adding classpath dependency in buildscript was sufficient for me and added dependencies only during compilation:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
But unfortunately now it has to be added to the application dependencies in that way (adding do buildscript doesn't work):
dependencies {
implementation platform('com.google.firebase:firebase-bom:31.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
}
I'm new to android development, but as explained here, when we use different gradle dependency declarations we get:
implementation
Gradle adds the dependency to the compile classpath and packages the dependency to the build output.
api
Gradle adds the dependency to the compile classpath and build output.
compileOnly
Gradle adds the dependency to the compile classpath only (that is, it is not added to the build output). This is useful when you're creating an Android module and you need the dependency during compilation, but it's optional to have it present at runtime.
runtimeOnly
Gradle adds the dependency to the build output only, for use during runtime. That is, it is not added to the compile classpath.
Does api dependency solve my problem, as the description doesn't use the word packages ?

Found more than one jar in the 'lintChecks' configuration

I want to add custom lint rules to my projects, but I get error while syncing project.
Execution failed for task ':app:prepareLintJar'.
Found more than one jar in the 'lintChecks' configuration. Only one file is supported. If using a separate Gradle project, make sure compilation dependencies are using compileOnly
How can I check which library or module is adding another jar?
I fixed problem. My dependencies in my custom rules module was
dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compileOnly 'com.android.tools.lint:lint-api:26.5.3'
compileOnly 'com.android.tools.lint:lint-checks:26.5.3'
}
I changed kotlin dependency to compileOnly and it worked
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
compileOnly 'com.android.tools.lint:lint-api:26.5.3'
compileOnly 'com.android.tools.lint:lint-checks:26.5.3'
}

How to use gradle BoM with annotation processor?

I’m trying to define all my dependencies in a bill of materials (BoM) platform module so the other modules in my multi-module project can use the same versions. All works fine except the kapt dependencies. In those I get this error:
Could not determine the dependencies of task ':app:kaptDebugKotlin'.
> Could not resolve all task dependencies for configuration ':app:kapt'.
> Could not find com.google.dagger:dagger-compiler:.
Required by:
project :app
For example with this platform (:bom) module:
plugins {
id 'java-platform'
}
dependencies {
constraints {
api 'com.google.dagger:dagger:2.25.2'
api 'com.google.dagger:dagger-compiler:2.25.2'
}
}
I'm getting that error when I use it like this in the app module:
dependencies {
implementation platform(project(':bom'))
implementation 'com.google.dagger:dagger'
kapt 'com.google.dagger:dagger-compiler'
// ...
}
I’m getting the same error if I use annotationProcessor. If I set the version like kapt 'com.google.dagger:dagger-compiler:2.25.2' all works.
What am I doing wrong? Can I use BoM for kapt or annotationProcessor?
you are missing kapt platform(project(':bom'))
kapt doesn't include dependencies from implementation, so it doesn't include the platform either

Android Dependencies not resolving in groovy project

I have a groovy project with
dependencies {
compile project(':app')
}
where app is an android project.
When I run ./gradlew dependecies
compile - Compile classpath for source set 'main'.
\--- project :app
is all that is printed out.
Why are all the dependencies from the app project being printed out?
Is there a way to get all of the dependencies from this project and add them to this project?
I was able to fix my problem with
dependencies {
compile project(':app').configurations.compile.dependencies
}

Categories

Resources