1.2.2. Setting up a plugin project

This section describes how to prepare a project for writing user-defined procedures and functions in Neo4j.

The example described in this section is available as a repository on GitHub. To get started quickly you can fork the repository and work with the code as you follow along in the guide below.

The following example shows the steps to create and deploy a new procedure:

  1. Set up a project with Maven.

    A project can be set up in any way that allows for compiling a procedure and producing a jar file. Below is an example configuration using the Maven build system. For readability, only excerpts from the Maven pom.xml file are shown here, the whole file is available from the Neo4j Procedure Template repository.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     <name>Neo4j Procedure Template</name>
     <description>A template project for building a Neo4j Procedure</description>
  2. Define build dependencies.

    1. Add a dependency section that includes the procedure and function APIs, which procedures and functions use at runtime.

      The scope is set to provided, because once the procedure is deployed to a Neo4j instance, this dependency is provided by Neo4j. If non-Neo4j dependencies are added to the project, their scope should normally be compile.

    2. Add dependencies that are necessary for testing the procedure.

      • Neo4j Harness, a utility that allows for starting a lightweight Neo4j instance. It is used to start Neo4j with a specific procedure or function deployed, which greatly simplifies testing.
      • The Neo4j Java driver, used to send Cypher statements that call the procedure or function.
      • JUnit, a common Java test framework.

  3. Define the steps that Maven will go through to build the project.

    The goal is first to compile the source, then to package it in a jar that can be deployed to a Neo4j instance.

    + The Maven Shade plugin is used to package the compiled procedure. It also includes all dependencies in the package, unless the dependency scope is set to test or provided.

    + Once the procedure has been deployed to the plugins directory of each Neo4j instance and the instances have restarted, the procedure is available for use.