🤗 ApiHug × {Postman|Swagger|Api...} = 快↑ 准√ 省↓
- GitHub - apihug/apihug.com: All abou the Apihug
- apihug.com: 有爱,有温度,有质量,有信任
- ApiHug - API design Copilot - IntelliJ IDEs Plugin | Marketplace
ApiHug 整个工具链基于 Gradle, 使用 ApiHug 准备工作最先需要学习的就是 gradle. 工欲善其事,必先利其器
参考: BOM 版本open in new window + 版本字段open in new window 。
pugin | 文档 | 源码 | 备注 |
---|---|---|---|
org.springframework.boot | 2.7.0 | DOCopen in new window | 源码open in new window |
io.spring.dependency-management | 1.0.11.REALEASE | DOCopen in new window | 源码open in new window |
#init
gradle init
org.springframework.bootopen in new window 主要是各种Job gradle tasks
里面 boot 开头的job 都是:
- 打包成可执行jar、war
- 引入以来管理 spring-boot-dependencies 也就是:
BOM_COORDINATES
public static final String BOM_COORDINATES = "org.springframework.boot:spring-boot-dependencies:"
+ SPRING_BOOT_VERSION;
gradle tasks
Application 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 false
id("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 tasks
Application 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 的版本。
#参考项目
- 统一版本管理 Sharing dependency versions between projectsopen in new window
- The Java Platform Pluginopen in new window
- spring boot pluginopen in new window
- spring depedency managementopen in new window
- spring framework testopen in new window
- java gradle template