|

JUST – CLI for developing Spring Boot applications

JUST is command line toolkit which greatly simplifies the developing of Spring Boot Applications.

Introducing Just, the go-to command line tool designed to enhance your Spring Boot developer experience! Currently offering the incredible “Just Run” feature.

Get ready for Just Run, the only command you’ll need to kickstart your Spring Boot application in development mode. It seamlessly takes care of:

1. Live reload – Say goodbye to the hassle of rebuilding, recompiling, or restarting applications. Just save your changes in IntelliJ IDEA and watch as Just compiles the updated code, reflecting alterations in mere seconds.

2. Zero-config infrastructure services – Starting infrastructure services like databases and message queues has never been easier. Just detects your application’s connection to a service, launches a docker container, and configures the connection effortlessly. Plus, these services launch only once without impacting live reload performance!

3. Docker compose integration – Utilizing a docker-compose.yml for local development? Just will automatically execute “docker compose up” before launching your application and even live reloads Docker containers whenever the docker-compose.yml file is modified.

4. Project run command selection – Maven or Gradle? Daemon or Wrapper? With Just Run, there’s no need to choose. Everything is determined automatically for you.

Requirements

Spring Boot projects that require Java 11+ and compatible with Spring Boot Dev tools

Docker if you want to use zero-config infrastructure services or docker compose file

Installation

JUST can be installed either using package managers (Homebrew for Mac OS, scoop for Windows) or manually by downloading the binary.

Note: At the moment only x86_64 architectures are supported.

Using Scoop

scoop bucket add maciejwalkowiak https://github.com/maciejwalkowiak/scoop-just.git
Code language: Java (java)
scoop install justCode language: Java (java)

Manual

Download just-0.12.0-windows-x86_64.zip, unzip it, and place just.exe in the PATH.

Using Homebrew

brew install maciejwalkowiak/brew/justCode language: Java (java)

Manual

curl -Lo just.zip https://github.com/maciejwalkowiak/just/releases/latest/download/just-0.13.0-osx-x86_64.zip && unzip just.zip && chmod +x just && sudo mv just /usr/local/bin/just && just helpCode language: Java (java)

Manual

curl -Lo just.zip https://github.com/maciejwalkowiak/just/releases/latest/download/just-0.13.0-linux-x86_64.zip && unzip just.zip && chmod +x just && sudo mv just /usr/local/bin/just && just helpCode language: Java (java)

You can test the installation with following command.

just helpCode language: Java (java)
    ??????   ????????????????????
       ??????   ????????????????????
       ??????   ???????????   ???
  ??   ??????   ???????????   ???
  ?????????????????????????   ???
   ??????  ??????? ????????   ???

Usage: just [-V] [COMMAND]
  -V, --version   Print Just version
Commands:
  run     runs Spring Boot project - either with Maven or Gradle in dev mode
            with hot reloading enabled
  help    Display help information about the specified command.
  format  formats code with Spotless
  init    initializes Just related files
  build   builds application
  kill    kills process running on portCode language: Java (java)

How it works?

JUST CLI transparently  adds Spring Boot Devtools dependency to the project and also monitors the source for changes and starts compilation using Maven or Gradle when it detects a change.

It also responds to changes in build files such as pom.xml or build.gradle; anytime a change occurs, it pauses the Spring Boot application, refreshes the build file, and restarts the application. Because of this, you may execute run only once, amend any source file, and the programme will take care of reflecting the changes.

JUST CLI also starts the its own server on random available port

Usage

Now let’s look at the how to use Just CLI.

You have to run following commands from the root of the project.

Just run

just run
Code language: Java (java)

The above command launches Spring Boot application in the development mode with live reload, Docker Compose Support and zero config infrastructure services.

Passing command line arguments to Maven/Gradle

Anything that is added after just run is passed to Maven/Gradle commands. For example, to activate a Maven profile named local run:

$ just run -Plocal
Code language: Java (java)

Running just server on fixed port

By default just run starts the just server on the random available port. To run it with fixed port, set the environment variable JUST_SERVER_PORT:

$ JUST_SERVER_PORT=8081 just runCode language: Java (java)

Running multi-module Maven projects

 Just ( from versio 0.13)  works with multi-module Maven projects.

$ just run <module-directory>
Code language: Java (java)

For example for following project structure:

.
├── application
│   └── pom.xml
├── library
│   └── pom.xml
└── pom.xml
Code language: Java (java)

application module is the one that is meant to be run (it has @SpringBootApplication annotated class), to run project with just execute:

$ just run applicationCode language: Java (java)

Just build

just buildCode language: Java (java)

just build command builds the spring boot project. The command automatically detects Maven or Gradle build tool and picks up the best command to execute ( mvn./mvnwmvndgradle./gradlew)

CommandDescriptionMavenGradle
just buildbuilds the jarmvn packagegradle build
just build native
mvn native:compile -Pnativegradle nativeCompile
just build native-image
builds a Docker Image with a native executablemvn spring-boot:build-image -Pnativegradle bootBuildImage
just build imagebuilds a Docker Image with an executable JARmvn spring-boot:build-image
gradle bootBuildImage

just build command can be customized by using just.properties or just.yml file in project root directory.

PropertyDescriptionDefault value
just.build.extra-argsExtra command line arguments passed to Maven or Gradle
just.build.default-targeta default target to build when the command is invoked with just buildjar
just.build.services.enabledenables/disables Zero-Config Infrastructure Services feature during the build phasetrue

just format

just formatCode language: Java (java)

just format formats the code with Spring Java Format or Spotless depending on the plugin configured.

If none of the plugin is configured , it defaults to Spring Java Format.

just kill

$ just kill -p 8082
Code language: Java (java)

just kill allows you to quickly and easily kill processes that are listening on specific ports. This can be useful if you need to free up a port for a different process, or if you want to stop a process that is no longer needed.

Customizing Just

just run command can be customized by using just.properties or just.yml file in project root directory.

PropertyDefault valueDescription
just.framework
none This should be used only if Just is unable to identify that the project utilises Spring Boot for some reason. SPRING_BOOT is one of the possible values.
just.run.live-reload.enabled trueenables/disables live-reload feature
just.run.live-reload.browser.enabled trueenables/disables frontend resources reload without a browser refresh
just.run.maven.profilesa comma-separated list of Maven profiles to activate (passed with -Pprofile1,profile2)
just.run.spring-boot.profilesa comma-separated list of Spring Boot profiles to activate (as spring.profiles.active)
just.run.docker-compose.enabled trueenables/disables Docker Compose feature
just.run.docker-compose.filedocker-compose.ymlDocker Compose YML file path relative to project root
just.run.services.enabledtrueenables/disables Zero-Config Infrastructure Services feature

Docker Compose support

If your project uses docker compose file to start the database, queue service or any other service, JUST CLI can start the services defined in the docker compose file.

To refresh running containers, just execute docker compose up –remove-orphans whenever there is a change in docker-compose.yml

The zero-config infrastructure services capability is immediately disabled when Docker Compose support is enabled and a docker-compose.yml file exists.

Docker Compose support can be disabled through setting a property in just.properties:

just.run.docker-compose.enabled=false
Code language: Java (java)

Docker Compose file name and path can be customized with property:

just.run.docker-compose.file=services.yml
Code language: Java (java)

Note

To run services defined in docker compose with just, you must have Docker Compose version 2.7.0 or newer installed in your system.

Zero Config Infrastructure Services

just run command, communicates with Just server to start infrastructure services whenever a configuration property for such service is not set.

For example, if you add spring-boot-starter-data-jpa and a JDBC driver for PostgreSQL but you do not set spring.datasource.url property in application.properties, Just will automatically download docker image of Postgres Database and start database and set all spring.datasource.* properties needed by the application to connect to Postgres.

To start zero config services JUST CLI internally makes use of Tesstcontainers libraries.

This applies to following infrastructure services:

  • PostgreSQL
  • MySQL
  • MongoDB
  • Neo4j
  • RabbitMQ

Infrastructure Services can be disabled through setting a property in just.properties:

just.run.services.enabled=falseCode language: Java (java)

If are using zero config infrastructure , you can customize the properties like image and port to be used and enable/disable services.

PostgreSQL

PropertyDescriptionDefault value
just.run.services.postgres.enabledenables/disables starting PostgreSQL database when requestedtrue
just.run.services.postgres.log-queriesenables/disables logging SQL queries by PostgreSQL (experimental)false
just.run.services.postgres.image-namePostgreSQL Docker Image Namepostgres:13.3
just.run.services.postgres.portTCP port on which PostgreSQL is exposed5432

MySQL

PropertyDescriptionDefault value
just.run.services.mysql.enabledenables/disables starting MySQL database when requestedtrue
just.run.services.mysql.image-nameMySQL Docker Image Namemysql:8.0.30
just.run.services.mysql.portTCP port on which MySQL is exposed3306

RabbitMQ

PropertyDescriptionDefault value
just.run.services.rabbitmq.enabledenables/disables starting RabbitMQ when requestedtrue
just.run.services.rabbitmq.image-nameRabbitMQ Docker Image Namerabbitmq:3.7.25-management-alpine
just.run.services.rabbitmq.portTCP port on which RabbitMQ is exposed5672
just.run.services.rabbitmq.management-portTCP port on which RabbitMQ Management Console is exposed15672

Neo4j

PropertyDescriptionDefault value
just.run.services.neo4j.enabledenables/disables starting Neo4j database when requestedtrue
just.run.services.neo4j.image-nameNeo4j Docker Image Nameneo4j:4.4
just.run.services.neo4j.portTCP port on which Neo4j is exposed7687

MongoDB

PropertyDescriptionDefault value
just.run.services.mongodb.enabledenables/disables starting MongoDB database when requestedtrue
just.run.services.mongodb.image-nameMongoDB Docker Image Namemongo:4.0.10
just.run.services.mongodb.portTCP port on which MongoDB is exposed27017

Redis

PropertyDescriptionDefault value
just.run.services.redis.enabledenables/disables starting Redis database when requestedtrue
just.run.services.redis.image-nameRedis Docker Image Nameredis:7.0.5-alpine
just.run.services.redis.portTCP port on which Redis is exposed6379

Zipkin

PropertyDescriptionDefault value
just.run.services.zipkin.enabledenables/disables starting Zipkin when requestedtrue
just.run.services.zipkin.image-nameZipkin Docker Image Nameopenzipkin/zipkin:2.24
just.run.services.zipkin.portTCP port on which Redis is exposed9411

References

https://just.maciejwalkowiak.com/

Similar Posts