Local development

To run the code for your challenge locally, you’ll need java & mvn installed. Our test runners use Java 21 (as of November 2023).

The script for your challenge (like ./your_bittorrent.sh) will automatically compile your code using mvn before executing it. It’ll look something like this:

#!/bin/sh
set -e
mvn -B --quiet package -Ddir=/tmp/codecrafters-redis-target
exec java -jar /tmp/codecrafters-redis-target/java_redis.jar "$@"

When running tests on our servers, the mvn command will only be run once and then commented out. This ensures that each test only runs the java -jar ... line.

File structure

  • The files for your solution are placed in the src/main/java directory.
  • src/main/java/Main.java contains the Main function, which is what the test runner executes.

Adding more files

You can add more files and directories to the src/main/java directory. The test runner will include them when compiling your code.

TODO: Add an example of adding a file.

This section is incomplete, and we’d love your help expanding it. We’re already got a similar section in the Kotlin Guide that you can use as a reference. If you’d like to help out, please open a PR at codecrafters-io/docs.

Adding dependencies

You can add dependencies to your project by adding them to your pom.xml file.

For example, to add the gson library, add the following to the <dependencies> section in your pom.xml:

<dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
  <version>2.8.6</version>
</dependency>

When you push your code next, the runner will automatically download the dependency.