IDEA 导入Spring 源码

本次导入 Spring 源码的相关版本为:

  1. Spring 5.X
  2. JDK 1.8.0_211
  3. IntelliJ IDEA 2018.1
  4. 项目中使用的是:Gradle 4.7  系统环境为: Gradle 5.2

一、下载并安装 Git 或者下载安装 GitHub

  1. Git 下载地址:https://git-scm.com/downloads
  2. GitHub下载地址:https://desktop.github.com/

二、通过 Git 或 GitHub 下载源码

  1. spring 的项目路径为:https://github.com/spring-projects/spring-framework
  2. 通过 Git clone Spring:git clone  git@github.com:spring-projects/spring-framework.git

三、下载安装 Gradle

  1. Gradle的下载路径为:http://services.gradle.org/distributions/
  2. 查看 Gradle 是否安装成功,命令为:Gradle -version,如图 1-1 中所示:
  3. 初始化 Gradle 。命令:Gradle init
图:1-1

四、构建 spring-oxm

  1. 在Spring项目中有个说明文件 import-into-idea.md。打开说明文件,说明文件中有几个步骤:
  • Precompile `spring-oxm` with `./gradlew :spring-oxm:compileTestJava`
  • Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle)
  • When prompted exclude the `spring-aspects` module (or after the import via File-> Project Structure -> Modules)
  • Code away
  1. 打开终端,切换至 Spring项目的目录:spring-framework
  2. 执行:gradlew :spring-oxm:compileTestJava
  3. 打开 settings.gradle 将 include "spring-aspects" 注释掉。

四、将 Spring 项目导入 IDEA 中

  1. File  —> New —>Project from Existing Source —>build.gradle。如图 1-2 和 1-3 中所示: 
1-2

 

1-3

五、可能出现的问题

版本问题,JDK 需要使用 1.8 ,如果是1.7及以下,则无法完成编译。

Gradle 的版本不清楚,建议使用的 Gradle 版本为 5.2。

2-1

会出现如图 2-1 中所示的报错。需要修改 build.gradle 文件,

buildscript {
   repositories {
      maven { url "https://repo.spring.io/plugins-release" }
      // 这行是新增加的
      maven { url "https://plugins.gradle.org/m2/" }
   }
   dependencies {
      classpath("io.spring.gradle:propdeps-plugin:0.0.9.RELEASE")
      classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16")
   }
}
// 3rd party plugin repositories can be configured in settings.gradle
plugins {
	id "io.spring.dependency-management" version "1.0.7.RELEASE" apply false
	id "org.jetbrains.kotlin.jvm" version "1.3.31" apply false
        // 从原来的 0.9.18 修改为 0.9.15
	id "org.jetbrains.dokka" version "0.9.15"
	id "org.asciidoctor.convert" version "1.5.8"
}

 

	configurations.all {
		// Check for updates every build
		resolutionStrategy.cacheChangingModulesFor 0, "seconds"

		// Consistent slf4j version (e.g. clashes between slf4j versions)
                // 这一段直接注释掉
//		resolutionStrategy.eachDependency { DependencyResolveDetails details ->
//			if (details.requested.group == "org.slf4j") {
//				details.useVersion slf4jVersion
//			}
//		}
	}
repositories {
		maven { url "https://repo.spring.io/libs-release" }
		maven { url "https://repo.spring.io/snapshot" } // Reactor
		maven { url "https://oss.jfrog.org/artifactory/libs-snapshot" } // RSocket
                // 新增仓库依赖 
                maven { url "https://plugins.gradle.org/m2/" }
		mavenLocal()
	}

在 IDEA 的 Settings 中将 Gradle 版本修改为 4.7 版本。

注:网上的各类 Spring 项目导入的教程很多,按着一步一步做也有构建不成功的情况,上述操作中我也不知道为什么最终成功了。请各位读者谨慎参考

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值