Spring 如何组织项目-ApiHug准备-工具篇-007

news2025/2/27 20:59:48

  🤗 ApiHug × {Postman|Swagger|Api...} = 快↑ 准√ 省↓

  1. GitHub - apihug/apihug.com: All abou the Apihug   
  2. apihug.com: 有爱,有温度,有质量,有信任
  3. ApiHug - API design Copilot - IntelliJ IDEs Plugin | Marketplace

ApiHug 整个工具链基于 Gradle, 使用 ApiHug 准备工作最先需要学习的就是 gradle. 工欲善其事,必先利其器

Spring 早在2020 将整个框架编译平台从maven 迁移到gradle: Migrating Spring Boot's Build to Gradleopen in new window; 来看一看spring 两个关键的项目,是如何组织自己的项目的:

  1. spring frameworkopen in new window spring framework 源码
  2. spring bootopen in new window spring boot 源码
  3. spring scanopen in new window 包含所有spring 编译的scan

#Spring Framework

spring scanopen in new window 找一个编译成功的项目开始分析。

项目结构:

buildSrc
framework-bom
integration-tests
spring-aop
spring-aspects
spring-beans
spring-context
spring-context-indexer
spring-context-support
spring-core
spring-core-test
spring-expression
spring-instrument
spring-jcl
spring-jdbc
spring-jms
spring-messaging
spring-orm
spring-oxm
spring-r2dbc
spring-test
spring-tx
spring-web
spring-webflux
spring-webmvc
spring-websocket

#gradle.properties 配置

org.gradle.jvmargs=-Xmx2048m
org.gradle.caching=true
org.gradle.parallel=true

#settings.gradle 配置

异构了 build.gradle 到每个项目名字 gradle 比如 spring-websocket.gradle

rootProject.name = "spring"
rootProject.children.each {project ->
	project.buildFileName = "${project.name}.gradle"
}

#build.gradle 主入口

里面内容比价多, 异议分解下

  1. 预定义很多的 plugin,大部分 apply false, 表示根项目暂时不apply这些插件, 子项目可以引入,可以从根项目控制版本-Applying external plugins with same version to subprojectsopen in new window。
  2. ext 项目基本的归类, framework-bom 比较特别, 看名字就知道她是哥bom 类库管理项目。
    1. moduleProjects 模块项目: 所有的 spring- 开头项目
    2. javaProjects java项目:剔除 framework-bom 的项目
  3. 各个项目的配置
    1. 所有依赖 io.spring.dependency-management 来管理依赖
    2. 根项目 + java 项目的插件配置,主要是测试依赖部分配置
    3. java
    4. check style
    5. tool chain
    6. text fixture
  4. 模块项目, 单独引入 spring-module.gradle 配置
  5. jar 配置
  6. doc 配置
  7. jmh 配置
  8. repository 推送配置
  9. framework-bom
  10. java-platform 插件, 不需要java 插件,否则出错
  11. publications.gradle, 引入里面的任务
  12. 将所有的 moduleProjects 项目加入到 BOM 中

#Spring Boot

spring scanopen in new window 找一个编译成功的项目开始分析。

spring boot 结构相对复杂, 有193 个项目(主要在smoke test),但是一级项目没有那么多:


spring-boot-build +4
spring-boot-project +14
spring-boot
spring-boot-actuator
spring-boot-actuator-autoconfigure
spring-boot-autoconfigure
spring-boot-cli
spring-boot-dependencies
spring-boot-devtools
spring-boot-docs
spring-boot-parent
spring-boot-properties-migrator
spring-boot-starters +54
spring-boot-test
spring-boot-test-autoconfigure
spring-boot-tools +12
spring-boot-system-tests
spring-boot-deployment-tests
spring-boot-image-tests
spring-boot-tests

由于 spring boot 嵌套的项目比较深, settings.gradle 有些技巧:


file("${rootDir}/spring-boot-project/spring-boot-starters").eachDirMatch(~/spring-boot-starter.*/) {
	include "spring-boot-project:spring-boot-starters:${it.name}"
}

file("${rootDir}/spring-boot-tests/spring-boot-smoke-tests").eachDirMatch(~/spring-boot-smoke-test.*/) {
	include "spring-boot-tests:spring-boot-smoke-tests:${it.name}"
}

gradle.properties 配置


org.gradle.caching=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8

build.gradle 配置简单, 仅仅给每个项目:

  1. base plugin

allprojects {
	group "org.springframework.boot"
}

#spring-boot-dependencies

两个非常重要的插件open in new window & 参考: BOM 版本open in new window + 版本字段open in new window 。

pugin文档源码备注
org.springframework.boot2.7.0DOCopen in new window源码open in new window
io.spring.dependency-management1.0.11.REALEASEDOCopen in new window源码open in new window

spring-boot-parent 又是一个 bom 项目:


bom{
    ....
}

dependencies {
	api(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
}

各个starter 其实是 spring-framework api bom 依赖, 比如 spring-boot-starter-data-jdbc:

plugins {
	id "org.springframework.boot.starter"
}

description = "Starter for using Spring Data JDBC"

dependencies {
	api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jdbc"))
	api("org.springframework.data:spring-data-jdbc")
}

根目录的 spring-boot-starter:


plugins {
	id "org.springframework.boot.starter"
}

description = "Core starter, including auto-configuration support, logging and YAML"

dependencies {
	api(project(":spring-boot-project:spring-boot"))
	api(project(":spring-boot-project:spring-boot-autoconfigure"))
	api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-logging"))
	api("jakarta.annotation:jakarta.annotation-api")
	api("org.springframework:spring-core")
	api("org.yaml:snakeyaml")
}

api-hug-contact

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1585199.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

贪心算法|452.用最少数量的箭引爆气球

力扣题目链接 class Solution { private:static bool cmp(const vector<int>& a, const vector<int>& b) {return a[0] < b[0];} public:int findMinArrowShots(vector<vector<int>>& points) {if (points.size() 0) return 0;sort(p…

【JavaEE】_Spring MVC项目获取Session

目录 1. 使用servlet原生方法获取Session 1.1 错误获取方法 1.2 正确获取方法 2. 使用Spring注解获取Session 3. 使用Spring内置对象获取Session 1. 使用servlet原生方法获取Session .java文件内容如下&#xff1a; setSession方法用于设置Session对象的内容&#xff1b;…

文件输入/输出流(I/O)

文章目录 前言一、文件输入\输出流是什么&#xff1f;二、使用方法 1.FileInputStream与FileOutputStream类2.FileReader与FileWriter类总结 前言 对于文章I/O(输入/输出流的概述)&#xff0c;有了下文。这篇文章将具体详细展述如何向磁盘文件中输入数据&#xff0c;或者读取磁…

面试八股——数据库——事务

概述 事务的特性&#xff08;ACID&#xff09; 原子性&#xff1a;事务是不可分割的操作单元&#xff0c;要么全部成功&#xff0c;要么全部失败。 一致性&#xff1a;事务结束时&#xff0c;所有数据都必须保证一致状态。 隔离性&#xff1a;事务在独立环境运行&#xff0c;…

Burp Suite Professional 2024.3.1 for Windows x64 - 领先的 Web 渗透测试软件

Burp Suite Professional 2024.3.1 for Windows x64 - 领先的 Web 渗透测试软件 世界排名第一的 Web 渗透测试工具包 请访问原文链接&#xff1a;Burp Suite Professional 2024.3.1 for Windows x64 - 领先的 Web 渗透测试软件&#xff0c;查看最新版。原创作品&#xff0c;转…

OpenGL Assimp 加载3D模型介绍

OpenGL Assimp 加载3D模型介绍 Assimp对应模型结构体解说 所有的模型、场景数据都包含在scene对象中&#xff0c;如所有的材质和Mesh。同样&#xff0c;场景的根节点引用也包含在这个scene对象中 场景的Root node&#xff08;根节点&#xff09;可能也会包含很多子节点和一个…

微服务面试题一

1.SOA、分布式、微服务之间有什么关系和区别&#xff1f; 分布式架构是指将单体架构中的各个部分拆分&#xff0c;然后部署不同的机器或进程中去&#xff0c;SOA和微服务基 本上都是分布式架构的SOA是⼀种⾯向服务的架构&#xff0c;系统的所有服务都注册在总线上&#xff0c;…

“植物大战僵尸:机器学习引领游戏AI新革命“

上期回顾&#xff1a; 今天给大家推荐一个Gtihub开源项目&#xff1a;PythonPlantsVsZombies&#xff0c;翻译成中就是植物大战僵尸。 《植物大战僵尸》是一款极富策略性的小游戏。可怕的僵尸即将入侵&#xff0c;每种僵尸都有不同的特点&#xff0c;例如铁桶僵尸拥有极强的抗…

开源推荐榜【Casbin.NET 一个为.NET(C#)项目设计的高效且强大的访问控制库】

Casbin 是一个强大高效的开源访问控制库&#xff0c;支持各种 访问控制模型 , 如 ACL, RBAC, ABAC 等。 我们希望可以让指定的主体 subject&#xff0c;可以访问指定的资源 object&#xff0c;访问可以是读和写。这就是 Casbin 使用最广泛的方式。也称为 { subject, object, ac…

【MATLAB源码-第20期】基于matlab的短波通信多径信道仿真,多径数目为3,用QPSK来测试误码率效果输出误码率对比图。

1、算法描述 短波通信是一种使用短波频段的无线电通信技术&#xff0c;它具有以下特点&#xff1a; 1. 频段范围&#xff1a;短波通信通常使用3MHz到30MHz之间的频段。这个频段之所以称为“短波”&#xff0c;是因为它的波长相对较短&#xff0c;适合进行长距离通信。 2. 长距…

大语言模型的指令调优:综述

&#x1f349; CSDN 叶庭云&#xff1a;https://yetingyun.blog.csdn.net/ 论文标题&#xff1a;Instruction Tuning for Large Language Models: A Survey 论文地址&#xff1a;https://arxiv.org/abs/2308.10792 指令调优是提升大语言模型&#xff08;LLMs&#xff09;性能…

前端招聘:几招识别注水简历,不懂技术也能挤出水分。

现在的前端开发市场鱼目混珠&#xff0c;尤其是某些培训机构经常鼓动学院美&#xff08;造&#xff09;化&#xff08; 假&#xff09;简历&#xff0c;搞得很多前端招聘经验缺乏&#xff0c;又急需用人单位公司损失不小&#xff0c;满以为找到合适的人员了&#xff0c;其实是频…

倍思和南卡开放式耳机哪个好?深度测评剖析实力王!

​开放式耳机凭借其新颖的佩戴设计和优秀的音质体验&#xff0c;正逐渐赢得越来越多消费者的喜爱。在众多品牌中&#xff0c;南卡、倍思等业界巨头推出的开放式耳机尤为引人注目。这些耳机是否真的名副其实&#xff1f;它们又有哪些特色和优缺点&#xff1f;为了解答这些问题&a…

Canal扩展篇

1.Canal介绍 Canal官网&#xff1a;https://github.com/alibaba/canal Canal 主要用途是基于 MySQL 数据库增量日志解析&#xff0c;提供增量数据订阅和消费&#xff0c;工作原理如下&#xff1a; Canal 模拟 MySQL slave 的交互协议&#xff0c;伪装自己为 MySQL slave &…

FPGA - 以太网UDP通信(一)

一&#xff0c;简述以太网 以太网简介 ​以太网是一种计算机局域网技术。IEEE组织的IEEE 802.3标准制定了以太网的技术标准&#xff0c;它规定了包括物理层的连线、电子信号和介质访问层协议的内容。 ​ 以太网类型介绍 以太网是现实世界中最普遍的一种计算机网络。以太网有…

流程图高亮跟踪 可自定义渲染图片

【流程跟踪】获取流程定义图 获取代码如下&#xff1a; ProcessDefinition processDefinition repositoryService.createProcessDefinitionQuery().processDefinitionKey("leave").singleResult();String diagramResourceName processDefinition.getDiagramResour…

恒流电源驱动惠斯通电桥输出电压计算

笔记 并联分流/串联分压贯穿始终 先通过式子计算每条路流经的电流大小 &#xff08;1-(支路电阻)/(所有电阻) &#xff09;* 电流源I 每条之路电流大小知道了。就可以知道每条路中间点输出 支路电流*电阻。 输出即&#xff1a;中间点输出电位差。同理可以通过阻值变化推…

力扣HOT100 - 240. 搜索二维矩阵 II

解题思路&#xff1a; 从左下角开始&#xff0c;根据条件删除行和列。 class Solution {public boolean searchMatrix(int[][] matrix, int target) {int row matrix.length - 1;int col matrix[0].length - 1;int l 0;while (row > 0 && l < col) {if (targ…

深入理解java虚拟机-类的生命周期-初始化阶段

针对P2的字节码解释&#xff1a; 操作数栈里面放1&#xff0c;然后对Demo1.value的static变量进行赋值操作&#xff0c;从栈里面拿1赋值给Demo1.value的static变量 P3的情况由于源码是把 public static int value 1; static {value 2; }颠倒为&#xff1a; static {value …

2024电力、电网与智能应用技术国际学术会议(ICPGIAT2024)

2024电力、电网与智能应用技术国际学术会议(ICPGIAT2024) 会议简介 2024年国际电力、电网和智能应用技术大会&#xff08;ICPGIAT 2024&#xff09;将在中国杭州举行&#xff0c;就“电力系统”、“智能控制”和“智能应用技术”等研究主题进行讨论和交流。会议围绕智能系统…