Idea构建Spring问题解决
2020-08-13 本文已影响0人
slowwalkerlcr
软件
- Idea 2020.1
- Jdk 1.8
- gradle-5.5.1
问题一
Idea和Spring Kotlin版本不一致
解决方法
-
查看IEDA kotlin版本
image.png
- 修改Spring根补录下build.gradle对应的kotlin版本,如图


问题二 下载jar包慢
更换为阿里云镜像仓库地址
1、配置gradle
在gradle根目录:\init.d\下,新建一个:init.gradle 文件,添加以下内容
设置gradle的源 为阿里云
allprojects{
repositories {
def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
all { ArtifactRepository repo ->
def url = repo.url.toString()
if ((repo instanceof MavenArtifactRepository) && (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com'))) {
project.logger.lifecycle 'Repository ${repo.url} replaced by $REPOSITORY_URL .'
remove repo }
}
maven {
url REPOSITORY_URL }
}}
2、修改Spring配置
配置spring源码根目录下的build.gradle文件:
注释configurations.all (注意不要注释错了,这里要小心,截图如下)
同时,添加一段配置
allprojects {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
}

3、修改Idea 的gradle配置
- 3.1
File -> New -> Project from Existing Sources -> 找到选择spring-framework源码
然后配置项目的gradle 为自己的下载安装的gradle,不用使用idea自带的,如图
image.png
- 3.2 这个时候 idea应该开始自动build了,然而发现 还是很慢。这里还有一处配置(
注意是spring根补录下的setting.gradle
)
# 在第一行插入
pluginManagement {
repositories {
maven { url "https://maven.aliyun.com/repository/public" }
gradlePluginPortal()
maven { url 'https://repo.spring.io/plugins-release' }
}
}

最后,保存好一切设置后,建议重启idea,重新打开项目,然后就会发现,飞一样的速度,编译通过!
