intellij idea gradle 导入 spring 问题记录

环境:

  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

intellij idea gradle 导入 spring 问题记录

修改docs.gradle文件 >>> dokka方法以及asciidoctor方法注释

intellij idea gradle 导入 spring 问题记录

 intellij idea gradle 导入 spring 问题记录

注: 

task schemaZip(type: Zip) 在某些版本该任务中是没有兼容window的路径符号,需要手动修改一下

intellij idea gradle 导入 spring 问题记录

 修改如下  >>>>>>>

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版本问题

intellij idea gradle 导入 spring 问题记录

打开./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

成功导入展示:

intellij idea gradle 导入 spring 问题记录

4. 编译源代码

这里先看一下spring的markdown文档

intellij idea gradle 导入 spring 问题记录

 大致意思是需要先预编译`spring-core`、`spring-oxm`以及`spring-aspects`。

 先直接编译`spring-oxm`它依赖了`spring-core`

 gradle窗口中选择spring-oxm > Tasks > other > compileTestJava

然后是`spring-aspects` >>>
spring-aspects > Tasks > other > compileTestJava

如果失败请先安装ajc编译器 https://www.eclipse.org/aspectj/downloads.php

intellij idea gradle 导入 spring 问题记录

 点击Test 

intellij idea gradle 导入 spring 问题记录

再生成即可

----------------------------------------------------------------------------------

目前遇到问题就这几点,希望能帮助到大家。