Spring5.3. x source code reading environment construction-gradleBuild to compile

The article directories

1. Rely on tools

  1. git

I won’t go into git tools

  1. jdk17

Open the www.oracle.com/java/techno… We built the spirng source code to learn from Spring, not to get to the end of the tree. If we build spirng5.3.x instead of JDk17, there will be some problems. So this article uses JDK17 to build spring source code!

3. Gradle – 7.4

Open services.gradle.org/distributio… Select the latest version: gradle-7.4-all.zip

Download and decompress the configuration environment variables

Then open CMD and enter gradle -v, as shown in the following figure, indicating that the environment variables are successfully configured

  1. idea

www.jetbrains.com/idea/ Click on the website to download it yourself

Download the source code

Many friends can’t pull down because of the network speedgithubThe source code! So we use it heregiteetoForkThe source code.

  • Why do you want toFork ? Now that we’ve started reading and debugging the source code, we’ll probably write some comments, have our own repository, and be free to commit.
  • The version of Spring used in this article isX 5.3.Master branch code (5.3.0-snapshot).
  • First of all,https://github.com/spring-projects/spring-frameworkClick the import button to Fork github’s Spring source code into your own Gitee repository.

Three, start building

Now that we have our repository address, we are ready to start building the source code

Copy Fork to gitee’s repository address

And I’m gonna hit Clone

Idea will download the build automatically when the clone is opened. Now we will click Cancel immediately.

Now we click file – > Settings – > build, Exection and Deployment – > build Tools – > Gradle

Then click Apply -> OK

Then go to the build.gradle file and configure the repositories variable as follows

Repositories {/ / add the following two ali cloud image maven {url 'https://maven.aliyun.com/nexus/content/groups/public/'} maven {url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' } maven { url "https://repo.spring.io/libs-spring-framework-build" } maven { url "https://repo.spring.io/snapshot" } mavenCentral() }Copy the code

Click the refresh button and wait for Gradle to build spring source code.

Compile the source code

Well, now that our source code is built, let’s start compiling it

ComplileTestJava = complileTestJava = complileTestJava = complileTestJava = complileTestJava

5. Source code testing

Open the build.gradle file of the created test directory to add the following code

dependencies { implementation(project(":spring-beans")) implementation(project(":spring-context")) testImplementation 'org. Junit. Jupiter: junit - Jupiter - API: 5.6.0' testRuntimeOnly 'org. Junit. Jupiter: junit - Jupiter - engine'}Copy the code

At the moment insrc->main->javaNext create two classesKukahaMain,SysConfig

import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class KukahaMain { public static void main(String[] args) { AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(SysConfig.class); System.out.println(annotationConfigApplicationContext); }}Copy the code
import org.springframework.context.annotation.Configuration;


@Configuration
public class SysConfig {
}
Copy the code

At this point, run the main method of the KukahaMain class. The result is to print a graphic showing that you have set up the spring source environment. Now you can start to play !!!!

Tail, the end of the flower

This article is the author step by step can succeed! I hope you have a good time. I will update the source code analysis of Spring later. I hope you can get more support from my friends !!!!!