Recent study spring-framework source code, step on a lot of pits in the process of configuring the source environment, where the configuration process will be recorded for later re-configuration can save time point in time.
Native environment: jdk1.8.0_161, IDEA2019.3.1, Gradle5.6.2, spring -framework-5.1.x, windows10
Gradle
installation
Spring-framework
Use Gradle
the environment to build, so the compiler Spring
when you need to install the source Gradle
environment, Gradle
and Maven
similar installation are direct download archive -> unpack -> configuration environment variable.
- Download gradle archive
into the official website Download: https: //gradle.org/releases/ download the corresponding version, here I downloaded 5.6.2 - Extracting archive
extract to your own directory, my directory is D: \ work \ softSave \ gradle -5.6.2 - Configuration environment variable
- Configuring GRADLE_HOME = D: \ work \ softSave \ gradle-5.6.2 (own extract the directory);
- Increase% GRADLE_HOME% \ bin in the PATH
- Increase GRADLE_USER_HOME environment variable, specify your own gradle download jar package on what, I'm here to configure the D: \ work \ file \ gradle_repo
- In the command line input gradle -v, if the following message appears it indicates a successful installation configuration
- Configuring local repository
directly installedgradle
during the build when some packets due to network and other resources will be wall download fails, you can configure the global gradle warehouse, I configured Ali cloud repository:
extract the directory in the init.d gradle New init.gradle file directory, which you can add the following
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
}
}
}
Download Spring-framework
Source
All projects are located in github above spring, spring-framework of the github link https://github.com/search?q=org%3Aspring-projects+spring&unscoped_q=spring
- Open the link, select the following items
- Select the version you want to download the source code, and download or directly to local git clone
Compile source code
- IEDA into the source in this case can only look at the code can not be found by IDEA click directly into the corresponding class, because the source is required to build gradle
- Construction of Source:
- spring-core, and is spring-aspect project two other modules depends, it is necessary to build these two works
a. first spring-aspect to the next directory, the command line is built gradle build command, as shown, if there then the bUILD sUCCESSFUL constructed successfully;
. B into the spring-core directory, a similar operation performed; - Find buildSrc directory under spring-framework directory, run build.gradle file to compile the source code.
Note: The error can occur with this method source code compilation process, if it is wrong to download resources, you need to reconfigure gradle warehouse, if other error, you can try commenting out the appropriate line, mostly test class for errors, can be resolved, Ferguson can drop a variety show to see the source code of the operating compiled by.