I wanted to find unused dependencies in my project. Is there any feature for this in gradle like in maven?

解决方案

UPDATE: 28-06-2016: Android support to unused-dependency

In June, 2017, they have released the 4.0.0 version

and renamed root project name "gradle-lint-plugin" to

"nebula-lint-plugin". They have also added Android support to

unused-dependency.

In May,2016 Gradle has implemented gradle lint plugin for finding and removing unwanted dependency

The Gradle Lint plugin is a pluggable and configurable linter tool for

identifying and reporting on patterns of misuse or deprecations in

Gradle scripts and related files.

This plugin has various rules. Unused Dependency Rule is one of them. It has 3 specific characteristics.

Removes unused dependencies.

Promotes transitive dependencies that are used directly by your code

to explicit first order dependencies.

Relocates dependencies to the 'correct' configuration.

To apply the rule, add:

gradleLint.rules += 'unused-dependency'

Details of Unused Dependency Rule is given in the last part.

To apply gradle lint plugin:

buildscript { repositories { jcenter() } }

plugins {

id 'nebula.lint' version '0.30.2'

}

Alternatively:

buildscript {

repositories { jcenter() }

dependencies {

classpath 'com.netflix.nebula:gradle-lint-plugin:latest.release'

}

}

apply plugin: 'nebula.lint'

Define which rules you would like to lint against:

gradleLint.rules = ['all-dependency'] // add as many rules here as you'd like

For an enterprise build, we recommend defining the lint rules in a init.gradle script or in a gradle script that is included via the Gradle apply from mechanism.

For multimodule projects, we recommend applying the plugin in an allprojects block:

allprojects {

apply plugin: 'nebula.lint'

gradleLint.rules = ['all-dependency'] // add as many rules here as you'd like

}

Details of Unused Dependency Rule is given in this part

To apply the rule, add:

gradleLint.rules += 'unused-dependency'

The rule inspects compiled binaries emanating from your project's source sets looking for class references, and matches those references to the dependencies that you have declared in your dependencies block.

Specifically, the rule makes the following adjustments to dependencies:

1) Removes unused dependencies

Family-style jars like com.amazonaws:aws-java-sdk are removed, as

they contain no code

2) Promotes transitive dependencies that are used directly by your code to explicit first order dependencies

This has the side effect of breaking up family style jars like

com.amazonaws:aws-java-sdk into the parts that you are actually

using, and adding those as first order dependencies

3) Relocates dependencies to the 'correct' configuration

Webjars are moved to the runtime configuration

Jars that contain no classes AND content outside of META-INF are

moved to runtime

'xerces', 'xercesImpl', 'xml-apis' should always be runtime scoped

Service providers (jars containing META-INF/services) like

mysql-connector-java are moved to runtime if there is no provable

compile-time reference

Dependencies are moved to the highest source set configuration

possible. For example, 'junit' is relocated to testCompile unless

there is an explicit dependency on it in the main source set (rare).

UPDATE: Previous plugins

For your kind information, I want to share about previous plugins

Gradle plugin that finds unused dependencies, declared and transitive is com.github.nullstress.dependency-analysis

But it's latest version 1.0.3 is created 23 December 2014. After that there is no update.

N.B: Many of our engineers are being confused about this plugin as they

updated only the version number nothing else.

gradle mysql依赖关系,如何在gradle中找到\删除未使用的依赖关系相关推荐

  1. linux内核源文件依赖,linux-kernel – 如何在Kbuild中为生成的源文件添加依赖项?...

    还有一个问题:在尝试构建多文件模块时,您不能拥有与模块同名的C文件.将mymod.c重命名为mymod-core.c 然后,以下应该工作: obj-m := mymod.o mymod-objs := ...

  2. mysql里面的选择运算_在MySQL关系模型中,选择运算是在一个关系的所有元组中选择指定属性列,组成新关系。...

    [单选题]下列关于元素第一电离能的说法不正确的是( ) [填空题]We had already ____ contact with the museum. [判断题]DELETE语句功能是对表中所有记 ...

  3. 如何在python中找到两个日期时间对象之间的时差?

    本文翻译自:How do I find the time difference between two datetime objects in python? 如何分辨两个datetime对象之间的时 ...

  4. 如何在Go中找到一个对象的类型?

    本文翻译自:How to find a type of an object in Go? How do I find the type of an object in Go? 如何在Go中找到对象的类 ...

  5. 如何在 R 中找到 F 临界值

    当您进行 F 检验时,您将获得 F 统计量作为结果.要确定 F 检验的结果是否具有统计显着性,可以将 F 统计量与 F 临界值进行比较.如果 F 统计量大于 F 临界值,则检验结果具有统计显着性. F ...

  6. wps启用编辑按钮在哪里_如何在wps工具栏中添加按钮 如何在Excel中添加删除命令按钮...

    延伸:如何在Excel中添加删除命令按钮 描述:在Excel 2003中,很多常用的命令按钮都放置在工具栏中,用户可以很方便地进行操作.添加命令主要是通过拖动的方式完成的,其具体的操作如下:骤一,在视 ...

  7. rstudio中位数的公式_如何在R中找到中位数

    rstudio中位数的公式 In this tutorial, let's learn how we can find the median in R. Median is defined as th ...

  8. 如何在centos中找到安装mysql_如何在CentOS 7上安装MySQL

    随着CentOS 7 MySQL的发布,全球最受欢迎的开源关系数据库管理系统在CentOS的存储库中不再可用,而且MariaDB已成为默认的数据库系统. MariaDB是MySQL的向后兼容,二进制插 ...

  9. mysql连接clickhouse_如何在ClickHouse中使用MySQL客户端

    目录 介绍 安装 2.1成功完成安装后,启动ProxySQL. 创建ClickHouse用户 从MySQL客户端连接到ClickHouse 查询ClickHouse之类的MySQL 局限性 6.1结论 ...

最新文章

  1. Linux tree命令
  2. tcp-ip协议详解二知识进阶
  3. 大众EA211djs和css的区别,宣传上却说捷达VS5用的发动机是EA211,但这款车的参数配置栏发动机型号写的却是DJS,谁能为我解惑吗?(只有斯柯达的柯米克的发动机型号写得才是EA211)...
  4. pytorch argmax_一起无聊地用PyTorch刷爆sklearn的内置数据集吧(`?ω?′)
  5. 【jquery】select下拉框赋值
  6. perl xml dom中文乱码问题解决
  7. Max Sum Plus Plus HDU - 1024
  8. java 调用groovy脚本,实现多个sql按指定逻辑运行,可做报表预聚合
  9. 今天的几点感悟_20160429
  10. 老板催你交圣诞海报设计?PSD源文件素材,直接编辑
  11. 不用加号实现两整数相加
  12. [原]shader实现矩形圆角
  13. Poj2259 Team Queue 【队列】
  14. [争什么! 掺在一起做撒尿牛丸啊! 笨蛋]ASP.NET Core 2.0 + EF6 + Linux +MySql混搭
  15. 写写做数模竞赛的经验
  16. 全球唯一顶级车展来袭,云徙科技成为造车新势力?
  17. opencv 实现等值线_绘制等值线
  18. 微信公众号排版学习之图片篇
  19. Java设计模式 -- GOF23
  20. Java线程死锁模拟

热门文章

  1. 计算机黑屏时间,如何在计算机上设置黑屏时间
  2. bat文件备份MySQL数据库
  3. 如何从外网向内网传东西_鱼缸内出现气泡还会不断缓缓升起,是什么东西,如何处理和解决?...
  4. l2-004 这是二叉搜索树吗?_MySQL索引为何选择B+树
  5. minio在不同平台下的启动命令
  6. ORACLE 索引的三种状态: VALID、 N/A 、UNUSABLE
  7. mysql 存储过程(提供查询语句并返回查询执行影响的行数)
  8. IOCP模型TCP服务器
  9. SQL Server 数据库原理与应用
  10. YAML文件结构简介