In addition to installing the JDK, you'll need to install either the Maven or Gradle build systems in your shell.
In both cases, you'll want to first activate devbox shell before generating your Maven or Gradle projects, so that the tools use the right version of the JDK for creating your project.
devbox add jdk binutils, or in your devbox.json
"packages": [
"jdk@latest",
"binutils@latest"
],
This will install the latest version of the JDK. To find other installable versions of the JDK, run devbox search jdk.
Other distributions of the JDK (such as OracleJDK and Eclipse Temurin) are available in Nixpkgs, and can be found using NixPkg Search
Gradle is a popular, multi-language build tool that is commonly used with JVM projects. To setup an example project using Gradle, follow the instructions below:
-
Create a project folder:
my-project/and calldevbox initinside it. Then add these packages:devbox add jdkanddevbox add gradle.- Replace
jdkwith the version of JDK you want. Get the exact nix-pkg name fromsearch.nixos.org.
- Replace
-
Then do
devbox shellto get a shell with thatjdknix pkg. -
Then do:
gradle init-
In the generated
build.gradlefile, put the following text block:/* build.gradle */ apply plugin: 'java' apply plugin: 'application' /* Change these versions to the JDK version you have installed */ sourceCompatibility = 17 targetCompatibility = 17 mainClassName = 'hello.HelloWorld' jar { manifest { /* assuming main class is in src/main/java/hello/HelloWorld.java */ attributes 'Main-Class': 'hello.HelloWorld' } }
-
While in devbox shell, run
echo $JAVA_HOMEand take note of its value. -
Create a
gradle.propertiesfile like below and put value of$JAVA_HOMEinstead of <JAVA_HOME_VALUE> in the file./* gradle.properties */ org.gradle.java.home=<JAVA_HOME_VALUE>
-
-
gradle buildshould compile the package and create abuild/directory that contains an executable jar file. -
gradle runshould print "Hello World!". -
Add
build/to.gitignore.
An example devbox.json would look like the following:
{
"packages": [
"gradle",
"jdk",
"binutils"
],
"shell": {
"init_hook": null
}
}

