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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值