2

在本地搭建spring-framework5环境

 3 years ago
source link: https://tianmingxing.com/2021/04/03/%E5%9C%A8%E6%9C%AC%E5%9C%B0%E6%9E%84%E5%BB%BAspring-framework5%E6%BA%90%E7%A0%81/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在本地搭建spring-framework5环境

发表于

2021-04-03 更新于 2021-06-13 分类于 java spring5

查看项目创建的所有标签,下面克隆5.3.5版本的源码。

# 基于标签克隆源码到本地
git clone --depth 1 --branch v5.3.5 [email protected]:spring-projects/spring-framework.git

# 克隆下来的版本处于游离状态,所以还要创建本地分支(非强制要求)
git switch -c v5.3.5
  • 如果像上面按照SSH协议克隆,需要提前配置SSH key。
  • 如果因为网络问题导致克隆比较慢,甚至克隆失败,那么你也可以直接下载压缩包。采用这种方式时需要把解压出来的目录变成本地git仓库,然后把文件全部提交,否则构建脚本会报错。

在IDEA中打开项目会自己进入构建(JDK11),可能出现下载gradle错误Cause: connect timed out,我们可以这样来解决。

  1. 用浏览器下载gradle-6.8.3-bin.zip,假设将其放在本地目录E:\ProgramFiles\gradle-6.8.3中(注意路径中不要有空格)。
  2. 在Spring源码目录中打开gradle/wrapper/gradle-wrapper.properties文件,将distributionUrl的值改为本地路径file\:/e:/ProgramFiles/gradle-6.8.3/gradle-6.8.3-bin.zip
  3. 重启IDEA重新进行构建

编译过程中可能出现下载包失败的情况,可能是包找不到,也可能是网络超时。对于这类情况的解决方法是配置国内镜像仓库。

  1. 打开根目录下的settings.gradle文件,在pluginManagement.repositories中增加阿里云的镜像。
    pluginManagement {
    repositories {
    maven { url 'https://maven.aliyun.com/repository/public/' }
    maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
    gradlePluginPortal()
    maven { url 'https://repo.spring.io/plugins-release' }
    }
    }
  2. 继续在plugins配置下面增加Gradle Enterprise服务器的配置。
    gradleEnterprise {
    buildScan {
    server = "https://gradle-enterprise.mycompany.com"
    }
    }
    必须使用JDK11来编译,否则会发现引入jdk.jfr.*路径的类找不到。也要在IDEA设置中找到gradle JVM并选择JDK11。

由于项目中使用到了kotlin,因此也需要通过IDEA插件管理中心来安装kotlin。

每个人遇到的问题可能不一样,主要是因环境的不同而异,遇到问题时注意看提示,然后分析下提示是什么意思?产生这种问题的途径有哪些?逐个排除就行。

找个单元测试用例来执行,例如:成功执行单元测试用例E:\Documents\source\opensource\spring-framework\spring-core\src\test\java\org\springframework\util\Base64UtilsTests.java#encode


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK