Mastering Quarkus CLI Command (with examples)
Quarkus is a Kubernetes-native Java framework tailored for GraalVM and OpenJDK HotSpot to provide a unified development experience. The Quarkus CLI tool allows developers to easily create and manage Quarkus projects, augment them with valuable extensions, and streamline essential build and deployment tasks. This powerful tool helps in reducing boilerplate, increasing productivity, and enhancing developer comfort through dynamic workflows.
Use case 1: Creating a New Application Project
Code:
quarkus create app project_name
Motivation:
Starting a new project can often be time-consuming, especially when configuring a development environment. Using the Quarkus CLI to create a new application project accelerates this initial step, providing a standardized project structure with necessary configurations, dependencies, and boilerplate code. This is especially beneficial for developers who aim to quickly prototype ideas or establish a new service.
Explanation:
quarkus
: Invokes the Quarkus CLI tool, opening access to various commands associated with project management and development.create app
: Specifies the action to be taken โ here, to create a new application project.project_name
: The desired directory name for the new project, which becomes the root folder storing all the project files.
Example Output:
๐จ Creating a new project with the following parameters:
-> Project name (project_id) : project_name
-> Build tool : Maven
-> Java version : 11
๐ New Quarkus project created in: /path/to/project_name
Use case 2: Running the Current Project in Live Coding Mode
Code:
quarkus dev
Motivation:
During application development, the ability to immediately see the effects of code changes without stopping and restarting the whole application can significantly enhance productivity. Live coding mode facilitates this by automatically detecting changes and recompiling the code, reducing downtime between changes and testing.
Explanation:
quarkus
: The command-line interface for Quarkus operations.dev
: Initiates live coding mode, offering a continuous feedback loop for developers by monitoring file changes and refreshing the application instantaneously.
Example Output:
โ Quarkus application started in live coding mode
๐ Scanning for changes...
Notice: Press Enter to restart application manually or e to edit and restart.
Use case 3: Running the Application
Code:
quarkus run
Motivation:
Once an application is ready for execution, developers often need an efficient way to start the application to perform various operational tests or demonstrate its functionality. The quarkus run
command simplifies running an application, abstracting away the need for complex scripts or setups.
Explanation:
quarkus
: The command-line tool for Quarkus based management.run
: Command that starts the application in its production-like or current configuration mode, initiating all services defined within the project.
Example Output:
๐ Quarkus application running...
๐ Server started on http://localhost:8080
Use case 4: Running the Current Project in Continuous Testing Mode
Code:
quarkus test
Motivation:
Automated testing plays a crucial role in maintaining code quality. By running tests continuously, developers are apprised of any breaking changes instantly, ensuring reliability and correctness of their code base. Continuous testing mode encourages a test-driven development approach, immediately notifying developers of issues.
Explanation:
quarkus
: The entry point for Quarkus CLI commands.test
: Instructs the CLI to run the project’s test suite continuously, re-executing tests when changes in the test files or related code occur.
Example Output:
๐งช Running tests...
All tests passed! (20/20) - Great job!
Use case 5: Adding Extensions to the Current Project
Code:
quarkus extension add extension_name1 extension_name2 ...
Motivation:
Quarkus extensions simplify the integration and management of various libraries and frameworks within a project, such as Hibernate or RESTEasy. Adding these extensions through the CLI avoids manual inclusion in build files, ensuring that dependencies are correctly curated and configured.
Explanation:
quarkus
: Accesses Quarkus CLI functionalities.extension add
: Command to add specified extensions to the current project.extension_name1 extension_name2 ...
: Names of the extensions to be added, provided as a space-separated list.
Example Output:
โจ Extensions added:
โ extension_name1
โ extension_name2
Use case 6: Building a Container Image Using Docker
Code:
quarkus image build docker
Motivation:
Containerization has become a staple in deploying reproducible and portable applications across various environments. The quarkus image build docker
command conveniently packages a Quarkus application into a Docker image, ensuring that dependencies and configurations are consistently bundled.
Explanation:
quarkus
: Invokes the Quarkus command-line tool.image build
: Indicates the task involving creating an image.docker
: Signifies the technology used for building the image, here being Docker.
Example Output:
๐ณ Docker image build successful: quarkus-app:latest
Use case 7: Deploying the Application to Kubernetes
Code:
quarkus deploy kubernetes
Motivation:
Deploying applications to Kubernetes enhances scalability, reliability, and management due to its container orchestration capabilities. Using the CLI to deploy simplifies and automates the integration process with Kubernetes clusters, ensuring a streamlined deployment pipeline.
Explanation:
quarkus
: Entry point to the Quarkus CLI tool.deploy
: Command performing the deployment task.kubernetes
: Specifies the target platform where the application will be deployed.
Example Output:
๐ Application deployed successfully to Kubernetes!
Use case 8: Updating the Project
Code:
quarkus update
Motivation:
Keeping a project up to date with the latest dependencies and Quarkus versions is vital for security and access to new features. The quarkus update
command facilitates this, ensuring projects remain stable and efficient by maintaining currency with new releases and updates automatically.
Explanation:
quarkus
: Pertains to the Quarkus CLI execution tool.update
: Performs an update check for project dependencies and framework components to align with the newest versions.
Example Output:
๐ฆ Project updated successfully: Your project uses the latest version of Quarkus and dependencies.
Conclusion:
Harnessing the Quarkus CLI commands allows for seamless transitions between development phases, from setting up and running applications, through augmenting them with useful extensions, to deploying on modern cloud infrastructure platforms. These versatile and efficient commands ensure that developers can focus more on creating features and less on configuring environments, enhancing their productivity while building powerful, reliable Java applications with Quarkus.