1. Why do you do it? The project continues to develop, and constantly add new functions, new features, and the introduction of new frameworks and components. The JAR package dependencies are many and complex, coupled with various changes in requirements. Many existing functions are offline, but the JAR package dependencies are not taken care of, and are still placed in the project’s pOM.xml file. Project for a long time, often can appear package requires more memory, the problem of low time how to analyze projects which rely on is useful, which can eliminate, on the one hand, reduce packaging memory footprint is much, time slow problem, on the other hand to take care of the development of children’s shoes obsessive-compulsive disorder problem (let no useless jars in my project, This matter can be put on the agenda.

Two, how to do? If you are a Maven project, it is relatively easy to execute. Maven provides its own detection tool by typing a command. In IDEA, switch to the Terminal window, or use the command line to open the corresponding project directory and enter directly

mvn dependency:analyze

Looking at the log output from the console, 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: the compile [WARNING] com. Google. Code. Gson: gson: jar: 2.8.0: compile [WARNING] org. Springframework. The boot: spring - the boot: jar: 2.1.6. RELEASE: the compile [WARNING] Com. Fasterxml. Jackson. Core: Jackson - core: jar: 2.9.9: compile [WARNING] Org. Springframework: spring - the core: jar: 5.1.8. RELEASE: the 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. The boot: spring - the boot - starter - test: jar: 2.1.6. RELEASE: test
Used undeclared dependencies found

An indirect dependency is one that you do not declare directly on the project’s pom.xml. The dependency is passed on the pom.xml dependency that you declared. For example org. Apache. Rocketmq: rocketmq – common: jar: 4.5.2: is the compile your reference the:

< the dependency > < groupId > org. Apache. Rocketmq < / groupId > < artifactId > rocketmq - client < / artifactId > < version > 4.5.2 < / version > </dependency>

This is the way Maven uses it. It is not recommended that you copy this reference to your pom.xml. Warning for this part should be ignored.

Unused declared dependencies found

Xml.xml, but not used in the project. This is not the focus of our attention this time. If we determine that it is not necessary, we can remove this dependency.

Three, when to do it? 1) When a new project is established, it is necessary to be careful when quoting JAR packages. Don’t copy the dependencies of old projects directly, and avoid spending time to remove them later. 2) When the functional code is reconfigured, it can be removed properly, because there are self-testing and submit testing links. If there is any mistake in deleting, it can be found during testing.

IV. What risks should I pay attention to? 1) the results of this test is for reference only, and is sometimes inaccurate, as described above org. Projectlombok: lombok: jar: 1.16.20: provided, in fact, in the project have to use its annotations @ Data, this belongs to a miscalculation. Be careful to remove dependencies after testing, after all, the tool has defects. 2) If children take over the legacy of the old project, there must be a lot of such problems, but it is not recommended to do this operation when they take over, because they are not familiar with the project, it will waste a lot of time and energy to delete the problem will lead to problems, it is recommended to temporarily leave this thing.

Five, add a small plug-in

When you look at the pom.xml dependencies, you can install the Maven Help plug-in on IDEA to visually see the various JAR dependencies

Focus on Java high concurrency, distributed architecture, more technical dry goods to share and experience, please pay attention to the public number