Skip to content
Public template

About

Java development template with GraalVM JDK, Maven, Gradle, and pre-commit hooks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java development environment

Nix flake template for Java and JVM projects. The dev shell provides GraalVM CE as the JDK, Maven, and Gradle. Maven and Gradle are configured to use the GraalVM JDK. The flake is built with purr and uses git-hooks.nix for pre-commit hooks.

Part of the develop-templates collection.

Quick start

Create the project files in the current directory:

nix flake init -t "github:nixcafe/develop-templates#java" --refresh

Register the collection once to use the shorter name:

nix registry add beans "github:nixcafe/develop-templates"
nix flake init -t beans#java

With cattery-modules, beans is already registered.

You can also create a repository from the template repository:

gh repo create my-java-project --template nixcafe-develop/java --clone

Enter the dev shell:

nix develop

If direnv is installed, direnv allow loads the shell when you enter the directory. The template includes an .envrc that calls use flake.

The template does not include a flake.lock. The first nix develop resolves the inputs and writes one.

What's included

Tool Purpose
GraalVM CE JDK used by Maven and Gradle
Maven Build and dependency management
Gradle Build and dependency management

The dev shell has a shell hook that installs the hooks enabled in develop/checks/git-hooks/default.nix. The hooks set in this template is empty, so no hooks run until you enable some.

Useful commands

nix develop          # enter the dev shell
direnv allow         # load the shell through direnv
mvn --version        # print the Maven and Java versions
gradle --version     # print the Gradle and JVM versions

Customizing

Use a different JDK

develop/shells/default/default.nix sets:

jdk = pkgs.graalvmPackages.graalvm-ce;

Replace it with another JDK package from nixpkgs, for example:

jdk = pkgs.jdk23;

Maven and Gradle are defined in terms of jdk, so both use the new JDK.

Enable pre-commit hooks

develop/checks/git-hooks/default.nix starts with an empty hooks set. Add entries to enable hooks:

hooks = {
  nixfmt.enable = true;
  deadnix.enable = true;
  statix.enable = true;
};

See git-hooks.nix for the available hooks. The shell hook installs enabled hooks when you enter the dev shell.

Project structure

.
├── flake.nix                          # Flake entry point
├── .envrc                             # direnv: use flake
├── .gitignore
└── develop/
    ├── shells/default/default.nix     # Dev shell (GraalVM, Maven, Gradle)
    └── checks/git-hooks/default.nix   # Pre-commit hook configuration

About

Java development template with GraalVM JDK, Maven, Gradle, and pre-commit hooks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

Generated from nixcafe-develop/nix