文章目录
安装gradle
- 参考:https://blog.csdn.net/vistaed/article/details/106960918
IDEA配置gradle
- https://blog.csdn.net/vistaed/article/details/106960918
- https://blog.csdn.net/vistaed/article/details/107235528 这个文章一定要看,当然还得需要结合下面的一些配置,加速spring
build
下载源码
- 打开git
- 克隆 https://github.com/spring-projects/spring-framework.git
导入源码
- 我是直接open这个项目的
配置加速
- 我们的文件可能有所不同是因为我删除了某些东西~~~
build.gradle
- spring-farmeword项目下面有这个文件,打开进行配置
- 需要注意的是要在
plugins{...}
之后配置
plugins {
id 'io.spring.dependency-management' version '1.0.9.RELEASE' apply false
id 'org.jetbrains.kotlin.jvm' version '1.3.72' apply false
id 'org.jetbrains.dokka' version '0.10.1' apply false
id 'org.asciidoctor.jvm.convert' version '2.4.0'
id 'io.spring.nohttp' version '0.0.5.RELEASE'
id 'de.undercouch.download' version '4.0.4'
id "io.freefair.aspectj" version '5.0.0' apply false
id "com.github.ben-manes.versions" version '0.28.0'
id "me.champeau.gradle.jmh" version "0.5.0" apply false
}
// 新加配置,需要配置在plugins{} 下面
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'}
}
// 新加配置,需要配置在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'}
}
}
settings.gradle配置
- 这个文件位于spring-farmeword的目录下
- 将默认配置换成这个
pluginManagement {
repositories {
gradlePluginPortal()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
maven { url "https://repo.spring.io/libs-spring-framework-build" }
}
}
报错
我在bind的时候报错了
plugins {
id "com.gradle.enterprise" version "3.2"
//这里会报错,不知道为什么,我直接注掉了
// id "io.spring.gradle-enterprise-conventions" version "0.0.2"
}
搭建自己的测试MODE
- 选择父级项目,创建模块
选择gradle
下一步下一步即可
- 由于我已经创建过了这
- 输入对应的信息即可
项目配置build.gradle
- 这个文件是刚创建项目里面的文件而不是根目录的~~~
- 导入这些包,基本就可以跑起来了,
dependencies {
compile(project(":spring-beans"))
compile(project(":spring-web"))
compile(project(":spring-oxm"))
compile(project(":spring-core"))
compile(project(":spring-context"))
testCompile group: 'junit', name: 'junit', version: '4.12'
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
测试跑一下
- 需要注意的是,需要自己创建一个package~~~
public class TestSpringSource {
public static void main(String[] args) {
//初始化入口
AnnotationConfigApplicationContext ax = new AnnotationConfigApplicationContext(SpringSourceConfig.class);
AService bean = ax.getBean(AService.class);
}
}
创建service
- 这里输出可能会乱码,参考下面文章
- https://blog.csdn.net/vistaed/article/details/106965442
@Service
public class AService {
public AService() {
System.out.println("我执行了");
}
}
创建扫描
@ComponentScan("vip.xjdai.service")
public class SpringSourceConfig {
}
后言
- 我是这个做是跑起来的…
必看
- 编译速度问题:https://blog.csdn.net/vistaed/article/details/107235528
- 编译问题:https://blog.csdn.net/vistaed/article/details/107354547