# spring-framework **Repository Path**: capcat/spring-framework ## Basic Information - **Project Name**: spring-framework - **Description**: spring-framework源码构建 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-16 - **Last Updated**: 2024-05-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Spring Framework [![Build Status](https://ci.spring.io/api/v1/teams/spring-framework/pipelines/spring-framework-5.3.x/jobs/build/badge)](https://ci.spring.io/teams/spring-framework/pipelines/spring-framework-5.3.x?groups=Build") [![Revved up by Gradle Enterprise](https://img.shields.io/badge/Revved%20up%20by-Gradle%20Enterprise-06A0CE?logo=Gradle&labelColor=02303A)](https://ge.spring.io/scans?search.rootProjectNames=spring) 1. 参考链接: https://blog.csdn.net/weixin_43591980/article/details/116790551 2. 参考链接: https://ld246.com/article/1617104943096 #### Description spring-framework源码构建 仅供学习参考使用 #### 基础环境1 1. gradle: 6.9 2. java: openjdk 11 3. spring-framework: 5.3.9 4. IDEA: 2020.1 #### 基础环境2 1. gradle: 7.2 2. java: openjdk 11 3. spring-framework: 5.3.10 4. IDEA: 2021.2 #### 配置gradle(略) 注意:为保证尽量不出意外错误,gradle版本参考【spring-framework-5.3.10\gradle\wrapper\gradle-wrapper.properties】中指定的版本 ```text distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip ``` #### 修改配置文件 build.gradle ```text repositories { //mavenCentral() //maven { url "https://repo.spring.io/libs-spring-framework-build" } maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/'} maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'} mavenCentral() maven { url "https://repo.spring.io/libs-spring-framework-build" } } ``` settings.gradle ```text pluginManagement { repositories { maven { url "https://maven.aliyun.com/repository/public" } gradlePluginPortal() maven { url "https://repo.spring.io/plugins-release" } } } ``` #### 遇到的问题 ![avatar](/src/docs/images/spring_build_error1.png) > 解决办法: 注释掉 setting.gradle 中的 ge.spring.io #### 编译源码 在项目根目录打开命令行,依次执行以下命令 ```text 执行 cmd 执行 gradlew :spring-oxm:compileTestJava 预编译spring-oxm模块 cmd 执行 gradlew :spring-core:compileTestJava 预编译spring-core模块 ``` ![avatar](/src/docs/images/build.png) #### 导入项目至IDEA中(略) 以下内容参考import-into-idea.md 文件 ```text The following has been tested against IntelliJ IDEA 2016.2.2 ## Steps _Within your locally cloned spring-framework working directory:_ 1. Precompile `spring-oxm` with `./gradlew :spring-oxm:compileTestJava` 2. Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle) 3. When prompted exclude the `spring-aspects` module (or after the import via File-> Project Structure -> Modules) 4. Code away ## Known issues 1. `spring-core` and `spring-oxm` should be pre-compiled due to repackaged dependencies. See `*RepackJar` tasks in the build and https://youtrack.jetbrains.com/issue/IDEA-160605). 2. `spring-aspects` does not compile due to references to aspect types unknown to IntelliJ IDEA. See https://youtrack.jetbrains.com/issue/IDEA-64446 for details. In the meantime, the 'spring-aspects' can be excluded from the project to avoid compilation errors. 3. While JUnit tests pass from the command line with Gradle, some may fail when run from IntelliJ IDEA. Resolving this is a work in progress. If attempting to run all JUnit tests from within IntelliJ IDEA, you will likely need to set the following VM options to avoid out of memory errors: -XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m 4. If you invoke "Rebuild Project" in the IDE, you'll have to generate some test resources of the `spring-oxm` module again (`./gradlew :spring-oxm:compileTestJava`) ``` #### 测试 创建gradle项目,引入本地spring模块 ```text dependencies { compile project(":spring-context") compile project(":spring-core") compile project(":spring-beans") testCompile group: 'junit', name: 'junit', version: '4.12' } ``` 注意:Gradle 7+ 中删除了compile和testCompile配置。可以改用implementation和testImplementation。 ```text dependencies { //Gradle 7+ 中删除了compile和testCompile配置。您可以改用implementation和testImplementation。 implementation(project(":spring-context")) implementation project(":spring-core") implementation project(":spring-beans") testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' } ``` #### 测试中遇到的问题 如果jdk版本设置正确,测试中一直遇到【java: 程序包jdk.jfr不存在】问题时,可以调整以下设置解决(本机环境采用此办法解决) Settings -> Build, Execution, Deployment -> Build Tools -> Gradle 设置 Build and run using : Gradle 设置 Run tests using : Gradle