Recently, I have been sorting out the dependency information in the project, and there are many ways to view the dependency information. Here I will only talk about the methods that I personally think are more useful:
Output all dependency information of the specified module to the specified file
Format:
./gradlew :模块名:dependencies > 文件名.txt
Example:
./gradlew :app:dependencies > deps.txt
After the task is executed, a txt file named by you will be generated, which contains a lot of content, and lists all the dependencies of the environment for you. There are a lot of them. Generally, we only need to care about the following
- debugRuntimeClasspath debug runtime dependencies
- debugCompileClasspath debug compile-time dependencies
- releaseRuntimeClasspath release runtime dependencies
- releaseCompileClasspath release compile-time dependencies
Then go to view the corresponding dependency information.
View the dependency information of the specified environment
There is too much interference information output in the above way, we can specify to output only the dependencies of a certain environment
For example:
./gradlew app:dependencies > deps.txt --configuration releaseCompileClasspath
At this time, only the dependencies of releaseCompileClasspath will be output to txt.
But if you configure it productFlavors
, if you execute the above command directly, an error will be reported, indicating that it cannot findreleaseCompileClasspath
Configuration 'releaseCompileClasspath' not found in configuration container.
Example:
The productFlavors error message is configured
:
The reason is also relatively simple, because the environment name has changed, releaseCompileClasspath
just change it to one with a productFlavors prefix, as prdReleaseCompileClasspath
in the example:
Check which library brings in a certain version of the dependency
Another requirement is that I want to see which library brings in the dependency of a certain version
. It must be that a certain component I depend on internally depends on version 1.7.10, resulting in the final actual dependent version not being 1.6.21, but 1.7.10. At this time, I want to confirm which component internally depends on 1.7.10 version of kt.
There are two ways
method one
First of all, the first step is to pull out the overall dependencies. Note that the dependency information of the runtime environment needs to be used here.
Then search directly for keywords such askotlin:kotlin-stdlib:1.7.10
After finding it, go up to find out who his parent is, just judge the parent according to the blue ±–
found to be androidx.appcompat:appcompat:1.5.1
internally dependentorg.jetbrains.kotlin:kotlin-stdlib:1.7.10
Then go to the mvnrepository warehouse to search for the specified library to confirm .
It can be seen androidx.appcompat:appcompat:1.5.1
that the 1.7.10 version of kotlin-stdlib is indeed dependent on
way two
Use the command to print out which libraries the dependencies of the specified version exist in
Format
./gradlew 模块名:dependencyInsight > 文件名.txt --configuration 环境 --dependency 要查找的依赖组件名称
Example:
./gradlew app:dependencyInsight > kotlin.txt --configuration prdReleaseRuntimeClasspath --dependency kotlin:kotlin-stdlib
The result is as follows, and it can also be found that it is androidx.appcompat:appcompat:1.5.1
dependent onkotlin-stdlib:1.7.10
build scan
Execute ./gradlew build --scan
the command and enter yes according to the prompt
The construction information of the project will be generated as a web link.
Clicking on the link will allow you to enter your email address for the first time, and an email will be sent to you later
Click the link in the mailbox to view very detailed build information. Here we only look at the dependent modules
and the internal dependencies of the specified dependent library.
Well, that’s all. Basically, these methods can solve the problems of obtaining dependencies and versions in most scenarios. I hope they can help you.
If you think this article is helpful to you, please give it a thumbs up. It can help more developers. If there are any mistakes in the article, please correct me. For reprinting, please indicate that you are reposting from Yu Zhiqiang’s blog, thank you !