SPRING01_基于gradle6.8.2和JDK15搭建Spring源码坏境
Posted TZ845195485
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SPRING01_基于gradle6.8.2和JDK15搭建Spring源码坏境相关的知识,希望对你有一定的参考价值。
①. 坏境搭建说明
-
①. 注意注意:搭建spring源码环境,IDEA版本要用新版2020系列/2021的IDEA来构建spring源码环境,否则低于2020版本的idea,是不支持gradle 6.8.2以上高版本
-
②. gradle6.8.2 链接:https://pan.baidu.com/s/1aaOLqaH8Y-Es4lvxxmYnzg 提取码:1234
gradle官网下载地址
JDK15 链接:https://pan.baidu.com/s/1DQyjPmWSn-N8LVJVizamNg 提取码:1234 -
③. 将下载的gradle解压到磁盘下
-
④. 配置环境变量
-
⑤. 配置下载加速
Gradle还是从 maven 仓库下载的。
给gradle安装目录下init.d文件夹,放一个init.gradle文件
allprojects{
repositories {
def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
all { ArtifactRepository repo ->
def url = repo.url.toString()
if ((repo instanceof MavenArtifactRepository) && (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com'))) {
project.logger.lifecycle 'Repository ${repo.url} replaced by $REPOSITORY_URL .'
remove repo
}
}
maven {
url REPOSITORY_URL
}
}
}
# 下面这个可以不用
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
google {
url GOOGLE_URL
}
maven {
url NEXUS_URL
}
}
}
repositories {
def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
println("buildscript ${repo.url} replaced by $JCENTER_URL.")
remove repo
}
else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
remove repo
}
else if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
remove repo
}
}
}
jcenter {
url JCENTER_URL
}
google {
url GOOGLE_URL
}
maven {
url NEXUS_URL
}
}
}
}
- ⑥. 配置idea整合
如果你环境变量配置了GRADLE_USER_HOME,idea一般都会自动帮你感应到,如果没有感应到,那你自己指定一下
②. 将源码环境导入到码云
-
②. 可同步Spring在github上的仓库地址源码的,若也想跟我一样的话,请看如下操作与截图:
-
③. 同步spring的github源码地址到自己的码云仓库里面,然后点击确定即可
③. 拉取项目,导入IDEA
- ①. 然后利用git Bach来进行下载,注意一定要指定分支
- ②. 下载下来以后,导入到idea里面
- ③. 然后就开始构建Spring源码了,进来项目以后,点Cancel,先别让他加载,先进来设置jdk15
- ④. 然后点右侧giadle进行项目的刷新,开始重新加载工程
- ⑤. 如无意外,构建Spring源码完成:
④. 测试源码环境
- ①. 创建一个子工程名为:springsource-test,然后创建一个MainTest类进行测试
- ②. 随便找个spring的工程,比如找这个spring-websocket工程里面的spring-websocket.gradle这个配置,在这个spring-websocket.gradle里面找dependencies下面的compile(如下图所示)
compile(project(":spring-context"))
-
③. 比如就测试spring的ioc容器,就把compile(project(":spring-context"))这个复制到springsource-test工程下面的build.gradle的里面dependencies下面添加进去(如下图所示)
- ④. 然后重新刷新一下springsource-test这个工程 -
⑤. 只要引入相关依赖成了,就可以创建一个IOC容器进行测试了
一旦快捷键有提示,就说明引入成功了
package com.xiaozhi.bean;
public class Person{
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\\'' +
'}';
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="com.xiaozhi.bean.Person" id="person">
<property name="name" value="tangzhi"></property>
</bean>
</beans>
package com.xiaozhi;
import com.xiaozhi.bean.Person;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MainTest {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
Person bean = context.getBean(Person.class);
System.out.println(bean);
}
}
以上是关于SPRING01_基于gradle6.8.2和JDK15搭建Spring源码坏境的主要内容,如果未能解决你的问题,请参考以下文章
SPRING01_基于gradle7.4.2和JDK17搭建Spring源码坏境