Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
In the actual development process, maven helps us manage project dependencies and saves a lot of code time. However, there are some minor issues when using Maven to manage dependency information, such as project dependencies suddenly turning red and Maven dependencies not loading properly.
Issue review
1. The background
In the development stage of the project, we generally do not change the old project, but when we upgrade the architecture or code reconstruction, there will be a demand for version upgrade, such as JDK, MySQL version upgrade, SpringBoot version upgrade, Maven or IDEA editor version upgrade occur. At some point, the project will go wrong, leaving people wondering what the problem is, or even having to go back to the original starting point.
2. Dependency error reporting
The dependent information errors reported in this project are mainly as follows:
- Project files are reported red
- Annotations and incoming messages in code files are reported red
3. Maven dependency information is reported red
3. Try recovery
When this problem occurs, it is relatively easy to tell if maven dependencies are not loading properly. But how is it produced, why is it used well before, and how to solve it? With this list of questions in mind, I began a battle of wits with the IDEA editor and Maven.
- First of all, according to previous experience, maven reported an error and tried to download again. After repeatedly clicking the refresh button and re-downloading, there was no change, and it was found that maven could not download normally at this time.
- Then, it considers whether IDEA import project dependence is not correctly loaded or IDEA temporary leakage (did encounter), then remove the project, restart IDEA and load the project, found no change, again rule out the problem of IDEA;
- Later, I thought whether there was a problem with the mirror configured in maven’s configuration file that the dependency could not be downloaded, and whether the maven repository location specified in IDEA was incorrect. I checked the Maven configuration of IDEA and found that the configuration was normal without any change.
- The project under normal development suddenly reported an error, which was ridiculous to think about. Finally, I had no choice but to start maven and try to download Maven again and configure it into IDEA. It suddenly came to mind that Maven is Bundled(Maven3). It was abandoned because custom Mabundled makes more flexible use of configuration information such as images.
- Finally, with a try attitude, switch Maven configurations to Bundled(Maven3), configuration files and repository paths unchanged, and when applied, go red! I found the problem.
4. After discovering the problem
- After finding a solution to the problem, maven is basically the cause of the problem. For further verification, I downloaded a different version of Maven (V3.5.4) from the official website of Maven. After configuring the Maven into IDEA, I found that there was no problem. However, I switched to the original version (V3.0.5) again.
- On second thought, the only possible change in the project was that the SpringBoot version went from 1.x to 2.x, and nothing else changed.
5. Version information about related tools
- IDEA version: 2019.3.3
- Error Maven version: 3.0.5
- SpringBoot version: 2.2.6.RELEASE
6. Think about
Although this project relies on the red report, it is a small problem, but it is a sense of accomplishment to solve it independently. By accumulating experience, mastering skills and drawing inferences from one another, we can locate the problem more quickly and solve it in time when we encounter similar problems in the future.