Nake

A simplified Make for Java 8 Nashorn

View the Project on GitHub winterbe/nake

Nake

Nake is a simplified version of Make (Cake, Jake, Rake) for the Java 8 Nashorn Javascript Engine.

You define tasks in a project specific nakefile.js and call them from the command line. Tasks are written in Javascript and run natively on the JVM by utilizing Nashorns jjs -scripting command. This enables you to utilize everything from the JDK 8 API or any external Java libraries.

Usage

Running nake with no arguments prints all tasks in the current directory's Nakefile.

Use nake -- taskName [options] to run a specific task from your Nakefile.

Installation

Use the following steps to install Nake on POSIX systems (Mac OSX, Linux):

$ cd /usr/bin
$ ln -s $JAVA_HOME/bin/jjs jjs
$ cd /usr/bin
$ ln -s /path/to/nake/src/nake.js nake

Nake also runs on Windows: Set PATH to nake.js directory; then run Nake with jjs -scripting nake.js -- taskName.

Getting started

Create a file called nakefile.js in your projects root directory with the following content:

task('hello', 'Hello World', function() {
  print('Hello World!');
};

Open the terminal, cd into any project directory and type nake -- hello.

Next, check out the API Documentation and example tasks. You should also consider reading my Nashorn Tutorial to get started with the Nashorn engine.

Examples

The java example found in test/java contains a sample java application with some basic java-related nake tasks:

Run the java application:

Invokes the java main method. Nake arguments will be passed to java.

task("run", "Run java application", function(options) {
  shell()
    .dir("out")
    .exec("java com/winterbe/nake/java/Main ${options[0]}")
    .print();
});

Run the task from your terminal:

nake -- run [arg]

Compile all java files:

Compiles all java files from src to out.

task("compile", "Compile all java files", function() {
  shell()
    .exec("find src -name *.java")
    .apply(function(result) {
      return java.lang.String.join(" ", result.split("\n"));
    })
    .stash("files")
    .print("compiling java files...")
    .exec("mkdir -p out")
    .exec("javac -d out {{files}}")
    .print("done");
});

Run the task from your terminal:

nake -- compile

Keep in mind that you can run nake tasks from any subfolder of your project. Read the API Documentation for a detailed description.

Contribute

Your Feedback is highly appreciated. Feel free to file an issue or ping me on Twitter or Google+.