前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >搭建SpringBoot源码环境的正确姿势(避坑必备)

搭建SpringBoot源码环境的正确姿势(避坑必备)

作者头像
明明如月学长
发布2021-08-27 16:30:37
1.6K0
发布2021-08-27 16:30:37
举报
文章被收录于专栏:明明如月的技术专栏

最近打算拉取SpringBoot源码,各种编译报错,各种问题。参考很多网上的教程,仍然是各种错误。

最终研究出来了搭建SpringBoot源码环境的正确姿势。

SpringBoot Github地址:https://github.com/spring-projects/spring-boot

0、环境准备

安装maven 3.5或者以上版本。

安装JDK 8或者以上。

1、fork到自己的库 

当然如果你觉得不需要,可以忽略。

fork到自己的github的好处是后面自己的修改可以提交上去,可以随意造作..

2、 clone下来 

clone下来后可以导入IDEA(也可以先不导入),导入步骤见最后。

3、设置Maven镜像

设置maven镜像如果不会可以自行百度。就是找到setting.xml然后再mirrors标签里粘贴如下内容。

代码语言:javascript
复制
        nexus-aliyun
        central
        Nexus aliyun
         [http://maven.aliyun.com/nexus/content/groups/public](http://maven.aliyun.com/nexus/content/groups/public) 


  
     ibiblio  
     central  
     ibiblio Mirror of  [http://repo1.maven.org/maven2/](http://repo1.maven.org/maven2/)   
      [http://mirrors.ibiblio.org/pub/mirrors/maven2/](http://mirrors.ibiblio.org/pub/mirrors/maven2/)   
  

  
     jboss-public-repository-group  
     central  
     JBoss Public Repository Group  
      [http://repository.jboss.org/nexus/content/groups/public](http://repository.jboss.org/nexus/content/groups/public)   



  repo2
  central
  Human Readable Name for this Mirror.
   [http://repo2.maven.org/maven2/](http://repo2.maven.org/maven2/) 




  ui
  central
  Human Readable Name for this Mirror.
  [http://uk.maven.org/maven2/](http://uk.maven.org/maven2/) 

4、修改最外层pom.xml文件

下加

代码语言:javascript
复制
true

  1. 安装并使用mvnwrapper编译项目

参见GitHub  maven-wrapper:  https://github.com/takari/maven-wrapper

进入到spring-boot检出的目录

执行: mvn -N io.takari:maven:wrapper

然后执行: ./mvnw clean install -DskipTests -Pfast

然后看到如下结果,表示构建成功。

然后选取项目里的一个单元测试运行一下,走起,发现运行成功了。

6 构造spring-boot-sample模块

导入项目后发现spring-boot-sample模块没有显示模块样式,没有显示正常的模块结构。

我们再回到最外层的pom.xml文件,发现模块这里专门有一句话“Samples are built via the invoker plugin” 可见 samples模块是通过invoker插件来构建的。

进入invoker模块。

编辑其中的pom.xml文件在

下加

代码语言:javascript
复制
true

我们打开IDEA右侧的maven面板,执行install。

也可以cd 到该子模块,然后执行mvn clean build

然后在最外层的pom.xml整添加模块:spring-boot-samples

然后发现sample模块显示正常

然后再sample模块里运行一个DEMO,发现运行正常,搞定...

可能遇到的情况

如果pom.xml文件的project标签上显示java.lang.OutOfMemoryError:GC overhead limit exceeded,可以参考

https://cloud.tencent.com/developer/article/1868939 来解决。

SpringBoot源码导入IDEA

IDEA菜单  File -->New --> Project From Existing Sources

然后选择Maven --> Next

后面就一步步导入就可以了。

写在最后

如果还有错误,请具体看错误提示,耐心排查。如果有其他需要注意的,请评论探讨。

我的settring.xml文件配置

代码语言:javascript
复制
        nexus-aliyun
        central
        Nexus aliyun
         http://maven.aliyun.com/nexus/content/groups/public)

 
  
     ibiblio  
     central  
     ibiblio Mirror of  [http://repo1.maven.org/maven2/](http://repo1.maven.org/maven2/)   
      http://mirrors.ibiblio.org/pub/mirrors/maven2/  
  
 
  
     jboss-public-repository-group  
     central  
     JBoss Public Repository Group  
     http://repository.jboss.org/nexus/content/groups/public   

 

  repo2
  central
  Human Readable Name for this Mirror.
   http://repo2.maven.org/maven2/

 
 

  ui
  central
  Human Readable Name for this Mirror.
  http://uk.maven.org/maven2/ 

    


	



 
      home-dev
      
    

          
            nexus-aliyun
            Nexus aliyun
            http://maven.aliyun.com/nexus/content/groups/public
        

     
            nexus-tmatesoft
            Nexus tmatesoftn
            https://maven.tmatesoft.com/content/groups/public/
        



     
            ibiblio
            Nexus ibiblio
            http://maven.ibiblio.org/maven2/
        


   
            nexus-repos1
            Central Repository1
            http://repo1.maven.org/maven2/
        

   
            uk-maven2
            Nexus uk maven2
            http://uk.maven.org/maven2/
        


      
    

  
  
    home-dev 

如果觉得本文对你有帮助,欢迎点赞,欢迎关注我,如果有补充欢迎评论交流,我将努力创作更多更好的文章。 另外欢迎加入我的知识星球,知识星球ID:15165241 一起交流学习。 https://t.zsxq.com/Z3bAiea  申请时标注来自CSDN。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018/12/19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 0、环境准备
  • 1、fork到自己的库 
  • 4、修改最外层pom.xml文件
  • 6 构造spring-boot-sample模块
  • 可能遇到的情况
  • SpringBoot源码导入IDEA
    • 写在最后
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档