Gradle 在 Spring 中的使用-ApiHug准备-工具篇-006

  🤗 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. 工欲善其事,必先利其器

参考: 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

#init


gradle init

org.springframework.bootopen in new window 主要是各种Job gradle tasks 里面 boot 开头的job 都是:

  1. 打包成可执行jar、war
  2. 引入以来管理 spring-boot-dependencies 也就是: BOM_COORDINATES

public static final String BOM_COORDINATES = "org.springframework.boot:spring-boot-dependencies:"+ SPRING_BOOT_VERSION;

gradle tasksApplication tasks
-----------------
bootRun - Runs this project as a Spring Boot application.Build tasks
-----------
bootBuildImage - Builds an OCI image of the application using the output of the bootJar task
bootJar - Assembles an executable jar archive containing the main classes and their dependencies.
bootJarMainClassName - Resolves the name of the application's main class for the bootJar task.
bootRunMainClassName - Resolves the name of the application's main class for the bootRun task.

io.spring.dependency-managementopen in new window, 主要是依赖控制: A Gradle plugin that provides Maven-like dependency management and exclusions, 提供和maven 里面 pom 类似操作。

这两个插件一般是组合使用, dependency-management 依赖 boot 的 pom 版本。


plugins {id 'org.springframework.boot' version '2.7.0'id 'io.spring.dependency-management' version '1.0.11.RELEASE'id 'java'
}

BOM 版本open in new window + 版本字段open in new window 。 两个plugin 有什么关系?

当 io.spring.dependency-management 插件被加入的时候, Spring Boot 插件将自动导入 spring-boot-dependencies bom,也就是避免导入starter 时候设置版本号(pom 的本质和好处)。

相当于自动导入了:

dependencyManagement {imports {mavenBom "org.springframework.boot:spring-boot-dependencies:${SPRING_BOOT_VERSION}"}
}

spring.boot 插件是避免带入版本号, 如果你只想使用 spring.boot 的版本依赖, 但是不想引用 spring.boot 的定制的一些task 比如 boot jar(比如定制spring starter); 有两种方式。

#第0种

plugins {id 'org.springframework.boot' version '2.7.0'id 'io.spring.dependency-management' version '1.0.11.RELEASE'id 'java'
}ext {set('springCloudVersion', "2021.0.3")set('testcontainersVersion', "1.17.2")
}dependencies {implementation 'org.springframework.boot:spring-boot-starter-web'implementation 'org.springframework.cloud:spring-cloud-starter-config'testImplementation 'org.springframework.boot:spring-boot-starter-test'testImplementation 'org.testcontainers:junit-jupiter'
}dependencyManagement {imports {//不需要显式的导入 boot-dependencies mavenBom "org.testcontainers:testcontainers-bom:${testcontainersVersion}"mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"}
}

#第一种

plugins {id 'java'id("org.springframework.boot") version "2.7.0" apply falseid("io.spring.dependency-management") version "1.0.11.RELEASE"
}dependencyManagement {imports {mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)}
}

apply false 表示不带task过来, 那么下面 SpringBootPlugin.BOM_COORDINATES 同样带来 导入 boot bom 效果:


public static final String BOM_COORDINATES = "org.springframework.boot:spring-boot-dependencies:"+ SPRING_BOOT_VERSION;

默认引入了tasks:

gradle tasksApplication tasks
-----------------
bootRun - Runs this project as a Spring Boot application.Build tasks
-----------
bootBuildImage - Builds an OCI image of the application using the output of the bootJar task
bootJar - Assembles an executable jar archive containing the main classes and their dependencies.
bootJarMainClassName - Resolves the name of the application's main class for the bootJar task.
bootRunMainClassName - Resolves the name of the application's main class for the bootRun task.

一旦 apply false, bootRun 开头的所有任务就没有了!

#第二种

用 gradle 原生的 platform 功能

plugins {id 'java'id("org.springframework.boot") version "2.7.0" apply false
}dependencies {implementation platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}

#两种方式差别

用 spring 的 dependency 或者 gradle platform 有什么差别?

#Spring Depedencies Management Plugin

Spring depedency management 提供了编辑通道:


ext['slf4j.version'] = '1.7.20'
#Gradle Platform

纯 gradle 方式:


configurations.all {resolutionStrategy.eachDependency { DependencyResolveDetails details ->if (details.requested.group == 'org.slf4j') {details.useVersion '1.7.20'}}
}

org.springframework.boot 和 boot 一致, io.spring.dependency-management 一般配合使用, dependency-management 会使用 boot 的版本。

#参考项目

  1. 统一版本管理 Sharing dependency versions between projectsopen in new window
  2. The Java Platform Pluginopen in new window
  3. spring boot pluginopen in new window
  4. spring depedency managementopen in new window
  5. spring framework testopen in new window
  6. java gradle template

api-hug-contact

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

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

相关文章

【arduino】控制N位数码管

以下以四位共阳极数码管为例; 本文所有说明均以注释的方式进行。 使用方法: #include "DigitalTube.h" //每位共阳极对应的引脚int digital[4] {8, 11, 12, 7};//参数分别为a f b g e c d dp digital(共阳极引脚数组) length(digital长度)D…

LRUCache原理及源码实现

目录 LRUCache简介: LRUCache的实现: LinkedHashMap方法实现: 自己实现链表: 前言: 有需要本文章源码的友友请前往:LRUCache源码 LRUCache简介: LRU是Least Recently Used的缩写&#xf…

ChatGPT-4 Turbo 今天开放啦!附如何查询GPT-4 是否为 Turbo

2024年4月12日,OpenAI在X上宣布GPT-4 Turbo开放了!提高了写作、数学、逻辑推理和编码方面的能力。另外最重要的是,响应速度更快了!! ChatGPT4 Turbo 如何升级?解决国内无法升级GPT4 Turbo的问题&#xff0…

设计模式-代理模式(Proxy)

1. 概念 代理模式(Proxy Pattern)是程序设计中的一种结构型设计模式。它为一个对象提供一个代理对象,并由代理对象控制对该对象的访问。 2. 原理结构图 抽象角色(Subject):这是一个接口或抽象类&#xff0…

ros2 launch gazebo_ros gazebo.launch.py无法启动

我的系统是ubuntu20.04,ros2的版本是humble,当运行gazebo仿真时,运行 ros2 launch gazebo_ros gazebo.launch.py命令,会出现以下问题: 此时,这个页面会卡死在第六行,gazebo也不会打开 但最后单…

哈希函数算法

概述 为了实现哈希集合这一数据结构,有以下几个关键问题需要解决: 哈希函数:能够将集合中任意可能的元素映射到一个固定范围的整数值,并将该元素存储到整数值对应的地址上。冲突处理:由于不同元素可能映射到相同的整…

C语言中局部变量和全局变量是否可以重名?为什么?

可以重名 在C语言中, 局部变量指的是定义在函数内的变量, 全局变量指的是定义在函数外的变量 他们在程序中的使用方法是不同的, 当重名时, 局部变量在其所在的作用域内具有更高的优先级, 会覆盖或者说隐藏同名的全局变量 具体来说: 局部变量的生命周期只在函数内部,如果出了…

【C++类和对象】构造函数与析构函数

💞💞 前言 hello hello~ ,这里是大耳朵土土垚~💖💖 ,欢迎大家点赞🥳🥳关注💥💥收藏🌹🌹🌹 💥个人主页&#x…

Stacked Hourglass Networks for Human Pose Estimation 用于人体姿态估计的堆叠沙漏网络

Stacked Hourglass Networks for Human Pose Estimation 用于人体姿态估计的堆叠沙漏网络 这是一篇关于人体姿态估计的研究论文,标题为“Stacked Hourglass Networks for Human Pose Estimation”,作者是 Alejandro Newell, Kaiyu Yang, 和 Jia Deng&a…

多模态 ——LLaVA 集成先进图像理解与自然语言交互GPT-4的大模型

概述 提出了一种大型模型 LLaVA,它使用 GPT-4 生成多模态语言图像指令跟随数据,并利用该数据将视觉和语言理解融为一体。初步实验表明,LLaVA 展示了出色的多模态聊天能力,在合成多模态指令上的表现优于 GPT-4。 在科学质量保证中…

第1章、react基础知识;

一、react学习前期准备; 1、基本概念; 前期的知识准备: 1.javascript、html、css; 2.构建工具:Webpack:https://yunp.top/init/p/v/1 3.安装node:npm:https://yunp.top/init/p/v/1 …

Python 基于 OpenCV 视觉图像处理实战 之 OpenCV 简单视频处理实战案例 之三 简单动态聚光灯效果

Python 基于 OpenCV 视觉图像处理实战 之 OpenCV 简单视频处理实战案例 之三 简单动态聚光灯效果 目录 Python 基于 OpenCV 视觉图像处理实战 之 OpenCV 简单视频处理实战案例 之三 简单动态聚光灯效果 一、简单介绍 二、简单动态聚光灯效果实现原理 三、简单动态聚光灯效果…

Mysql视图与事物与字符集实验

一 视图 1.视图的定义 视图是一个虚拟表,其内容由查询定义。 2.视图的优点 1)视点集中 2)简化操作 3)定制数据 4)分隔合并数据 5)安全性好 3.语法格式及限定条件 1)语法格式&#xff1…

轻量化模块整理,即插即用

轻量化模块整理,即插即用(持续更新) 整理一些轻量化的结构,作为知识储备,可以用到后续的项目和研究中 Mobilenetv3 深度可分离卷积 MobileNetV3 是一个轻量级的深度学习模型,专为移动和边缘设备上的高效…

力扣HOT100 - 56. 合并区间

解题思路: class Solution {public int[][] merge(int[][] intervals) {// 先按照区间起始位置排序Arrays.sort(intervals, (v1, v2) -> v1[0] - v2[0]);int[][] res new int[intervals.length][2];int idx -1;for (int[] interval : intervals) {//直接加入的…

CSS基础之伪类选择器(如果想知道CSS的伪类选择器知识点,那么只看这一篇就足够了!)

前言:学习CSS就必须要学习选择器,在之前我们已经学习了基本选择器和复合选择器,但是还有几个选择器没有学习,这篇文章主要讲解伪类选择器。 ✨✨✨这里是秋刀鱼不做梦的BLOG ✨✨✨想要了解更多内容可以访问我的主页秋刀鱼不做梦-…

基于springboot实现视频网站管理系统【项目源码+论文说明】计算机毕业设计

基于springboot实现视频网站管理系统演示 摘要 使用旧方法对视频信息进行系统化管理已经不再让人们信赖了,把现在的网络信息技术运用在视频信息的管理上面可以解决许多信息管理上面的难题,比如处理数据时间很长,数据存在错误不能及时纠正等问…

顶顶通呼叫中心中间件(mod_cti基于FreeSWITCH)-回铃音补偿

文章目录 前言联系我们解决问题操作步骤 前言 回铃音: 当别人打电话给你时,你的电话响铃了,而他听到的声音叫做回铃音。回铃音是被叫方向主叫方传送,也是彩铃功能的基础。我们平时打电话听到的“嘟 嘟 嘟 嘟”的声音,就…

asp.net core 网页接入微信扫码登录

创建微信开放平台账号&#xff0c;然后创建网页应用 获取appid和appsecret 前端使用的vue&#xff0c;安装插件vue-wxlogin 调用代码 <wxlogin :appid"appId" :scope"scope" :redirect_uri"redirect_uri"></wxlogin> <scri…

机器学习和深度学习 --李宏毅(笔记与个人理解)Day 18

Day 18 Spatial Transformer Layer 因为单纯的cNN无法做到scaling&#xff08;放大&#xff09;and rotation&#xff08;转&#xff09;&#xff0c;所以我们引入&#xff1b; 实战中也许我们可以做到 是因为 我们的training data 中包含了对data 的augmentation&#xff1b; …