A small, hand-written Java build system inspired by tsoding/nob.h. It keeps build steps explicit and editable in ordinary Java, without Gradle, Maven, plugins, or mandatory third-party dependencies. It is intended as a lightweight starting point for small projects and custom build tasks—not as a replacement for full-featured build tools.
- JDK 17 or newer (
java,javac, andjaronPATHfor the tasks that use them). - Run commands from the project root: the directory containing
build.java.
java -version
javac -versionjava build.java help
java build.java build
java build.java run -- hello worldbuild.java contains the entire utility as one Java source file and runs directly through Java source-file mode. By default, it compiles src/**/*.java into build/classes/; run launches Main with the arguments after --.
| Command | What it does |
|---|---|
java build.java or build |
Compile configured application sources and copy resources. |
run [--main CLASS] [--jvm OPT] [-- ARGS...] |
Build and launch the app. JVM options may be repeated; arguments after -- go to the app. |
test [--main CLASS] [--jvm OPT] [-- ARGS...] |
Build, compile configured test sources if present, and run the configured test runner with assertions enabled. |
verify |
Build and run configured tests; if no test runner is configured, perform a build and reject unconfigured test sources. |
jar |
Build an executable JAR with the configured main class, resources, and optional custom manifest. |
sources |
List Java files in configured source roots. |
plan |
Show the active profile and key build settings without running build commands. |
doctor |
Print the project root and check Java/Javac availability. |
exec -- COMMAND [ARGS...] |
Run an external command with the project root as its working directory. |
clean |
Remove generated files under build/. |
help |
Display command help. |
Examples:
java build.java run --main app.Main --jvm -ea -- --verbose "file with spaces.txt"
java build.java test --jvm -Dsample.mode=ci -- first "two words"
java build.java exec -- java -versionrun and test pass repeated --jvm options directly to the JVM. For example, start the app with a local JDWP listener and attach an IDE debugger:
java build.java run --jvm '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:5005'The listener is opt-in; use a loopback address and do not expose a debug port to an untrusted network. test accepts the same --jvm option.
For a project that needs Maven, Gradle, or another tool, exec can invoke it with explicit arguments:
java build.java exec -- mvn test
java build.java exec -- gradle buildThe external tool must already be installed/on PATH (or invoked by an explicit wrapper command). exec uses the project root as working directory, does not start a shell, and returns the subprocess exit code. When adopting Maven or Gradle as the authoritative build, keep dependency and build configuration there rather than duplicating it in build.properties; use this utility only for workflows it still owns, or migrate fully. This tool does not translate its configuration into theirs.
Arguments are passed as process arguments, not shell text. exec does not invoke a shell; to use pipes or redirection, explicitly run a shell, for example java build.java exec -- sh -c 'echo hello | sort'.
All settings are optional and read from build.properties in the project root. Relative paths are resolved from that root.
| Setting | Default | Purpose |
|---|---|---|
source.dir |
src |
One application Java source root. |
source.dirs |
— | Multiple source roots, separated with the platform path separator (: on Unix-like systems, ; on Windows); overrides source.dir. |
output.dir |
build/classes |
Compiled application classes. Keep it under build/ if clean should remove it. |
test.dir |
test |
Optional Java test source root. |
test.main |
— | Main class for the test runner. It can be compiled from the app sources or test.dir; there is no built-in test framework or discovery. |
resources.dir |
resources |
One resource root copied into application class output. |
resources.dirs |
— | Multiple resource roots using the platform path separator; overrides resources.dir. |
main.class |
Main |
Default application entry point. |
javac.options |
— | Compiler options, split on whitespace. Quoted values containing spaces are not supported. |
classpath |
— | Compatibility shorthand used for both compile and runtime dependencies. |
compile.classpath |
classpath |
Platform-separated files/directories used by javac. Entries are checked before compilation. |
runtime.classpath |
classpath |
Platform-separated files/directories used when running applications and tests. Entries are checked before launch. |
jar.name |
app.jar |
JAR file name/path relative to build/. |
jar.manifest |
— | Optional manifest file path for custom JAR metadata. |
profile |
default |
Default profile name. |
Profile-prefixed properties override their base setting. Select a profile in the file or for one command with -Dbuild.profile=NAME:
profile=development
javac.options=-g
profile.release.javac.options=--release 17 -Xlint:all
profile.release.output.dir=build/release-classesjava -Dbuild.profile=release build.java buildDependencies are explicit local paths; the tool does not download or resolve artifacts. Compile and runtime classpaths can differ. A normal executable JAR contains the project’s compiled classes and resources, not its dependencies; use an explicit runtime classpath or distribution if external libraries are needed at runtime.
The examples/ directory contains focused projects for basic builds, CLI arguments, resources/tests/JARs, profiles, local dependencies, JDWP debugging, and Maven/Gradle delegation. Each standalone helper example has its own copy of build.java; refresh copies after changing the root implementation:
for f in examples/*/build.java; do cp build.java "$f"; doneRun the automated smoke checks from the repository root with sh scripts/check-examples.sh. They require JDK 17+, verify copies are in sync, exercise key commands/failure statuses, and run Maven/Gradle samples only when those tools are installed. Maven/Gradle checks may need network access to resolve plugins; they are optional integrations, not core requirements.
The checks are currently shell-based and best suited to Unix-like environments. Windows path separators, Unicode/space-containing project paths, and Windows subprocess behavior still need dedicated verification; do not treat passing the script as proof of Windows compatibility. External commands are passed as argument lists without an implicit shell. exec returns the child's status; launch errors and invalid usage are reported by the helper. run/test return the application/runner status, while configuration errors use status 2 and build/tool failures use status 1 (interruption uses 130).
The examples/ directory contains standalone projects, each with its own copy of build.java:
basic/— compile, run, argument forwarding, source listing, and clean.cli/— alternate entry points and JVM flags.resource-app/— configuration, resources, assertions, and executable JARs.custom-output/— configured class output path.profile-build/— build profiles and custom JAR manifests.test-options/— test-runner JVM options and arguments.local-jar/— explicit local library JAR and separate compile/runtime classpaths.
See examples/README.md for exact commands and setup steps.
The build recompiles application sources on each build/run and clears the configured class output first, preventing stale classes but not providing incremental compilation. The build tool itself is a single file; task logic and helpers are package-private classes in build.java. External processes are launched using ProcessBuilder argument lists, not shell-concatenated commands.
For the project roadmap, see TODOS.md. The roadmap is exploratory; features should remain explicit, small, and paired with runnable examples.