eclipse导入idea项目_源码学习:IDEA成功导入、编译、调试SPRING5源码项目


成功编译(不代表就完全成功,需要测试成功才是最终成功)

dd8110299b03f2aa1a84721b756efc7c.png

测试成功

7b4e07b098824a1ea502f6fc2533286e.png


看到项目调试成功,那就可以开启我们的源码学习之路啦!!!!错误信息汇总:
1、TASK API:这个任务出现error,大都是javadoc出现问题,确定为JDK版本不对
正确做法是换为我们要求的JDK版本即可!
2、成功编译后,运行自己的测试项目报错:找不到InstrumentationSavingAgent

6902a40f320d41ead4dcd82fadda3f1a.png


正确做法是spring-context.gradle修改 optional(project(":spring-instrument"))为 compile(project(":spring-instrument")),然后重新编译一下spring-context(compileTestJava+build),完美解决!


1、编译流程1.1、环境搭建:JDK1.8.0_211、GRADLE4.9、IDEA2019.1.2
JDK:jdk1.8.0_211(推荐这个版本)链接

98c1c0139d5701a57f7abbfbb64d4cc1.png

61f65c9ba2a662d8100d46c4a737b60a.png


Gradle:gradle4.9链接
Gradle的GRADLE_HOME环境配置和Java配置JAVA_HOME是一样的
记得在Path中配置%GRADLE_HOME%bin

0bfe07b0506a9a1a2518a698af1e7d4a.png

60072bd1c9339d0cc12ac3bc7a547069.png


IDEA:IDEA 2019.1.2
1.2、将源码导入IDEA
在IDEA中File->Open将源码的文件夹导入

4e807a4781f11cbd84aafb5771e14bf2.png


1、点击auto-import
2、点击使用本地的gradle
3、JVM环境设置为你的jdk1.8.0_211,也就是列表里的JAVA_HOME选项
4、在这里面配置vm选项
点击

1b15d61c1fd0e9bce8e6d1401e8eb4b4.png


设置VM为XX:MaxMetaspaceSize=2048m -Xmx2048m -XX:MaxHeapSize=1024m
点击ok即可
1.3、修改文件

fe5de695ca33156291370911de1b45e9.png


第一步:注释DOKKA和ASCIIDOCTOR

  1. /*dokka {
  2. dependsOn {
  3. tasks.getByName("api")
  4. }
  5. doFirst {
  6. classpath = subprojects.collect { project -> project.jar.outputs.files.getFiles() }.flatten()
  7. classpath += files(subprojects.collect { it.sourceSets.main.compileClasspath })
  8. }
  9. moduleName = "spring-framework"
  10. outputFormat = "html"
  11. outputDirectory = "$buildDir/docs/kdoc"
  12. sourceDirs = files(subprojects.collect { project ->
  13. def kotlinDirs = project.sourceSets.main.kotlin.srcDirs.collect()
  14. kotlinDirs -= project.sourceSets.main.java.srcDirs
  15. })
  16. externalDocumentationLink {
  17. url = new URL("https://docs.spring.io/spring-framework/docs/$version/javadoc-api/")
  18. packageListUrl = new File(buildDir, "api/package-list").toURI().toURL()
  19. }
  20. externalDocumentationLink {
  21. url = new URL("https://projectreactor.io/docs/core/release/api/")
  22. }
  23. externalDocumentationLink {
  24. url = new URL("https://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/")
  25. }
  26. }
  27. asciidoctor {
  28. sources {
  29. include '*.adoc'
  30. }
  31. resources {
  32. from(sourceDir) {
  33. include 'images/*', 'stylesheets/*', 'tocbot-3.0.2/*'
  34. }
  35. }
  36. logDocuments = true
  37. backends = ["html5"]
  38. // only ouput PDF documentation for non-SNAPSHOT builds
  39. if(!project.getVersion().toString().contains("BUILD-SNAPSHOT")) {
  40. backends += "pdf"
  41. }
  42. options doctype: 'book', eruby: 'erubis'
  43. attributes 'icons': 'font',
  44. 'idprefix': '',
  45. 'idseparator': '-',
  46. docinfo: '',
  47. revnumber: project.version,
  48. sectanchors: '',
  49. sectnums: '',
  50. 'source-highlighter': 'coderay@', // TODO switch to 'rouge' once supported by the html5 backend
  51. stylesdir: 'stylesheets/',
  52. stylesheet: 'main.css',
  53. 'spring-version': project.version
  54. }*/


第二步:修改SCHEMAZIP的两处位置,看注释行


  1. task schemaZip(type: Zip) {

  2. group = "Distribution"

  3. baseName = "spring-framework"

  4. classifier = "schema"

  5. description = "Builds -${classifier} archive containing all " +

  6. "XSDs for deployment at https://springframework.org/schema."

  7. duplicatesStrategy 'exclude'

  8. moduleProjects.each { subproject ->

  9. def Properties schemas = new Properties();

  10. subproject.sourceSets.main.resources.find {
  11. //此处修改为

  12. it.path.endsWith("META-INFspring.schemas")

  13. }?.withInputStream { schemas.load(it) }

  14. for (def key : schemas.keySet()) {

  15. def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1')

  16. assert shortName != key

  17. File xsdFile = subproject.sourceSets.main.resources.find {
  18. //此处将Linux路径符号替换为Windows路径符号

  19. it.path.endsWith(schemas.get(key).replaceAll('/',''))

  20. }

  21. assert xsdFile != null

  22. into (shortName) {

  23. from xsdFile.path

  24. }

  25. }

  26. }

  27. }


1.4、预编译
第一步:打开源码文件夹中的

861e9b7ac3487eef8408779250f5109d.png

6b0f58569b55a8f47bf5de3c160ca660.png


spring-oxm和spring-core需要预先编译
第二步:预编译
打开gradle面板,找到各个源码模块,然后双击compileTestJava

011c68669eae1d108aa1c2245ca11d6d.png

fd96cf39260092d0ab7ef5df69914ce5.png

46be867ecef05b16b8e16a1ac62b8de5.png


第三步:整体编译

2881ed162a92b46d957c67e760827298.png


等待即可,大概20-40分钟

dd8110299b03f2aa1a84721b756efc7c.png


2、测试模块
在源码项目new一个moudle,类型为gradle的管理的java项目即可

dc9722ce0f86dbfb53cf43c8a212e9b7.png


自己使用注解测试一下即可

460fe8afac22db272e9d211ac2ee7fe5.png


UserDao.java


  1. package com.lpf.dao;

  2. import org.springframework.stereotype.Repository;

  3. @Repository

  4. public class UserDao {

  5. public void printInfo(){

  6. System.out.println("user dao");

  7. }

  8. }


Test.java


  1. package com.lpf.test;

  2. import com.lpf.dao.UserDao;

  3. import com.lpf.utils.AnnotationConfig;

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

  5. public class Test {

  6. public static void main(String[] args) {

  7. AnnotationConfigApplicationContext ac=new

  8. AnnotationConfigApplicationContext(AnnotationConfig.class);

  9. UserDao userDao=(UserDao) ac.getBean(UserDao.class);

  10. userDao.printInfo();

  11. }

  12. }


AnnotationConfig.java


  1. package com.lpf.utils;

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

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

  4. @Configuration

  5. @ComponentScan("com.lpf")

  6. public class AnnotationConfig {

  7. }


build.gradle添加compile project(":spring-context")


  1. dependencies {

  2. testCompile group: 'junit', name: 'junit', version: '4.12'

  3. compile project(":spring-context")

  4. }

运行Test.java,出现下图即证明spring5.1.x项目完美部署成功!

7b4e07b098824a1ea502f6fc2533286e.png
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值