Mastering Quarkus CLI Command (with examples)

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.

Related Posts

How to use the command 'aws codecommit' (with examples)

How to use the command 'aws codecommit' (with examples)

AWS CodeCommit is a fully managed source control service for hosting secure and scalable private Git repositories.

Read More
Exploring the 'git ls-tree' Command (with examples)

Exploring the 'git ls-tree' Command (with examples)

The git ls-tree command is a versatile tool within the Git version control system that allows users to explore the contents of tree objects, which represent directories in a Git repository.

Read More
How to Use the Unix 'ed' Command (with Examples)

How to Use the Unix 'ed' Command (with Examples)

The ’ed’ command is a powerful text editor inherent to Unix systems and serves as one of the original forms of file manipulation in the Unix environment.

Read More