I believe that every Java programmer has the idea of reading Spring source code, but in the build time encountered various pits, this article details how to use the construction of Spring – Framework – 5.0.2.release – Chinese annotated version of the way, according to this step to ensure that you build a successful, to avoid the pit.

Download the source code

Spring – framework – 5.0.2. RELEASE – Chinese annotation version links: pan.baidu.com/s/1lsmuCuZ7… , extraction code: C7VW

Download the gradle version

Determine gradle version

Different versions of Spring use different gradle versions. Look at gradle/wrapper/gradle-wrapper.properties to see what gradle is currently using in Spring.

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-4.3.1-bin.zip
Copy the code

As you can see, we are using gradle version 4.3.1.

Manually install Gradle

Gradle can be downloaded from gradle.org/releases/

Find version 4.3.1 to download. Then configure environment variables. The MAC address is used as an example.

Enter vim ~/. Bash_profile on the command line terminal and add the following configuration:

Export GRADLE_HOME = / Users/chentianming/Downloads/work/gradle - 4.3.1 export PATH = $PATH: $GRADLE_HOME/binCopy the code

Finally, run source ~/.bash_profile for the configuration to take effect. When you are done, use Gradle -v to validate.

Configure the Ali Cloud image source

To speed up access, you can configure the Ali Cloud image source globally. Go to the ~/. Gradle folder, create a new init.gradle file, and type the following:

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

Compilation of the spring

Open the import-into-idea.md file, which describes the build steps. The key steps are as follows:

  1. usegradle :spring-oxm:compileTestJavaPrecompiled.
  2. Input to IDEA (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build. Gradle)
  3. Exclude the Spring-Aspects module when prompted.

precompiled

Image changed to Ali Cloud

Before compiling, put the projectbuild.gradleThe specified mirror source is changed to Ali Cloud to ensure that dependencies can be downloaded smoothly.

Perform precompilation

Enter the command to perform precompilation. If there is aaspectJNote out the corresponding Test code.

Such as the above error, direct put AutoProxyLazyInitTests. Java and AdvisorAutoProxyCreatorTests Java code commented out.

Try a few more times and BUILD SUCCESSFUL.

Import to IDEA

Navigate to directory -> Select build. Gradle (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.

Wait a little while to ensure that the import is successful

Original is not easy, feel that the article is written well small partners, a praise 👍 to encourage it ~

Welcome to my open source project: a lightweight HTTP invocation framework for SpringBoot