spring构建
1.找到github地址
https://github.com/spring-projects/spring-framework/tree/v5.3.5
https://github.com/spring-projects/spring-boot/tree/v2.4.4
2.复制到gitee里面,弄成自己的仓库
3.用git命令行工具
git clone https://gitee.com/wisper_wind/spring-framework.git
git clone https://gitee.com/wisper_wind/spring-boot.git
4.使用命令行执行gradlew
cmd进入spring-framework目录,执行命令gradlew build
5.idea打开
- Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle)
- 报错
```shell
Project resolve errors D:\SpringProject\spring-framework\build.gradle root project ‘spring’: Unable to resolve additional project configuration. Details: java.lang.IllegalStateException: Resolving dependency configuration ‘testFixturesCompileOnly’ is not allowed as it is defined as ‘canBeResolved=false’. Instead, a resolvable (‘canBeResolved=true’) dependency configuration that extends ‘testFixturesCompileOnly’ should be resolved.
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.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) at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.access$200(GradleProjectResolver.java:60) at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:725) at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:708) at org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper.execute(GradleExecutionHelper.java:276) at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:125) at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:60) at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.lambda$resolveProjectInfo$0(RemoteExternalSystemProjectResolverImpl.java:35) at com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:57) at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:35) at com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:44) at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:100) at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:146) at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:132) at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3.executeImpl(ExternalSystemUtil.java:540) at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3.lambda$execute$1(ExternalSystemUtil.java:392) at com.intellij.openapi.project.DumbServiceImpl.suspendIndexingAndRun(DumbServiceImpl.java:150) at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3.execute(ExternalSystemUtil.java:392) at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$5.run(ExternalSystemUtil.java:647) at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:888) at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:163) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:585) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:531) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:59) at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:150) at com.intellij.openapi.progress.impl.CoreProgressManager$4.lambda$run$0(CoreProgressManager.java:402) at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:221) at com.intellij.openapi.progress.impl.CoreProgressManager$4.run(CoreProgressManager.java:402) at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:238) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834)
<a name="pja9m"></a>
## 6.解决问题
报错里面出现了idea,全网搜索的方法都不行,参观[官网的构建文档](https://github.com/spring-projects/spring-framework/wiki/Build-from-Source)<br />官网的命令行build是可以的,idea的build会报错,可能是idea版本和spring构建gradle冲突导致的,回到idea里面,切换spring的版本到5.2.x(原先是最新的5.3.5)<br />![image.png](https://cdn.nlark.com/yuque/0/2021/png/655064/1618294845479-64634b32-c44a-4142-824d-f7dd9187d569.png#align=left&display=inline&height=339&margin=%5Bobject%20Object%5D&name=image.png&originHeight=678&originWidth=246&size=27693&status=done&style=none&width=123) <br />查看gradle.properties里面是:version=5.2.14.BUILD-SNAPSHOT,网上说最好用稳定的RELEASE.这边没注意
继续<br />gradlew build<br />gradlew :spring-oxm:compileTestJava<br />都是成功<br />然后用idea打开就可以了
<a name="buD5k"></a>
## 7.测试
![image.png](https://cdn.nlark.com/yuque/0/2021/png/655064/1618295114941-6976e4b1-9ed9-4c8b-be0e-4a886f8309d3.png#align=left&display=inline&height=327&margin=%5Bobject%20Object%5D&name=image.png&originHeight=653&originWidth=370&size=26217&status=done&style=none&width=185)<br />1.新建module<br />2.添加依赖
```bash
plugins {
id 'java'
}
group 'org.springframework'
version '5.2.14.BUILD-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile(project(':spring-context'))
testCompile group: 'junit', name: 'junit', version: '4.12'
}
3.写一些代码
4.运行
public class Demo01 {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfig.class);
Dog bean = context.getBean(Dog.class);
System.out.println(bean);
}
}
成功!
> Task :leo-test-01:Demo01.main()
四月 13, 2021 2:07:50 下午 org.springframework.context.support.AbstractApplicationContext refresh
信息: diy spring
Dog{name='ha'}
BUILD SUCCESSFUL in 24s
springboot构建
git
类似的
先git clone然后
git checkout -b 2.4.0 v2.4.0
报错
Filename too long
error: The following untracked working tree files would be overwritten by checkout:
解决:
git config —global core.longpaths true
git clean -d -fx
git checkout -b 2.4.0 v2.4.0 成功
build
cmd:D:\SpringProject\spring-boot>gradlew build
报
FAILURE: Build failed with an exception.
* Where:
Settings file 'D:\SpringProject\spring-boot\settings.gradle' line: 26
* What went wrong:
Error resolving plugin [id: 'io.spring.gradle-enterprise-conventions', version: '0.0.3']
> Could not resolve all dependencies for configuration 'detachedConfiguration2'.
> Could not determine artifacts for io.spring.gradle-enterprise-conventions:io.spring.gradle-enterprise-conventions.gradle.plugin:0.0.3
> Could not get resource 'https://repo.spring.io/plugins-release/io/spring/gradle-enterprise-conventions/io.spring.gradle-enterprise-conventions.gradle.plugin/0.0.3/io.spring.gradle-enterprise-conventions.gradle.plugin-0.0.3.jar'.
> Could not HEAD 'https://repo.spring.io/plugins-release/io/spring/gradle-enterprise-conventions/io.spring.gradle-enterprise-conventions.gradle.plugin/0.0.3/io.spring.gradle-enterprise-conventions.gradle.plugin-0.0.3.jar'. Received status code 401 from server: Unauthorized
去idea里面操作 修改build.gradle
修改setting.gradle
就可以正常build构建项目了,这一步比较慢