Initializr

您可以使用 Spring CLI 作为 [role="bare"][role="bare"]https://github.com/spring-io/initializr 的客户端,并将其设为 [role="bare"][role="bare"]https://start.spring.io 的默认值。外壳样式的项目创建模拟了如何从 UI 创建项目。下图显示了它的一个示例:

You can use Spring CLI as a client for [role="bare"]https://github.com/spring-io/initializr and defaults to [role="bare"]https://start.spring.io. Shell style project creation mimics how a project is created from the UI. The following image shows an example of it: image::initializr-1.svg[]

New Command

要使用 new 命令,请在命令行上定义选项。然后,如果 Initializr 需要更多信息,它会进入交互模式来询问澄清问题。

To use the new command, define options on the command line. Then, if Initializr needs more information, it goes into its interactive mode to ask clarifying questions.

NAME
       initializr new - Create a new project from start.spring.io

SYNOPSIS
       initializr new --server-id String --path String --project String --language String --boot-version String
       --version String --group String --artifact String --name String --description String --package-name String
       --dependencies List --packaging String --java-version String

OPTIONS
       --server-id String
       Server to use
       [Optional]

       --path String
       Path to extract
       [Optional]

       --project String
       Project
       [Optional]

       --language String
       Language
       [Optional]

       --boot-version String
       Language
       [Optional]

       --version String
       Version
       [Optional]

       --group String
       Group
       [Optional]

       --artifact String
       Artifact
       [Optional]

       --name String
       Name
       [Optional]

       --description String
       Description
       [Optional]

       --package-name String
       Package Name
       [Optional]

       --dependencies List
       Dependencies
       [Optional]

       --packaging String
       Packaging
       [Optional]

       --java-version String
       Java
       [Optional]

以下示例显示了所有提供的选项,并且命令在没有任何询问的情况下直接通过。

The following example shows all the options being provided and the command just passing through without anything being asked.

$ spring initializr new \
    --path demo \
    --project gradle-project \
    --language java \
    --boot-version 2.7.0 \
    --version 0.0.1-SNAPSHOT \
    --group com.example \
    --artifact demo \
    --name demo \
    --description "Demo project" \
    --package-name com.example.demo \
    --dependencies web \
    --packaging jar \
    --java-version 17

List Command

你可以使用 list 命令查看已定义的自定义 initializr 服务器:

You can use the list command to see the custom initializr servers you have defined:

$ spring help initializr list
NAME
       initializr list - Show the Initializr server environments

SYNOPSIS
       initializr list

如果你已定义了一个自定义 Initializr,输出将类似于以下内容:

If you have defined one custom Initializr,the output resembles the following:

$ spring initializr list
┌────────┬─────────────────────┐
│ServerId│Url                  │
├────────┼─────────────────────┤
│local   │http://localhost:8080│
└────────┴─────────────────────┘

Set Command

你可以使用 set 命令定义一个新的服务器环境:

You can use the set command to define a new server environment:

NAME
       initializr set - Set the Initializr server environment

SYNOPSIS
       initializr set [--server-id String] [--url String]

OPTIONS
       --server-id String
       Server to use
       [Mandatory]

       --url String
       Server base url
       [Mandatory]

例如,你可以按如下方式定义你的本地 initializr 服务器:

You can, for example, define your local initializr server, as follows:

$ spring initializr set --server-id local --url http://localhost:8080

Remove Command

你可以使用 remove 命令删除服务器环境:

You can use the remove command to remove a server environment:

$ spring help initializr remove
NAME
       initializr remove - Remove the Initializr server environment

SYNOPSIS
       initializr remove [--server-id String]

OPTIONS
       --server-id String
       Server to use
       [Mandatory]

例如,你可以按如下方式删除你的本地 initializr 服务器:

You can, for example, remove your local initializr server, as follows:

$ spring initializr remove --server-id local

Dependencies Command

你可以使用 dependencies 命令列出和搜索 initializr 依赖项:

You can use the dependencies command to list and search initializr dependencies:

$ spring help initializr dependencies
NAME
       initializr dependencies - List supported dependencies

SYNOPSIS
       initializr dependencies --server-id String --search String --version String

OPTIONS
       --server-id String
       Server to use
       [Optional]

       --search String
       Search string to limit results
       [Optional]

       --version String
       Limit to compatibility version
       [Optional]

例如,你可以按如下方式搜索 initializr 服务器:

You can, for example, search initializr server, as follows:

$ spring initializr dependencies --search webflux
┌───────┬───────────────────┬──────────────────────────────────────────────────────────────┬────────────────┐
│Id     │Name               │Description                                                   │Required version│
├───────┼───────────────────┼──────────────────────────────────────────────────────────────┼────────────────┤
│webflux│Spring Reactive Web│Build reactive web applications with Spring WebFlux and Netty.│                │
└───────┴───────────────────┴──────────────────────────────────────────────────────────────┴────────────────┘