环境:
windows 7
oracle jdk 1.8
intellij idea 2019.3.1
spring-framework 5.1.22.RELEASE
步骤:
1: 下载解压spring zip 包(githup或者gitee下载)
2: 修改spring-framework源码配置信息
打开项目子目录 >>> ./gradle
修改docs.gradle文件 >>> dokka方法以及asciidoctor方法注释
注:
task schemaZip(type: Zip) 在某些版本该任务中是没有兼容window的路径符号,需要手动修改一下
修改如下 >>>>>>>
task schemaZip(type: Zip) { group = "Distribution" baseName = "spring-framework" classifier = "schema" description = "Builds -${classifier} archive containing all " + "XSDs for deployment at https://springframework.org/schema." duplicatesStrategy 'exclude' moduleProjects.each { subproject -> def Properties schemas = new Properties(); subproject.sourceSets.main.resources.find { (it.path.endsWith("META-INF/spring.schemas") || it.path.endsWith("META-INF\spring.schemas")) }?.withInputStream { schemas.load(it) } for (def key : schemas.keySet()) { def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1') assert shortName != key File xsdFile = subproject.sourceSets.main.resources.find { (it.path.endsWith(schemas.get(key)) || it.path.endsWith(schemas.get(key).replaceAll('\/','\\'))) } assert xsdFile != null into (shortName) { from xsdFile.path } } } }
先留一个坑 。。。。
3.导入项目 >>> 选中build.gradle右键import
漫长的等待中 。。。。
一般情况下导入是可以成功的,但 。。
exception during working with external system: java.lang.AssertionError at org.jetbrains.plugins.gradle.service.project.BaseGradleProjectResolverExtension.createModule(BaseGradleProjectResolverExtension.java:154) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.kotlin.idea.configuration.KotlinMPPGradleProjectResolver.createModule(KotlinMPPGradleProjectResolver.kt:67) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at com.android.tools.idea.gradle.project.sync.idea.AndroidGradleProjectResolver.createModule(AndroidGradleProjectResolver.java:165) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.kotlin.android.configure.KotlinAndroidMPPGradleProjectResolver.createModule(KotlinAndroidMPPGradleProjectResolver.kt:45) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.createModule(AbstractProjectResolverExtension.java:86) at org.jetbrains.plugins.gradle.service.project.TracedProjectResolverExtension.createModule(TracedProjectResolverExtension.java:45) at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.doResolveProjectInfo(GradleProjectResolver.java:344)
... ...
这个是因为spring配置的gradle版本问题
打开./gradle/wrapper/gradle-wrapper.properties文件
修改为5.x版本,博主修改为gradle-5.5.1-all.zip //all包含源码
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https://services.gradle.org/distributions/gradle-5.5.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
成功导入展示:
4. 编译源代码
这里先看一下spring的markdown文档
大致意思是需要先预编译`spring-core`、`spring-oxm`以及`spring-aspects`。
先直接编译`spring-oxm`它依赖了`spring-core`
gradle窗口中选择spring-oxm > Tasks > other > compileTestJava
然后是`spring-aspects` >>>
先打开 Project Structure窗口:
可以发现只有Kotlin的,还没有AspecJ;这时我们需要加上
加上这两个AspecJ即可。
spring-aspects > Tasks > other > compileTestJava
如果失败请先安装ajc编译器 https://www.eclipse.org/aspectj/downloads.php
点击Test
再生成即可
最后再多嘴啰嗦一句
这里默认是没有勾上的,如果你自己勾上了。。。
那么spring-aspectjs配置步骤就不生效了,因为之前配置没有写入 .iml文件中。
去掉勾选并删除 .idea文件下的modules文件夹试试吧
还有就是build.gradle 脚本是可以查看源码和语法提示的
只需要在修改gradle-wrapper.properties步骤中改好后,执行一下gradlew.bat文件就好了。
----------------------------------------------------------------------------------
目前遇到问题就这几点,希望能帮助到大家。