“This is the 20th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”

Hello everyone, I’m Ah Q!

During the Spring Festival, a small friend of my private letter said that I want to study the Spring source code, want me to issue a tutorial to implement IDEA import Spring source code, today it came ~

Version: IDEA 2020.2.3; Spring 5.0 x; Gradle 4.4.1.

From the firstgithubThe abovespringDownload the source code and unzip it:

Remember: do not open with IDEA directly after decompression, because Spring source code is built with Gradle. If it is already opened with IDEA, delete it and decompress it again.

We find the folder

Spring - framework - 5.0 x \ gradle \ wrapper

Gradle-wrapper. properties file, check gradle version, go to the official website to download.

Download it when you’re donegradleEnvironment variables can be configured to usegradle -versionTo verify thegradleCheck whether the configuration is successful

Create a new init.gradle file under USER_HOME/. Gradle/and replace the foreign source with the domestic image

allprojects {
 repositories {
     def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
  all { ArtifactRepository repo ->
      if(repo instanceof MavenArtifactRepository){
       def url = repo.url.toString()
    if(url.startsWith('https://repo1.maven.org/maven2/')||url.startsWith('https://jcenter.bintray.com/')){
        project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
     remove repo
    }
   }
     }
  maven {
   url REPOSITORY_URL
  }
 }
}
Copy the code

Open a Git window in Spring-Framework-5.0.x and run the following command

./gradlew :spring-oxm:compileTestJava

The command is used to remove thespringintoIDEAEngineering structures that can be imported.

If you are opening a new DOS window for Windows, go to the source directory folder first and run the command without adding the preceding./

configurationIDEAIn thegradle

Use File -> open to import the Spring project into IDEA and wait for the JAR download to complete.

In case of error information:

Add it in build.gradle

maven { url "http://maven.aliyun.com/nexus/content/groups/public"}

The purpose is to change to a domestic image (init.gradle sometimes doesn’t work).

Error:

Gradle and gradle plugin versions are too old. You can change gradle to a higher version. However, this problem is only a reminder and does not affect compilation.

intestThe package randomly found a unit test run, run successfully

Post off

Ah Q will continue to update the Java practice of the article, interested in the public account can pay attention to: AH Q said the code, also can come to the technical group to discuss the problem!