Criar aplicações Quarkus com a interface de linha de comandos (CLI) do Quarkus
previewThe quarkus command lets you create projects, manage extensions and
do essential build and dev commands using the underlying project build tool.
|
Essa tecnologia é considerada preview. In preview, backward compatibility and presence in the ecosystem is not guaranteed. Specific improvements might require changing configuration or APIs, and plans to become stable are under way. Feedback is welcome on our mailing list or as issues in our GitHub issue tracker. Para obter uma lista completa de possíveis status, consulte nosso FAQ. |
Instalação do CLI
O Quarkus CLI está disponível em vários gestores de pacotes orientados para o desenvolvedor, tais como:
Se você já utiliza (ou pretende utilizar) uma destas ferramentas, esta é a forma mais simples de instalar o Quarkus CLI e de o manter atualizado.
Além desses gestores de pacotes, o Quarkus CLI também pode ser instalado via JBang. Escolha a alternativa que for mais prática para você:
-
JBang - para Linux, macOS e Windows
-
SDKMAN! - para Linux e macOS
-
Homebrew - para Linux e macOS
-
Chocolatey - para Windows
-
Scoop - para Windows
Usando o CLI
Use --help para exibir informações de ajuda com todos os comandos disponíveis:
quarkus --help
Usage: quarkus [-ehv] [--verbose] [-D=<String=String>]... [COMMAND]
Options:
-D=<String=String> Java properties
-e, --errors Display error messages.
-h, --help Show this help message and exit.
-v, --version Print version information and exit.
--verbose Verbose mode.
Commands:
create Create a new project.
app Create a Quarkus application project.
cli Create a Quarkus command-line project.
extension Create a Quarkus extension project
build Build the current project.
dev Run the current project in dev (live coding) mode.
extension, ext Configure extensions of an existing project.
list, ls List platforms and extensions.
categories, cat List extension categories.
add Add extension(s) to this project.
remove, rm Remove extension(s) from this project.
registry Configure Quarkus registry client
list List enabled Quarkus registries
add Add a Quarkus extension registry
remove Remove a Quarkus extension registry
version Display version information.
image Perform a container image operation.
build Build a container image.
docker Build a container image using Docker.
buildpack Build a container image using Buildpack.
jib Build a container image using Jib.
openshift Build a container image using Openshift.
push Push a container image.
completion bash/zsh completion: source <(quarkus completion)
|
While this document is a useful reference, the client help is the definitive source. Se você não visualizar o resultado esperado, use |
Criando um novo projeto
To create a new project we use the create command
(the app subcommand is implied when not specified):
quarkus create
-----------
applying codestarts...
📚 java
🔨 maven
📦 quarkus
📝 config-properties
🔧 dockerfiles
🔧 maven-wrapper
🚀 resteasy-codestart
-----------
[SUCCESS] ✅ quarkus project has been successfully generated in:
--> /<output-dir>/code-with-quarkus
This will create a folder called 'code-with-quarkus' in your current working directory using default groupId, artifactId and version values (groupId='org.acme', artifactId='code-with-quarkus' and version='1.0.0-SNAPSHOT').
Note: the emoji shown above may not match precisely. The appearance of emoji can vary by font, and terminal/environment. IntelliJ IDEA, for example, has several long-running issues open regarding the behavior/rendering of emoji in the terminal.
As of 2.0.2.Final, you should specify the groupId, artifactId and version using group:artifactId:version coordinate syntax directly on the command line. You can selectively omit segments to use default values:
# Create a project with groupId=org.acme, artifactId=bar, and version=1.0.0-SNAPSHOT
quarkus create app bar
# Create a project with groupId=com.foo, artifactId=bar, and version=1.0.0-SNAPSHOT
quarkus create app com.foo:bar
# Create a project with groupId=com.foo, artifactId=bar, and version=1.0
quarkus create app com.foo:bar:1.0
A saída mostrará seu projeto sendo criado:
-----------
applying codestarts...
📚 java
🔨 maven
📦 quarkus
📝 config-properties
🔧 dockerfiles
🔧 maven-wrapper
🚀 resteasy-codestart
-----------
[SUCCESS] ✅ quarkus project has been successfully generated in:
--> /<output-dir>/bar
-----------
Use the help option to display options for creating projects:
quarkus create app --help
quarkus create cli --help
|
Previous versions of the CLI used options |
Especificando a versão do Quarkus
Both quarkus create and quarkus extension list allow you to explicitly specify a version of Quarkus in one of two ways:
-
Forneça um Platform Release BOM específico
A Quarkus Platform release BOM is identified by
groupId:artifactId:version(GAV) coordinates. When specifying a platform release BOM, you may use empty segments to fall back to default values (shown withquarkus create app --help). If you specify only one segment (no:), it is assumed to be a version.For example:
-
With the
2.0.0.Finalversion of the CLI, specifying-P :quarkus-bom:is equivalent to-P io.quarkus:quarkus-bom:2.0.0.Final. Specifying-P 999-SNAPSHOTis equivalent to-P io.quarkus:quarkus-bom:999-SNAPSHOT. -
With the
2.1.0.Finalversion of the CLI,io.quarkus.platformis the default group id. Specifying-P :quarkus-bom:is equivalent to-P io.quarkus.platform:quarkus-bom:2.1.0.Final. Note that you need to specify the group id to work with a snapshot, e.g.-P io.quarkus::999-SNAPSHOTis equivalent to-P io.quarkus:quarkus-bom:999-SNAPSHOT.Note: default values are subject to change. Using the
--dry-runoption will show you the computed value.
-
-
Forneça um Plataform Stream
Um platform stream opera em um registro remoto. Cada registro define um ou mais platform stream, e cada fluxo define um ou mais arquivos do platform release BOM que definem como os projetos que usam esse fluxo devem ser configurados.
Streams são identificados usando a sintaxe
platformKey:streamId. Um stream específico pode ser especificado usando-S platformKey:streamId. Ao especificar um stream, os segmentos vazios serão substituídos por valores padrões descobertos, com base nas regras de resolução de recursos stream.
Trabalhando com extensões
quarkus ext --help
Listando extensões
The Quarkus CLI can be used to list Quarkus extensions.
quarkus ext ls
O formato do resultado pode ser controlado com uma das quatro opções:
-
--nameDisplay the name (artifactId) only -
--conciseExibir o nome (artifactId) e a descrição -
--fullDisplay concise format and version/status-related columns. -
--originsExibe informação concisa segundo a origem da extensão na plataforma Quarkus.
O comportamento do quarkus ext ls varia de acordo com o contexto.
Listing Extensions for a Quarkus release
If you invoke the Quarkus CLI from outside of a project, Quarkus will list all the extensions available for the Quarkus release used by the CLI itself.
You can also list extensions for a specific release of Quarkus using -P or -S, as described in Specifying the Quarkus version.
This mode uses the --origins format by default.
Listing Extensions for a Quarkus project
When working with a Quarkus project, the CLI will list the extensions the current project has installed, using the --name format by default.
Use the --installable or -i option to list extensions that can be installed from the Quarkus platform the project is using.
You can narrow or filter the list using search (--search or -s).
quarkus ext list --concise -i -s jdbc
JDBC Driver - DB2 quarkus-jdbc-db2
JDBC Driver - PostgreSQL quarkus-jdbc-postgresql
JDBC Driver - H2 quarkus-jdbc-h2
JDBC Driver - MariaDB quarkus-jdbc-mariadb
JDBC Driver - Microsoft SQL Server quarkus-jdbc-mssql
JDBC Driver - MySQL quarkus-jdbc-mysql
JDBC Driver - Oracle quarkus-jdbc-oracle
JDBC Driver - Derby quarkus-jdbc-derby
Elytron Security JDBC quarkus-elytron-security-jdbc
Agroal - Database connection pool quarkus-agroal
Build your project
To build your project using the Quarkus CLI (using the default configuration in this example):
quarkus build
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< org.acme:code-with-quarkus >---------------------
[INFO] Building code-with-quarkus 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.331 s
[INFO] Finished at: 2021-05-27T10:13:28-04:00
[INFO] ------------------------------------------------------------------------
| A saída varia de acordo com a ferramenta de compilação que seu projeto está usando (Maven, Gradle ou JBang). |
Modo de desenvolvimento
quarkus dev --help
To start dev mode from the Quarkus CLI do:
quarkus dev
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< org.acme:code-with-quarkus >---------------------
[INFO] Building code-with-quarkus 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
...
Listening for transport dt_socket at address: 5005
__ ____ __ _____ ___ __ ____ ______
--/ __ \/ / / / _ | / _ \/ //_/ / / / __/
-/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2021-05-27 10:15:56,032 INFO [io.quarkus] (Quarkus Main Thread) code-with-quarkus 1.0.0-SNAPSHOT on JVM (powered by Quarkus 999-SNAPSHOT) started in 1.387s. Listening on: http://localhost:8080
2021-05-27 10:15:56,035 INFO [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.
2021-05-27 10:15:56,035 INFO [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy-reactive, smallrye-context-propagation]
--
Tests paused, press [r] to resume
| A saída varia de acordo com a ferramenta de compilação que seu projeto está usando (Maven, Gradle ou JBang). |
|
Compatibility with Quarkus 1.x
The version 2 Quarkus CLI can not be used with 1.x Quarkus projects or releases. Use the Maven/Gradle plugins when working with Quarkus 1.x projects. |
Autocompletar e atalhos do terminal
Automatic command completion is available for Bash and Zsh:
# Setup autocompletion in the current shell
source <(quarkus completion)
If you choose to use an alias for the quarkus command, adjust command completion with the following commands:
# Add an alias for the quarkus command
alias q=quarkus
# Add q to list of commands included in quarkus autocompletion
complete -F _complete_quarkus q
Imagens de Contêiner
A CLI do Quarkus permite criar imagens de containers sem interferir na configuração do projeto (adicionar/remover extensões de imagens de containers). Para criar a imagem do seu projeto:
quarkus image build
O comando image build pode ser usado diretamente ou um subcomando pode ser adicionado. Os subcomandos disponíveis são:
-
docker
-
buildpacks
-
jib
-
openshift
Cada subcomando corresponde a uma ferramenta de criação de imagens compatível com o Quarkus e dá acesso a opções de configuração específicas.
Por exemplo, para usar um Cloud Native Buildpack com uma imagem personalizada, use o seguinte:
quarkus image build buildpack --builder-image <your builder image>