IDEA builds the latest Spring source code environment based on Gradle and JDK11

Posted by atravotum on Sun, 12 Sep 2021 05:00:16 +0200

The status of spring is self-evident. Many big guys have studied it. I believe you have been asked to talk about IOC, AOP, spring startup process, Bean initialization process, circular dependency and other issues more than once in the interview. Just looking at the eight part essay written by others, I haven't seen the source code. I don't know what to say. Only by studying it myself can I know what others are saying. Even if I can't understand it thoroughly, it should be easier to memorize it by rote. Therefore, it is necessary to build the spring source code environment. I thought about building it for a long time, but I haven't had time (busy playing). Spring can build it well or build SpringBoot. These two things are basically indispensable in the interview.
Don't talk too much nonsense.
The latest version of Spring source code basically uses the Gradle environment. In addition, JDK11 must be used. I originally built JDK1.8. There will be garbled code and one of the packages will not be found. If you want to dynamically switch between JDK11 and JDK1.8, you can see the first step below.

Build environment:Spring Source code 5.X +  Gradle 6.9.1 A stable new version is also OK + JDK11

Here are three steps to complete the construction of the Spring source code environment. If there are already JDK and Gradle environments, you can directly see the third step. The first step and the second step click the link below. Here we mainly talk about the third step.
I JDK11 installation and dynamic switching of JDK8;
2, Installation and download of Gradle;
3, Spring source code download and environment construction;
It is recommended to fork a code in github and clone it locally so that you can add your own comments and submit it.
Project address of github in Spring

Then import the project into the idea. You may be prompted that the idea is not configured with gradle. Configure it as follows.

Then you need to modify several file configurations of the source code.

Modify build.gradle by about 290 lines

		repositories {
			// Add 2 Ali image addresses
			maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
			maven { url 'https://maven.aliyun.com/repository/spring' }
			maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
			mavenCentral()
			maven { url "https://repo.spring.io/libs-spring-framework-build" }
			// New spring plug-in library
			maven { url "https://repo.spring.io/plugins-release"}
		}

Modify the second and tenth lines of the settings.gradle file

	repositories {
		maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
		maven { url "https://maven.aliyun.com/repository/public" }
		gradlePluginPortal()
		maven { url 'https://repo.spring.io/plugins-release' }
	}


plugins {
	id "com.gradle.enterprise" version "3.6.1"
	//A build scan was not published as you have not authenticated with server 'ge.spring.io'
	// id "io.spring.ge.conventions" version "0.0.7"
}

Modify the gradle.properties file

version=5.3.10-SNAPSHOT
org.gradle.jvmargs=-Xmx2048M
org.gradle.caching=true
org.gradle.parallel=true
kotlin.stdlib.default.dependency=false
org.gradle.configureondemand=true
org.gradle.daemon=true

Modify the gradle-wrapper.properties file

The configuration is as follows:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=file:///G:/gradle/gradle-6.9.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

The configuration is basically completed. Next, verify whether it is successful.
The spring source code provides us with a test method. Run the test package under the spring context module:

As a result, if the basic test cases can pass, the environment will be built successfully. As for the research on the source code, it depends on your own play.

Reducing maintenance costs is more important than reducing implementation costs.
The maintenance cost of the system is positively correlated with the complexity of the system—— Software design principles

Topics: Java Spring IDEA