最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

IDEA?下?Gradle?刪除多余無用依賴的處理方法

 更新時間:2022年03月31日 12:00:45   作者:assember  
這篇文章主要介紹了IDEA下Gradle刪除多余無用依賴,使用該插件可以一定程度上幫助我們刪除無用依賴,但是也可能會多刪除有用的依賴,需要在使用插件自動修復(fù)后手動檢測項目,驗證是否會出現(xiàn)問題,避免導(dǎo)致上線發(fā)布錯誤的負優(yōu)化

簡介

項目中經(jīng)過很久開發(fā),會有很多當(dāng)初引入后來又不再使用的依賴,靠肉眼很難分辨刪除。

這時候,我們可以使用分析無用依賴插件進行處理:gradle-lint-plugin

如何使用

注意: 他可能存在刪除錯誤的引用依賴,需要刪除后進行檢查和測試

并且,這里僅支持單模塊項目,如果是多模塊項目請參考官方文檔進行處理

官方文檔地址: https://github.com/nebula-plugins/gradle-lint-plugin/wiki

1.引入插件

在項目的 build.gradle 中引用該插件, 最新版本號可以 點擊這里查看:

plugins {
  id 'nebula.lint' version '17.7.0'
}

如何你項目中本身已經(jīng)有插件,則可以在后面追加,例如我的:

plugins {
    id 'org.springframework.boot' version '2.3.5.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
    id 'nebula.lint' version '17.7.0'
}

2.應(yīng)用插件

build.gradle 應(yīng)用 該插件,并在任意位置,配置檢測規(guī)則:

apply plugin :"nebula.lint"
gradleLint.rules=['unused-dependency']

3.使用 Gradle 進行重新載入項目

IDEA 使用 Gradle 進行重新載入項目,則會出現(xiàn) Lint 菜單, 如下圖所示:

4.生成報告

點擊 lint -> generateGradleLintReport, 可以生成報告。

報告僅保留不同類型的省略結(jié)果,可以看到有以下四種報告結(jié)果:

  • one or more classes are required by your code directly (no auto-fix available)
  • this dependency is unused and can be removed
  • this dependency should be removed since its artifact is empty (no auto-fix available)
  • this dependency is a service provider unused at compileClasspath time and can be moved to the runtimeOnly configuration (no auto-fix available)

其中, this dependency is unused and can be removed 表示可以刪除的依賴。

Executing 'generateGradleLintReport'...
> Task :generateGradleLintReport
Generated a report containing information about 83 lint violations in this project
> Task :autoLintGradle
This project contains lint violations. A complete listing of the violations follows. 
Because none were serious, the build's overall status was unaffected.
warning   unused-dependency                  one or more classes in org.mockito:mockito-core:3.3.3 are required by your code directly (no auto-fix available)
warning   unused-dependency                  this dependency should be removed since its artifact is empty (no auto-fix available)
build.gradle:59
implementation 'org.springframework.boot:spring-boot-starter-actuator'
warning   unused-dependency                  this dependency is a service provider unused at compileClasspath time and can be moved to the runtimeOnly configuration (no auto-fix available)
build.gradle:69
compileOnly 'org.projectlombok:lombok'
warning   unused-dependency                  this dependency is unused and can be removed
build.gradle:101
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
? 83 problems (0 errors, 83 warnings)
To apply fixes automatically, run fixGradleLint, review, and commit the changes.

5. 刪除無用依賴

我們可以看到報告的最后一句話,

To apply fixes automatically, run fixGradleLint, review, and commit the changes.

最后,可以執(zhí)行 fixGradleLint 自動刪除無用依賴。

修復(fù)報告如下,我們可以看到除了無用的依賴,還有一些其他的依賴也被刪除了,原因是因為,他認為我們可以直接引入其對應(yīng)的依賴而不是整個依賴包。

例如,compile group: 'com.baomidou', name: 'mybatis-plus-boot-starter', version: '3.3.1' 中我們只用了整個 starter 包的一部分依賴,可以僅依賴這一部分依賴,而不是整個 starter 包。這個也可以不按照他的推薦,直接手動選擇保留。

Executing 'fixGradleLint'...
> Task :compileJava
> Task :processResources UP-TO-DATE
> Task :classes
> Task :compileTestJava
> Task :fixGradleLint
This project contains lint violations. A complete listing of my attempt to fix them follows. Please review and commit the changes.
needs fixing   unused-dependency                  one or more classes in com.baomidou:mybatis-plus-core:3.3.1 are required by your code directly
fixed          unused-dependency                  this dependency is unused and can be removed
build.gradle:105
compile 'org.ehcache:ehcache'
build.gradle:106
compile 'javax.cache:cache-api'
build.gradle:107
compile 'org.mybatis:mybatis-typehandlers-jsr310:1.0.2'
build.gradle:112
testImplementation 'org.springframework.security:spring-security-test'
Corrected 17 lint problems

特殊情況

Lombok

Lombok 是一個編譯時自動生成 Getter/Setter 和構(gòu)造器的工具。

Nebula Lint 依舊會檢測無用的依賴,日志如下:

> Task :lintGradle FAILED
This project contains lint violations. A complete listing of the violations follows. 
Because none were serious, the build's overall status was unaffected.
warning   unused-dependency                  this dependency is a service provider unused at compile time and can be moved to the runtime configuration

處理方式(修改版本號):

gradleLint.ignore('unused-dependency') {
		compileOnly group: 'org.projectlombok', name: 'lombok', version:'1.16.20'
	}

相關(guān) Github issue: Nebula Lint does not handle certain @Retention(RetentionPolicy.SOURCE) annotations correctly #170

總結(jié)

使用該插件可以一定程度上幫助我們刪除無用依賴,但是也可能會多刪除有用的依賴。

需要在使用插件自動修復(fù)后手動檢測項目,驗證是否會出現(xiàn)問題,避免導(dǎo)致上線發(fā)布錯誤的負優(yōu)化。

到此這篇關(guān)于IDEA 下 Gradle 刪除多余無用依賴的文章就介紹到這了,更多相關(guān)idea Gradle 刪除依賴內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Springboot配置文件相關(guān)說明解析

    Springboot配置文件相關(guān)說明解析

    這篇文章主要介紹了Springboot配置文件相關(guān)說明解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-06-06
  • springboot jpa 延遲加載問題的2種解決

    springboot jpa 延遲加載問題的2種解決

    這篇文章主要介紹了springboot jpa 延遲加載問題的2種解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • Spring?Boot中的max-http-header-size配置方式

    Spring?Boot中的max-http-header-size配置方式

    這篇文章主要介紹了Spring?Boot中的max-http-header-size配置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 深入淺出講解Spring框架中AOP及動態(tài)代理的應(yīng)用

    深入淺出講解Spring框架中AOP及動態(tài)代理的應(yīng)用

    在軟件業(yè),AOP為Aspect?Oriented?Programming的縮寫,意為:面向切面編程,通過預(yù)編譯方式和運行期間動態(tài)代理實現(xiàn)程序功能的統(tǒng)一維護的一種技術(shù)
    2022-03-03
  • SpringBoot使用開發(fā)環(huán)境application.properties問題

    SpringBoot使用開發(fā)環(huán)境application.properties問題

    這篇文章主要介紹了SpringBoot使用開發(fā)環(huán)境application.properties問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • springboot 集成pgsql+mybatis plus的詳細步驟

    springboot 集成pgsql+mybatis plus的詳細步驟

    集成 Spring Boot、PostgreSQL 和 MyBatis Plus 的步驟與 MyBatis 類似,只不過在 MyBatis Plus 中提供了更多的便利功能,如自動生成 SQL、分頁查詢、Wrapper 查詢等,下面分步驟給大家介紹springboot 集成pgsql+mybatis plus的過程,感興趣的朋友一起看看吧
    2023-12-12
  • Struts2學(xué)習(xí)教程之入門小白的開始基礎(chǔ)

    Struts2學(xué)習(xí)教程之入門小白的開始基礎(chǔ)

    struts2其實就是為我們封裝了servlet,簡化了jsp跳轉(zhuǎn)的復(fù)雜操作,并且提供了易于編寫的標(biāo)簽,可以快速開發(fā)view層的代碼。下面這篇文章主要給各位想要學(xué)習(xí)Struts2的小白們詳細介紹了關(guān)于Struts2入門的一些開始基礎(chǔ),需要的朋友可以參考下
    2018-04-04
  • 入門到精通Java?SSO單點登錄原理詳解

    入門到精通Java?SSO單點登錄原理詳解

    這篇文章主要介紹了入門到精通Java?SSO單點登錄原理詳解,本文主要對SSO單點登錄與CAS、OAuth2.0兩種授權(quán)協(xié)議的關(guān)系和原理進行詳細說明
    2022-09-09
  • Java 遍歷list和map的方法

    Java 遍歷list和map的方法

    這篇文章主要介紹了Java 遍歷list和map的方法,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下
    2020-12-12
  • 使用Spring?Security搭建極簡的安全網(wǎng)站教程

    使用Spring?Security搭建極簡的安全網(wǎng)站教程

    這篇文章主要為大家介紹了使用Spring?Security搭建極簡的安全網(wǎng)站教程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06

最新評論

班玛县| 大冶市| 亳州市| 定兴县| 永胜县| 石景山区| 铅山县| 蒲江县| 嘉黎县| 乐东| 宁陵县| 西畴县| 依兰县| 三明市| 莱州市| 山东省| 枣阳市| 鄢陵县| 新安县| 长乐市| 四子王旗| 柳州市| 钟山县| 平原县| 淳化县| 潮安县| 汤阴县| 玛曲县| 蕉岭县| 巢湖市| 台东县| 雅江县| 开封县| 汾西县| 三穗县| 定南县| 佛冈县| 高陵县| 南平市| 惠州市| 岑巩县|