Just: a tool to store and execute your project commands

Just” (or “Justfile”) is a handy command-line tool that simplifies the execution of project-specific commands tasks. In this tutorial, we’ll explore why and how to use “Just” to enhance your day-by-day command line tasks.

Introduction to “Just”

As a developer, I have been using the command line script files (e.g. bashrc) as a repository of functions to manage all of my daily tasks. For example, shortcuts to build artifacts or to start docker images. At the end of the day, the number of functions or aliases grew up so much I simply forgot I had them available.

That’s where I switched to “Just“. Just is a command-line tool that allows you to define, save, and run project-specific commands in a more human-readable and convenient way. It abstracts away the complexities of running lengthy command lines or scripts and provides a simplified interface for executing tasks.

Advantages of Using “Just”

  • Simplified Command Execution: With “Just,” you can define meaningful names for your project-specific tasks, making it easier to execute them. This simplifies the process, especially for team members who may not be familiar with the intricacies of your project.
  • Improved Readability: “Justfiles” are typically more readable than complex command lines. This enhances the understanding of project tasks and aids collaboration within your team.
  • Customization: You can extend “Just” commands to include additional logic or steps beyond what your build system offers. This flexibility helps integrate with other tools and customize your project’s workflow.
  • Separation of Concerns: You can avoid to fill up your profile commands with a myriad of functions. You can define simple justfile to cover standard development tasks.

3. Getting Started with “Just”

To get started with “Just,” follow these steps:

Step 1: Installation: Install the “Just” command-line tool on your system. You can usually do this using a package manager or by downloading the binary from the official “Just” repository. For example, to install just from the binaries, you can do it with a single command:

curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to DEST

Step 2: Edit Justfile: Open the Justfile in a text editor and define your project-specific commands. Let’s see how to do it in the next paragraphs.

4. Creating and Using a Justfile

Firstly, just searches for a justfile in the current directory written in its particular syntax. Within the justfile, you define your project’s tasks and their corresponding commands. Here’s a simple example:

# Justfile
set shell := ["bash", "-uc"]

# Build the project
build:
    mvn clean install

# Run tests
test:
    mvn test

The above is a sample justfile which applies some settings in the environment (the shell to use) and then defines two tasks. At the end of the day, you will use plain bash/sh syntax for your tasks, in combination with some shortcuts available in just.

Firstly, by executing “just --list” you can see the list of tasks which are evailable:

just --list
build
test

Then, by executing only “just”, it will execute by default the first task (build)

just

On the other hand, if you provide the task name, it will execute that specific task. For example:

just test

Within your justfile, you can define aliases that you can use in your justfile using the := operator. Also, you can use backticks to have shell expansion. For example, the following snippet declares the JAVA_HOME alias to the value returned by the ‘jbang jdk home 11’ command:

JAVA_HOME := `jbang jdk home 11`

You can also provide parameter to your just tasks in a simple way. For example:

salute guy:
    @echo "Hello {{guy}}!"

The above salute function accepts the variable guy as parameter, therefore you can call is as follows:

just salute frank
Hello frank!

Finally, if you want to use a non-default filename for just, simply pass it as argument to the --justfile as follows:

just --color <COLOR> --dump-format <FORMAT> --justfile <JUSTFILE>

A justfile for Quarkus

As an example, here is a basic justfile I’m using to build a Quarkus project:

# Build and Run tests
build:
    mvn clean verify

# Build without test
quick:
    mvn clean package -DskipTests

# Launch dev mode
dev:
    mvn quarkus:dev

run: quick
    java -jar target/quarkus-app/quarkus-run.jar

You can find the GitHub project here, which contains links to the documentation and some examples of just: https://github.com/casey/just/

Found the article helpful? if so please follow us on Socials