Idea import dependencies have been stuck, or problem records cannot be imported normally (failed to transfer from https://repo.maven.apache.org/maven2··etc.)

Preface : In a new project I came into contact with, idea kept reporting errors when importing maven dependencies. First, the maven dependencies were stuck, and then the dependency packages could not be imported normally. Each dependency package was still popular. I encountered org.bytedeco:javacv. :jar:1.4.3 failed to transfer from···,java: package org.bytedeco.javacv does not exist···

Try to run Maven import with -U flag (force update snapshots) Cannot resolve plugin ···org.apache.maven.plugins:maven-deploy-plugin:2.8.2···

Mysql:mysql-connector-java:jar:8.0.20 failed to transfer from and other dependency issues, summarize and record them again.

There is still a problem with dependency import.

Maven dependencies continue to report errors.

 

Group attack method:

1. Reconfigure the maven environment and reload the most basic dependencies.

The first and most basic thing is to reconfigure maven for your project.

Click FIle in the upper left corner →Settings→Build,Execution,Deployment→Build Tools→Maven,

The first one, Maven home path, here is to fill in your real Maven address, but I chose Bundled (maven 3) here to give a brief introduction.

The "Maven Home Path" option tells the IDE or other tools where to find the Maven installation directory.

The option "Bundled (Maven 3)" refers to packaging Maven in an IDE or other tools instead of using Maven already installed on the system. This option is typically used to build projects using Maven without Maven being pre-installed.

When you select this option Bundled (Maven 3) , the IDE or other tool will package the Maven executable file and the necessary library files together and place them in a special directory so that you can directly use them in the project. use it. In this way, you do not need to install Maven in the system , but can directly use packaged Maven to build, test and deploy your Java applications.

In addition: If your options have the " Use Maven wrapper " option, it means that you are currently using Maven Wrapper to build your project. Maven Wrapper is a tool for managing and running Maven, allowing you to build projects using a specific version of Maven included in the project without having to install Maven on the system .

Timing of choice: When you have Maven installed and want to use Maven in the system in an IDE or other tools, fill in the real Maven address. When you want to use a specific version of Maven instead of the version provided by default by the IDE or other tools, You can download the required version of Maven and install it into the specified directory. The rest of the time, choose Bundled (Maven 3) or Use Maven wrapper.

The second one, User strings file, goes without saying. Just fill in the address of your setting.xml file, which is usually in the .m2 directory under the user's home directory.

The third one, Local repository, stores the directory where Maven stores all downloaded dependencies on the local computer. Just fill in your real warehouse address normally.

Reload dependencies:

 

2. Clean cache: File/Invalidate Caches are common.

After reconfiguring your Maven, if there is still a lag in importing dependencies, you can consider clearing the cache and then re-importing the dependencies.

 

3. Too many dependent files lead to stuck exceptions.

The project is too large and has too many dependencies, so if there is a problem importing dependencies, modify the memory configuration.

FIle →Settings→Build,Execution,Deployment→Build Tools→Maven→ Importing

 

change into:

-Xms1024m -Xmx2048m

introduce:

-Xmx<size>: Set the maximum heap memory size of the JVM. For example, -Xmx4G means to set the maximum heap memory to 4GB.

-Xms<size>: Set the initial heap memory size of the JVM. For example, -Xms2G means to set the initial heap memory to 2GB.

-XX:MaxPermSize=<size>: Set the maximum permanent generation (Permanent Generation) size of the JVM. Only valid in JDK 7 and earlier.

Single attack method:

4. View the exceptions caused by entering the debug mode to monitor the build and solve the problems individually.

mvn clean install -X -D "maven.test.skip=true"

idea enters the terminal and enters the command

Error report: Start looking at the first line of the error report

    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:3.2.0:jar (default-jar) on project corewell-study: Execution default-jar of goal org.apache.maven.plugins:m aven-jar-plugin:3.2.0:jar failed: Plugin org.apache.maven.plugins:maven-jar-plugin:3.2.0 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-jar-plugin:jar:3.2.0 -> org.apache.maven.shared:file-management:jar:3.0.0 -> org.apache.maven.shared:maven-shared-io:jar:3.0.0 -> org.apache.maven.wagon:wagon-provider-api:jar:2.10

Reasons for error reporting and solutions:

This error is usually caused by Maven's inability to resolve the maven-jar-plugin plugin and its dependencies when building the project.

①Clear the cache files in the Maven local repository. Run the following command on the command line:

mvn dependency:purge-local-repository

② Check that you can connect to the remote Maven repository.

③Try to update the index of the Maven central warehouse. Run the following command on the command line:

mvn -U clean install

Make sure you are using the correct version numbers and dependencies. Please check the maven-jar-plugin version and its dependencies specified in the pom.xml file and compare with the latest version in the Maven central repository.

5. Check the specific errors in Sync in Build and solve them one by one.

View the specific error reason:

    mysql:mysql-connector-java:jar:8.0.20 failed to transfer from https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact mysql:mysql-connector-java:jar:8.0.20 from/to central (https://repo.maven.apache.org/maven2): GET request of: mysql/mysql-connector-java/8.0.20/mysql-connector-java-8.0.20.jar from central failed

This error is caused by Maven being unable to download the mysql-connector-java jar file from the central repository when building the project.

solve:

Finally, a version was added to mysql-connector-java in the pom, which successfully solved the problem.

    <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
            <!-- 添加版本号             -->
            <version>8.0.17</version>
        </dependency>

After a whole morning, I used the above method to successfully run the project at hand .
 

Summarize:

1. First configure Maven of the project.

2. Clear cache and reload.

3. If there is still a problem, try debugging to solve the problem, find the specific error dependency, and perform specific operations.

4. Check whether the version number of the dependency introduced by Maven is correct.

I hope this article can provide you with ideas for solving problems and successfully solve them . May your work go well !

Guess you like

Origin blog.csdn.net/youyudehan/article/details/133137749