为了编译spring5源码折腾了3天,
用了IDEA2019.3报错
exception during working with external system: java.lang.AssertionError
at org.jetbrains.plugins.gradle.service.project.BaseGradleProjectResolverExtension.populateModuleContentRoots(BaseGradleProjectResolverExtension.java:272)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
at org.jetbrains.kotlin.idea.configuration.KotlinMPPGradleProjectResolver.populateModuleContentRoots(KotlinMPPGradleProjectResolver.kt:65)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.populateModuleContentRoots(AbstractProjectResolverExtension.java:95)
at org.jetbrains.plugins.gradle.service.project.TracedProjectResolverExtension.populateModuleContentRoots(TracedProjectResolverExtension.java:62)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.doResolveProjectInfo(GradleProjectResolver.java:382)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.access$200(GradleProjectResolver.java:76)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:879)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:862)
at org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper.execute(GradleExecutionHelper.java:217)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:141)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:76)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.a(RemoteExternalSystemProjectResolverImpl.java:37)
at com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:58)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:37)
at com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:45)
at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:100)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:166)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:152)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3.execute(ExternalSystemUtil.java:554)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$5.run(ExternalSystemUtil.java:659)
at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:727)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:164)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:582)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:151)
at com.intellij.openapi.progress.impl.CoreProgressManager$4.run(CoreProgressManager.java:403)
at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:314)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
没有解决,懒得弄了,最后换回2019.2
idea编译经常遇到spring-beans编译不过去,报Unresolved reference: BeanFactory这个错也是没解决,其他小问题百度也能搜到解决办法,先总结下最简便的方法
准备工作jdk1.8.0_211,gradle-4.9,aspectj1.9安装配置自己百度
首先从GitHub下载spring5.0.x源码,我下载的是zip压缩包,解压后开始正式编译
第一步先运行gradlew.bat,双击或者命令行都可以
第二步:修改spring-beans.gradle中的注释掉以下两行
// compileGroovy.dependsOn = compileGroovy.taskDependencies.values - "compileJava"
// compileKotlin.dependsOn(compileGroovy)
修改docs.gradle注释下面两个,没有做研究,为什么要注释,有的网站说的是编译后有的目录不对
dokka {
dependsOn {
tasks.getByName("api")
}
doFirst {
classpath = subprojects.collect { project -> project.jar.outputs.files.getFiles() }.flatten()
classpath += files(subprojects.collect { it.sourceSets.main.compileClasspath })
}
moduleName = "spring-framework"
outputFormat = "html"
outputDirectory = "$buildDir/docs/kdoc"
sourceDirs = files(subprojects.collect { project ->
def kotlinDirs = project.sourceSets.main.kotlin.srcDirs.collect()
kotlinDirs -= project.sourceSets.main.java.srcDirs
})
externalDocumentationLink {
url = new URL("https://docs.spring.io/spring-framework/docs/$version/javadoc-api/")
packageListUrl = new File(buildDir, "api/package-list").toURI().toURL()
}
externalDocumentationLink {
url = new URL("https://projectreactor.io/docs/core/release/api/")
}
externalDocumentationLink {
url = new URL("https://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/")
}
}
asciidoctor {
sources {
include '*.adoc'
}
resources {
from(sourceDir) {
include 'images/*', 'stylesheets/*', 'tocbot-3.0.2/*'
}
}
logDocuments = true
backends = ["html5"]
// only ouput PDF documentation for non-SNAPSHOT builds
if(!project.getVersion().toString().contains("BUILD-SNAPSHOT")) {
backends += "pdf"
}
options doctype: 'book', eruby: 'erubis'
attributes 'icons': 'font',
'idprefix': '',
'idseparator': '-',
docinfo: '',
revnumber: project.version,
sectanchors: '',
sectnums: '',
'source-highlighter': 'coderay@', // TODO switch to 'rouge' once supported by the html5 backend
stylesdir: 'stylesheets/',
stylesheet: 'main.css',
'spring-version': project.version
}
修改build.gradle文件找到configurations.all添加xml-apis
configurations.all {
resolutionStrategy {
force 'xml-apis:xml-apis:1.0.b2'
}
}
修改上面的这个是因为有时会报错误,这个错误可以在D:\.gradle\daemon\4.4.1\daemon-XXX.out.log,.gradle目录是环境变量里面设置的GRADLE_USER_HOME这个参数值
POM relocation to an other version number is not fully supported in Gradle : xml-apis:xml-apis:2.0.2 relocated to xml-apis:xml-apis:1.0.b2.
Please update your dependency to directly use the correct version 'xml-apis:xml-apis:1.0.b2'.
Resolution will only pick dependencies of the relocated element. Artifacts and other metadata will be ignored.
第三步,开始编译,需要先编译spring-oxm,spring-beans两个module,为啥要编译spring-beans,在idea编译的时候经常会遇到上面提到的Unresolved reference: BeanFactory这个错误,
注意:我编译的是在命令行下,为了避免的IDEA报错,还的网上搜解决办法,浪费时间
在命令行下切换到spring-framework-5.0.x目录下,执行下面两个命令
gradlew :spring-oxm:compileTestJava
gradlew :spring-beans:compileTestJava
我本机测试时没有报错,IDEA不保证通过Gradle插件编译是否成功,偶尔会编译出错,一定要确保spring-beans编译的没有问题
第四步导入idea,修改IDEA配置
在导入的时候IDEA就会自动编译,如果没有编译点击下面按钮就会自动编译
剩下就是等待了.....
只要有上面这个就算是编译成功,编译成功后会继续编译测试,我的是在编译成功后,继续编译测试的时候出错了
这个不影响编译成功
剩下的就是新建module测试了,其他网站都写的有代码,直接拿来用就可以
测试有的网友可以直接测试运行,我的不知道是什么原因还的编译后才打印输出
最后要感谢其他网友提供的编译资料,在此不一一列举了
参考:https://juejin.im/post/5d75a8e56fb9a06ade113673#heading-1
http://www.it1352.com/344046.html
https://blog.csdn.net/lianjiaokeji/article/details/82177236
控制台有乱码的可以修改