preface

describe The version number
The operating system win10
jdk 1.8.0 comes with _102
gradle 4.9
spring X 5.0.

Related packages are in the shared web disk

* * * * link: https://pan.baidu.com/s/1qDk4H9g5yGyrOOurXBGt7Q extraction code: lnt5Copy the code

Install the gradle

Download gradle

Services.gradle.org/distributio…

Other versions, tried a lot, this compilation passed, the test passed

Configuration gradle

Download it and unzip it

Configuring environment Variables

GRADLE_HOME

GRADLE_USER_HOME

Verify the gradle

Download spring source code

Version 5.0.x, several other versions were tried without success

Github.com/spring-proj…

Modify spring source configuration

Spring source download down, do not rush to import IDEA, first modify a few configurations

Configure gradle’s remote repository

Open the Gradle configuration file for Spring source code

Add the mirror source configuration in the following two ways

/ / configuration domestic mirror source maven {url 'http://maven.aliyun.com/nexus/content/groups/public/'} maven {url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}Copy the code

The gradle version used to configure the source code

DistributionUrl = file:///E:/yuanma/gradle-4.9-all.zipCopy the code

The distributionUrl value here points to the gradle-4.9-all.zip package we downloaded

Modify the spring-beans.gradle file configuration

Comment out some incorrect configurations and replace them with new ones

def deps = compileGroovy.taskDependencies.immutableValues + compileGroovy.taskDependencies.mutableValues
compileGroovy.dependsOn = deps - "compileJava"
compileKotlin.dependsOn(compileGroovy)
compileKotlin.classpath += files(compileGroovy.destinationDir)
Copy the code

Import the idea of

After the above steps, you can import the project into IDEA

After downloading the dependencies, you can see the imported Spring modules in the Gradle control panel

Compile OXM, compile core

To compile the entire spring source, we need to pre-compile Spring-OXM and Spring-core

Click the following button in the Gradle panel to compile the OXM module

The result is as follows:

I’ve already compiled it, so it’s faster

Similarly, compile core modules

The result is as follows:

Compile the entire Spring source code

Once the OXM and core modules are successfully compiled, spring as a whole can be compiled

The result is as follows:

I’ve already compiled it, so it’s faster. The first time I compiled it, it took about half an hour. If you do not configure the domestic mirror source, the compilation will not pass.

At this point, spring compilation is complete. The overall structure of the project is as follows, and each module has a small blue mark in IDEA

Open the ApplicationContext class, select the class name, and press CTR + Alt + Shift + U to generate a UML inheritance diagram for the ApplicationContext class

Create a test module test

Create a spring-jiuge submodule

Modify the build.gradle file of spring-jiuge module to add dependencies

    compile(project(":spring-beans"))
    compile(project(":spring-core"))
    compile(project(":spring-context"))
    compile(project(":spring-aop"))
Copy the code

Create package com.jiuge, class User, JavaConfig, App

User.java

package com.jiuge; Public class User {private String userName; private String userName; public User(String userName) { this.userName = userName; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; }}Copy the code

JavaConfig.java

package com.jiuge; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; /** * @componentScan public class JavaConfig {** * @componentScan public class JavaConfig { @bean public User User(){return new User("九歌"); }}Copy the code

App.java

package com.jiuge; import org.springframework.context.annotation.AnnotationConfigApplicationContext; Public class App {public static void main(String[] args) {public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(JavaConfig.class); User user = (User) context.getBean("user"); System.out.println(user.getUserName()); }}Copy the code

Run the main method in app. Java class to output the corresponding user object userName field value “nine songs”, as follows:

With that, Spring-5.0.x compiles and tests pass.

Appendix — Problem record

The above compilation process, in the company computer, after home, take their own computer, according to the above steps for the second compilation, or encountered some problems.

The plug-in cannot be downloaded after the project imports IDEA

The plugin id “com.gradle.build-scan” version “1.8” cannot be downloaded. Click Open File as prompted to locate the id “com.gradle.build-scan” version “1.8” as shown below:

Solution steps:

  1. Comment out the plug-in section to trigger compilation

  1. If the compile is triggered, an error message is displayed, as follows:

  1. Reopening the annotated plug-in and retriggering compilation solves the problem.

Run gradle build-x test-x Javadocjar on console. The jar will be automatically loaded, as shown in the figure below:

After oxM and core are compiled, it takes a long time to compile the whole Spring project

Solution steps:

  1. Build. Gradle is not compiling the doc file.

  1. Comment out the dokka and asciidoctor sections of the docs. Gradle file as shown below:

With the above comments out, the compile time is reduced to a few minutes