Idea build and compile spring5.1.x source environment

Preface

We usually write projects every day and always use spring. I personally feel that we face spring every day, and we have never compiled the spring source code, which is a bit inappropriate. So today we will compile the source code environment and take a note by the way.

Here is my configuration: JDK1.8.0_172, IntelliJ IDEA 2019.1 (Ultimate Edition), gradle-5.4 .

Note: gradle version needs to be above 4.2

The first step: to ensure that our environment has been fully prepared.

Step 2: Download the spring source code, the source code download address: https://github.com/spring-projects/spring-framework , here is the zip I downloaded.

Step 3: Unzip the project, and then import idea. After the import is complete, we need to pay attention to a file, import-into-idea.md, with the following content:

1. `spring-core` and `spring-oxm` should be pre-compiled due to repackaged dependencies.

Because other projects need to rely on spring-core and spring-oxm, we need to compile these two packages after importing. Compile these two projects first

Step 4: Pay attention before compiling . When compiling with tools, memory overflow may occur. Here we need to add relevant parameters when compiling

-XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m

As shown:

 Note: The pit I guessed here , the jdk version, should not be too high. I have used jdk1.8_20 and jdk1.8_191 to compile, and there will be version problems. I later used the 1.8_131 and 1.8.0_172 versions. success

Step 5: If the above steps are all completed, then start compiling. Since it takes a long time to download the gradle warehouse jar package (I need 26 minutes here), it is time to fight the machine performance and network speed

 After the compilation is successful (it does not mean complete success, the final success needs to be tested successfully), after the compilation is successful, as shown below:

Use the spring source code just compiled to build the spring project, create a new moudle in the project directory, and introduce the corresponding dependencies 

After the new project is completed, as follows, introduce dependencies and add test classes

 UserDao

package com.zoo.dao;

import org.springframework.stereotype.Repository;

/**
 * @author: 谢飞
 */
@Repository
public class UserDao {
	public void printInfo() {
		System.out.println("user dao");
	}
}

AppConfig

package com.zoo.utils;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author: 谢飞
 */

@Configuration
@ComponentScan("com.zoo")
public class AppConfig {
}

Test

package com.zoo;

import com.zoo.dao.UserDao;
import com.zoo.utils.AppConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author: 谢飞
 */
public class Test {
	public static void main(String[] args) {
		AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class);
		UserDao userDao = ac.getBean(UserDao.class);
		userDao.printInfo();
	}

}

Click to run the error as follows:

The correct way is to modify spring-context.gradle optional(project(":spring-instrument")) to compile(project(":spring-instrument")), 

Then rebuild the spring-context project, and click run

Final console output:

The project is built and output correctly. At this point, the spring5.1.x project has been built and compiled.

Guess you like

Origin blog.csdn.net/qq_36850813/article/details/103252426