Maven is an all-in-one CI-CD tool for building testing and deploying Java projects. To setup a sample project with Java and Maven in devbox follow the steps below:
- Create a dummy folder:
dummy/and calldevbox initinside it. Then add the nix-pkg:devbox add jdkanddevbox add maven.- 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:
mvn archetype:generate -DgroupId=com.devbox.mavenapp -DartifactId=devbox-maven-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false- In the generated
pom.xmlfile, replace java version in<maven.compiler.source>with the specific version you are testing for.
- In the generated
mvn packageshould compile the package and create atarget/directory.java -cp target/devbox-maven-app-1.0-SNAPSHOT.jar com.devbox.mavenapp.Appshould print "Hello World!".- Add
target/to.gitignore.
To test a sample Gradle app with devbox, follow the steps below:
- Create a dummy folder:
dummy/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
gradle.buildfile, put the following text block:apply plugin: 'java' apply plugin: 'application' sourceCompatibility = 17 targetCompatibility = 17 mainClassName = 'hello.HelloWorld' jar { manifest { attributes 'Main-Class': 'hello.HelloWorld' } }
- In the generated
gradle buildshould compile the package and create abuild/directory that contains an executable jar file.gradle runshould print "Hello World!".- Add
build/to.gitignore.