zoukankan      html  css  js  c++  java
  • 【SpringBoot】SpringBoot源码编译

      SpringBoot官网:https://github.com/spring-projects/spring-boot

      SpringBoot项目在2.3.0之前是使用Maven构建项目的,在2.3.0之后是使用Gradle构建项目了

      本章将介绍2种方式的源码编译构建

    SpringBoot-2.2.5源码编译  

      SpringBoot-2.2.5 是 Maven构建项目    

    环境准备

    • Maven:3.6.3
    • Jdk:1.8.0_181
    • idea:2021.1.1 Community Edition(社区版)

    1、下载Spring源码

      SpringBoot官网:https://github.com/spring-projects/spring-boot

      下载版本 :2.2.5

      

      源码中有文件 README.adoc ,可以进行参考如何编译

    2、使用Maven编译SpringBoot源码

      1、解压SpringBoot源码项目

      2、进入SpringBoot源码目录,打开pom文件,可以修改版本号,避免与官网的版本冲突

    <properties>
        <revision>2.2.5.RELEASE-MY</revision>
        <main.basedir>${basedir}</main.basedir>
    </properties>

      3、使用maven命令进行编译

      命令:mvn clean install -DskipTests

      

      

      编译成功

    可能出现的问题

       1、问题:Could not find artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.5.RELEASE in nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public/)

      意思是无法在阿里云的镜像仓库中找到资源

      解决:将配置的镜像删除即可,让它从Maven中央仓库中获取资源

      

      2、问题:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0:check (nohttp-checkstyle-validation) on project spring-boot-build: You have 1 Checkstyle violation. -> [Help 1]

      代码检测插件问题,

      解决:在根目录下的pom文件中,缺少一个属性,添加一个disable.checks属性,如下:

    <properties>
        <revision>2.2.5.RELEASE-MY</revision>
        <main.basedir>${basedir}</main.basedir>
        <!-- 添加属性 -->
        <disable.checks>true</disable.checks>
    </properties>    

    3、将SpringBoot项目导入Idea中,验证

      运行测试文件 org.springframework.boot.BannerTests#testDefaultBanner()

      

      运行成功,编译完成

    可能出现的问题

      1、问题:java: 服务配置文件不正确, 或构造处理程序对象javax.annotation.processing.Processor: Provider org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor not found时抛出异常错误

        解决:错误原因无法找到ConfigurationMetadataAnnotationProcessor类,查看ConfigurationMetadataAnnotationProcessor类是spring-boot-configuration-processor项目中的类,但是项目中的target目录确实没有,当读对spring-boot-configuration-processor项目进行编译,在target目录中生存ConfigurationMetadataAnnotationProcessor类的class文件,即可解决

      

    SpringBoot-2.3.0源码编译  

      SpringBoot-2.2.5 是 Gradle构建项目

    环境准备

    • Gradle:6.4(类似Maven构建工具)
    • Jdk:1.8.0_181
    • idea:2021.1.1 Community Edition(社区版)

    1、下载Spring源码

      SpringBoot官网:https://github.com/spring-projects/spring-boot

      下载版本 :2.3.0

      源码中有文件 README.adoc ,可以进行参考如何编译

      同上

    2、使用Gradle编译SpringBoot源码

      1、解压SpringBoot源码项目

      2、进入SpringBoot源码目录,打开 gradle.properties 文件,可以修改版本号,避免与官网的版本冲突

    version=2.3.0.RELEASE-MY

      3、配置项目依赖仓库 与 插件仓库

      依赖仓库添加本地maven仓库 与 阿里镜像仓库,文件 build.gradle

    allprojects {
        ......
    
        repositories {
            // 本地仓库位于USER_HOME/.m2/repository
            mavenLocal()
            // aliyun镜像
            maven { url 'https://maven.aliyun.com/nexus/content/groups/public/'}
            
            mavenCentral()
            if (!version.endsWith('RELEASE')) {
                maven { url "https://repo.spring.io/milestone" }
            }
            if (version.endsWith('BUILD-SNAPSHOT')) {
                maven { url "https://repo.spring.io/snapshot" }
            }
        }
    
        ......
    }

      插件仓库 添加本地maven仓库 与 阿里镜像仓库,文件 settings.gradle

      且将插件 io.spring.gradle-enterprise-conventions 注释

    pluginManagement {
        repositories {
            // 本地仓库位于USER_HOME/.m2/repository
            mavenLocal()
            // aliyun镜像
            maven { url 'https://maven.aliyun.com/nexus/content/groups/public/'}
    
            mavenCentral()
            
            gradlePluginPortal()
            maven {
                url 'https://repo.spring.io/plugins-release'
            }
            if (version.endsWith('BUILD-SNAPSHOT')) {
                maven { url "https://repo.spring.io/snapshot" }
            }
        }
        ......
    }
    
    plugins {
        id "com.gradle.enterprise" version "3.2"
    //     id "io.spring.gradle-enterprise-conventions" version "0.0.2"
    }

      3、使用gradle命令进行编译构建,-x test 是跳过测试

      命令:gradle build -x test

       

    可能出现的问题

      1、问题:构建时需要用到一些jar或者插件,用于网络原因无法下载

        解决:建议使用代理,进行下载

      2、问题:构建时需要用到一些jar或者插件,如:jar无法找到资源。

        解决:手动去网上下载资源,然后通过maven命令安装到maven仓库

        命令:mvn install:install-file -DgroupId=org.gradle -DartifactId=test-retry-gradle-plugin -Dversion=1.1.3 -Dpackaging=jar -Dfile=test-retry-gradle-plugin-1.1.3.jar

    3、将SpringBoot项目导入Idea中,验证

      1、导入idea中,配置gradle,使用gradle-6.4版本的

      

      2、运行测试文件 org.springframework.boot.BannerTests#testDefaultBanner()

       同上

      3、发布到Maven仓库

      命令:gradle publishToMavenLocal

        

  • 相关阅读:
    moviepy音视频剪辑:视频基类VideoClip子类VideoFileClip、CompositeVideoClip、ImageSequenceClip介绍及使用案例
    moviepy执行TextClip.search方法时报错TypeError: a bytes-like object is required, not str
    python学习接口测试(二)
    python 接口测试(一)
    接口测试学习
    python 将表格多个列数据放到同一个单元格中
    python对表格的使用
    python 下实现window 截图
    python selenium 下拉框
    selenium+chrome下载文件,格式怎么选择???
  • 原文地址:https://www.cnblogs.com/h--d/p/14775266.html
Copyright © 2011-2022 走看看