Spring Boot CLI命令行工具
Spring Boot CLI适应各命令行工具,你可以使用它快速创建spring项目,通常我们都是使用idea等工具来创建项目,用不到CLI,但这提供了一种在没有IDE的情况下快速创建启动spring应用的方法。
- 官方文档
https://docs.spring.io/spring-boot/installing.html#getting-started.installing.cli
- 使用SDKMAN!安装Spring Boot CLI并且可以管理多个版本
sdk install springboot 3.3.3
- 如果你为CLI开发了新特性并且想访问自己构建的版本,可以使用如下版本
$ sdk install springboot dev /path/to/spring-boot/spring-boot-cli/target/spring-boot-cli-3.3.3-bin/spring-3.3.3/
$ sdk default springboot dev
$ spring --version
Spring CLI v3.3.3
- 安装好springboot就可以使用spring命令行工具
xx:raccoon-docs xx$ spring
usage: spring [--help] [--version] <command> [<args>]Available commands are:init [options] [location]Initialize a new project using Spring Initializr (start.spring.io)encodepassword [options] <password to encode>Encode a password for use with Spring Securityshell Start a nested shellCommon options:--debug Verbose mode Print additional status information for the command you are runningSee 'spring help <command>' for more information on a specific command.
- 通过spring help init指令获取更详细的信息
xx:raccoon-docs xx$ spring help init
spring init - Initialize a new project using Spring Initializr (start.spring.io)usage: spring init [options] [location]Option Description
------ -----------
-a, --artifact-id <String> Project coordinates; infer archive name (for example 'test')
-b, --boot-version <String> Spring Boot version (for example '1.2.0.RELEASE')
--build <String> Build system to use (for example 'maven' or 'gradle') (default: gradle)
-d, --dependencies <String> Comma-separated list of dependency identifiers to include in the generated project
--description <String> Project description
-f, --force Force overwrite of existing files
--format <String> Format of the generated content (for example 'build' for a build file, 'project' for a project archive) (default: project)
-g, --group-id <String> Project coordinates (for example 'org.test')
-j, --java-version <String> Language level (for example '1.8')
-l, --language <String> Programming language (for example 'java')
--list List the capabilities of the service. Use it to discover the dependencies and the types that areavailable
-n, --name <String> Project name; infer application name
-p, --packaging <String> Project packaging (for example 'jar')
--package-name <String> Package name
-t, --type <String> Project type. Not normally needed if you use -- build and/or --format. Check the capabilities ofthe service (--list) for more details
--target <String> URL of the service to use (default: https://start.spring.io)
-v, --version <String> Project version (for example '0.0.1-SNAPSHOT')
-x, --extract Extract the project archive. Inferred if a location is specified without an extension examples:To list all the capabilities of the service:$ spring init --listTo creates a default project:$ spring initTo create a web my-app.zip:$ spring init -d=web my-app.zipTo create a web/data-jpa gradle project unpacked:$ spring init -d=web,jpa --build=gradle my-dir
- 查看spring boot CLI版本
spring version
- 查看支持的依赖项
xx:workplace-java xx$ spring init --list. ____ _ __ _ _/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/ ___)| |_)| | | | | || (_| | ) ) ) )' |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/
:: Service capabilities :: https://start.spring.ioSupported dependencies
+--------------------------------------+--------------------------------------------------------------+-----------------------+
| Id | Description | Required version |
+--------------------------------------+--------------------------------------------------------------+-----------------------+
| activemq | Spring JMS support with Apache ActiveMQ 'Classic'. | |
| | | |
| actuator | Supports built in (or custom) endpoints that let you monitor | |
| | and manage your application - such as application health, | |
| | metrics, sessions, etc. | |
| | | |
+--------------------------------------+--------------------------------------------------------------+-----------------------+Project types (* denotes the default)
+-----------------------+--------------------------------------------------------------+--------------------------------------------+
| Id | Description | Tags |
+-----------------------+--------------------------------------------------------------+--------------------------------------------+
| gradle-build | Generate a Gradle build file. | build:gradle,format:build |
| | | |
| gradle-project * | Generate a Gradle based project archive using the Groovy | build:gradle,dialect:groovy,format:project |
| | DSL. | |
| | | |
| gradle-project-kotlin | Generate a Gradle based project archive using the Kotlin | build:gradle,dialect:kotlin,format:project |
| | DSL. | |
| | | |
| maven-build | Generate a Maven pom.xml. | build:maven,format:build |
| | | |
| maven-project | Generate a Maven based project archive. | build:maven,format:project |
+-----------------------+--------------------------------------------------------------+--------------------------------------------+Parameters
+-------------+------------------------------------------+------------------------------+
| Id | Description | Default value |
+-------------+------------------------------------------+------------------------------+
| artifactId | project coordinates (infer archive name) | demo |
| bootVersion | spring boot version | 3.3.3 |
| description | project description | Demo project for Spring Boot |
| groupId | project coordinates | com.example |
| javaVersion | language level | 17 |
| language | programming language | java |
| name | project name (infer application name) | demo |
| packageName | root package | com.example.demo |
| packaging | project packaging | jar |
| type | project type | gradle-project |
| version | project version | 0.0.1-SNAPSHOT |
+-------------+------------------------------------------+------------------------------+
- 创建一个简单的项目
xx:workplace-java xx$ spring init --dependencies=web,data-jpa my-project
Using service at https://start.spring.io
Project extracted to '/Users/xx/Documents/IDE/workplace-java/my-project'
示例创建项目my-project,默认gradle依赖spring-boot-starter-web和spring-boot-starter-data-jpa
- spring shell命令
xx:raccoon-docs xx$ spring shell
Spring Boot (v3.3.3)
Hit TAB to complete. Type 'help' and hit RETURN for help, and 'exit' to quit.
$
clear encodepassword exit help init prompt version
$
开源SDK:https://github.com/mingyang66/spring-parent