In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to remove useless jar references from the Maven project, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Why do you want to do this? The project continues to develop, constantly add new functions, new features, introduce new frameworks and components, jar package depends on many and complex, coupled with various changes in requirements, there are many existing functions offline, but the jar package depends on no one to manage, or put in the project pom.xml file. Project lasts for a long time, there will often be project packaging requires more memory, slow time problems, how to analyze which dependencies in the project are useful, which can be eliminated, on the one hand to reduce the packaging memory consumption, time is slow, on the other hand to take care of the research and development of children's shoes obsessive-compulsive disorder problem (can not tolerate a little useless jar package in my project), this matter can be put on the agenda.
Second, how to do it? If it is a Maven project, it is relatively easy to execute. Maven provides a detection tool by itself, and you can enter commands. In IDEA, switch to the Terminal window, or use the command line to open the corresponding project directory and type directly
Mvn dependency:analyze
View the log output from the console and focus on these two parts:
[WARNING] Used undeclared dependencies found: [WARNING] com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile [WARNING] com.fasterxml.jackson.core:jackson-databind:jar:2.9.9:compile [WARNING] io.jsonwebtoken:jjwt:jar:0.9.0:compile [WARNING] org.apache.rocketmq:rocketmq-common:jar:4.5.2:compile [WARNING] org.springframework:spring-beans:jar:5 .1.8.RELEASE: compile [WARNING] com.google.code.gson:gson:jar:2.8.0:compile [WARNING] org.springframework.boot:spring-boot:jar:2.1.6.RELEASE:compile [WARNING] com.fasterxml.jackson.core:jackson-core:jar:2.9.9:compile [WARNING] org.springframework:spring-core:jar:5.1.8.RELEASE:compile [WARNING] org.apache.rocketmq:rocketmq -remoting:jar:4.5.2:compile [WARNING] Unused declared dependencies found: [WARNING] org.projectlombok:lombok:jar:1.16.20:provided [WARNING] org.springframework.boot:spring-boot-starter-test:jar:2.1.6.RELEASE:testUsed undeclared dependencies found
Indirect dependency, which means that you do not declare it directly in the pom.xml of the current project project. This dependency is passed from the pom.xml dependency in the dependency that you have declared. For example, org.apache.rocketmq:rocketmq-common:jar:4.5.2:compile, you quoted this:
Org.apache.rocketmq rocketmq-client 4.5.2
This is how Maven is used, and it is not recommended that you copy this part of the reference to your pom.xml. Generally speaking, this part of WARNING can be ignored.
Unused declared dependencies found
Useless dependency, which means that we declared the dependency of this jar package in pom.xml, but did not use it in the project project. This is not the focus of our attention this time. We can remove this dependency if we don't need it. After Reimport, the jar package was removed from our project.
When will you do it? 1) when setting up a new project, be careful not to directly copy the dependencies of the old project when quoting the jar package, so as to avoid taking the time to eliminate it later. 2) when refactoring the functional code, you can delete it properly, because there is also a self-test and submit the test link. If there is an erroneous deletion, you can find it during the test.
Fourth, what risks should be paid attention to? 1) the result of this test is for reference only, and sometimes it is not accurate. For example, org.projectlombok:lombok:jar:1.16.20:provided mentioned above actually uses its annotation @ Data in the project, which is a misjudgment. We should pay attention to more testing after removing dependencies. After all, the tools are defective. 2) if children's shoes take over the old projects left over, there must be a lot of problems, but when they first take over, it is not recommended to do this operation, because they are not familiar with the project, and deleting things will waste a lot of time and energy to solve the problem of dependence. It is recommended not to move for the time being.
Add a small plug-in to view the pom.xml dependencies, you can install the maven help plug-in on the IDEA, you can directly see the jar dependencies
The above is how to eliminate useless jar references in the Maven project. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.