As we all know, spring has become the enterprise standard for javaEE development, and we are afraid of this mysterious black box. But “ask canal where can be so clear, only the source water”, want to thoroughly understand the principle of Spring, source code learning is our Java engineers can not avoid the difficulty. The first step in learning spring source code is to build the spring source environment locally, which is the subject of all my discussions today. Without further ado, let’s get right to the subject of the day.
[Environment Preparation]
A, jdk1.8
Build tool Gradle
Spring has been built on Gradle since Spring 4. Gradle is a modern maven-like project build tool that won’t be covered here. Gradle has a very active community, which can be seen from the release of gradle. With so many gradle versions available, it is difficult for beginners to choose gradle versions when building Spring source code. Second, how can gradle be configured to speed up builds?
There are rules for selecting A gradle version. Go to the Githuab page of Spring and select the branch you want to branch. Use 5.1.x as an example to check /gradle/wrapper/gradle-wrapper.properties.
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip zipStoreBase = GRADLE_USER_HOME zipStorePath=wrapper/distsCopy the code
Export GRADLE_HOME = / home/mojito/application/gradle/gradle - 4.10.3 (gradle home directory) export PATH = $GRADLE_HOME/bin: $PATH export GRADLE_USER_HOME = / home/mojito/application/gradle/repository (grale download the jar storage location)Copy the code
CD/home/mojito/application/gradle/gradle - 4.10.3 / init. D (in the directory of your installation gradle) touch init. GradleCopy the code
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
After everything is done, test whether it is ready and execute the command as shown in the following figure
gradle --version
Copy the code
[Start building]
The gradlew command is not recommended because it does not require you to install Gradle locally. It will automatically download gradle binaries from the Internet for you to build your project. Greatly affect the build speed, recommended to proceed as follows)
Download the source code
Spring has been imported into Gitee, clone or zip is fast, first download spring source code to local. The directory to/home/mojito/workspace/opensource/spring framework
Two, start building
1. Enter the source directory/home/CD mojito/workspace/opensource/spring - framework 2. Oxm gradle cleanIdea: Spring-OXm :compileTestJava 3. 2). After the Project is created, File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle 4. Configure the gradle environment for the current project (if you do not configure gradle, you will download gradle from the web using the Wrapper configuration.Copy the code
Complete the above steps, just wait for the completion of the build, the network speed is more than 20 minutes to enjoy the fragrant Spring source code.
[appendix]
A: Github project imports Gitee
- Get the clone address of the project on Github.
- Choose to import projects from Github on Gitee
- Fill in the first input box with the copied URL, click Import, and wait
When you’re done, you get flying speed