idea构建spring源码项目

成功的环境 : jdk1.8.0_271/idea2019.1.3/gradle-4.4.1-bin.zip/spring-framework1-5.0.x

特别感谢借鉴的另两位博主

IntelliJ IDEA导入Spring源码_VFINE的博客-CSDN博客_idea导入spring源码

spring源码构建_l梁晴的博客-CSDN博客

1.下载源代码

源码下载地址

GitHub - spring-projects/spring-framework: Spring Framework

不建议从这个地址直接下载,太慢,可以fork到国内的码云上再下载非常快,

(源码下载可以在搜索引擎中搜索github,进入后搜索spring-framework即可找到)

也可以从这里下载,这个只需要安装并在idea中配置好gradle,就可以直接导入运行的,本地测试成功:

1294480-spring-framework1-5.0.x(3).zip-互联网文档类资源-CSDN下载

我是直接下载的压缩包

 找到gradle-wrapper.properties配置文件(这里指定了默认的gradle版本,下载这个版本就可以了):

2.下载gradle解压后配置环境变量

下载地址: Gradle | Releases

环境变量配置方法 : Gradle安装及环境变量配置_iBaoxing的博客-CSDN博客

3.修改配置文件

gradle-wrapper.properties修改结果:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=file:///D:\myprogram\tools\gradle-4.4.1-bin.zip

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip

改为

distributionUrl=file:///D:\myprogram\tools\gradle-4.4.1-bin.zip
这样就不需要再次下载了

build.gradle修改

		maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
		maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } 
		maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}

新增以下配置(没有以下配置,构建过程超级慢……),定义全局的国内镜像,注意该配置不能在plugins { }之前

allprojects {
	repositories {
		maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
		maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
		maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
		maven { url 'http://repo.springsource.org/plugins-release'}
	}
}

4.配置idea

配置gradle

 注意taget目录

这里我踩了个大坑,自己其他项目有target目录需要忽略,这里恰巧需要用到这个目录 

5.导入项目

 跟maven相似,项目加载会下载相关jar包,这个过程比较漫长,可能有半个小时

6.新建测试模块:

选中项目右键-->new -->modoule

 默认就是这样的

 填入项目名

修改新项目中build.gradle,添加依赖

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

7.添加测试类

package com.study;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class TestMy {

	public static void main(String[] args) {
		ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SysConfig.class);
		User user = (User)applicationContext.getBean("user");
		System.out.println(user.toString());
	}
}
package com.study;

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

@Configuration
@ComponentScan
public class SysConfig {

	@Bean
	public User user(){
		return new User("lq",12);
	}
}
package com.study;

public class User {
	private String name;
	private Integer age;

	public User() {
	}

	public User(String name, Integer age) {
		this.name = name;
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}


}

8.运行下main方法试试:

core模块报错 

重新编译一下spring-core

编译成功

spring-context没有成功引用spring-Instrument

 修改引用spring-instrument

 9.大功告成,完结

好长时间没有打开,今天打开总报错

org.springframework.cglib.core.DefaultNamingPolicy这个包找不到,

网上的办法好多都是自己敲命令,我本地又无法执行

D:\myprogram\workspace\other\1294480-spring-framework1-5.0.x (3)>gradle objenesisRepackJar
The project name '1294480-spring-framework1-5.0.x (3)' contains at least one of the following characters: [ , /, \, :, <, >, ", ?, *, |]. This has been deprecated and is scheduled to be removed in Gradle 5.0. Set the 'rootProject.name' or adjust the 'include' statement (see https://docs.gradle.org/4.4.1/dsl/org.gradle.api.initialization.Settings.html#org.gradle.api.initialization.Settings:include(java.lang.String[]) for more details).

FAILURE: Build failed with an exception.

* What went wrong:
Task 'objenesisRepackJar' not found in root project '1294480-spring-framework1-5.0.x (3)'.

* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

D:\myprogram\workspace\other\1294480-spring-framework1-5.0.x (3)>

解决办法简单的难以置信,点击1.objenesisRepackJar                2. objenesisRepackJar 

我是这个顺序成功的,倒过来应该也是可以的,还没有测试

compile(project(":spring-aspects"))

引入spring-aspects时出现了问题,运行时这个下边的包都找不到原来,aspects模块比较特别,它依赖了aspect,需要安装aspect和配置idea,大家可以去这里借鉴一下
链接地址: AspectJ Downloads | The Eclipse Foundation

配置:

 

spring源码项目使用spring-aspects_web_13004735258的博客-CSDN博客

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值