Skip to content

ProjectSetup

Christian Schlichtherle edited this page Feb 6, 2019 · 12 revisions

Project Setup

To setup a project for using Neuron DI, it's generally required to add a single dependency to the project. If your project is using Scala, it's also required to add the Macro Paradise plugin to the Scala compiler. If your project is using SBT, both can be easily done by applying the Neuron DI SBT Plugin to your project.

Project Setup With SBT

Assuming Neuron DI 6.0.1 is still the latest release, add the following line to project/plugins.sbt:

addSbtPlugin("global.namespace.neuron-di" % "neuron-di-sbt-plugin" % "6.0.1")

Next, in build.sbt, you need to add one of the following plugins to your project, depending on the application environment and programming language:

Java Scala
Standalone NeuronDIForJavaPlugin NeuronDIForScalaPlugin
Guice NeuronDIAtGuiceForJavaPlugin NeuronDIAtGuiceForScalaPlugin
Play TODO NeuronDIAtGuiceForScalaPlugin*

* There is no specific plugin for Play.

For example, to use Neuron DI in an application using Play For Scala with Guice, your build.sbt file should contain the following line:

lazy val root = (project in file(".")).enablePlugins(PlayScala, NeuronDIAtGuiceForScalaPlugin)

Note that this project definition enables two plugins, PlayForScala and NeuronDIAtGuiceForScalaPlugin. The latter plugin modifies the project definition as follows:

  1. It adds a dependency on Neuron DI @ Guice For Scala 6.0.1 and its transitive dependency Guice 4.1.0.
  2. It adds the Macro Paradise plugin to the Scala compiler.

Project Setup Without SBT

If your project is not built using SBT, you need to set it up manually. The following assumes that your project is built using Maven.

Adding A Dependeny On Neuron DI

Depending on your application environment and programming language, you need to add one of the following dependencies to your build, identified as Maven coordinates:

Java Scala
Standalone global.namespace.neuron-di:neuron-di:6.0.1 2.11: global.namespace.neuron-di:neuron-di-scala_2.11:6.0.1
2.12: global.namespace.neuron-di:neuron-di-scala_2.12:6.0.1
Guice global.namespace.neuron-di:neuron-di-guice:6.0.1 2.11: global.namespace.neuron-di:neuron-di-guice-scala_2.11:6.0.1
2.12: global.namespace.neuron-di:neuron-di-guice-scala_2.12:6.0.1

For example, to use Neuron DI in a Java application using Guice, your pom.xml file should contain the following XML element in the element with the path /project/dependencies:

<dependency>
    <groupId>global.namespace.neuron-di</groupId>
    <artifactId>neuron-di-guice</artifactId>
    <version>6.0.1</version>
</dependency>

This adds a dependency on Neuron DI @ Guice For Scala 6.0.1 and its transitive dependency Guice 4.1.0.

Adding The Macro Paradise Plugin

If your project is using Scala, you also need to add the Macro Paradise plugin to the Scala compiler or otherwise it would not understand the @Neuron and @Caching annotations in the Scala API of Neuron DI. Note that the plugin is solely required for compiling your Scala source code: It's not a runtime dependency of the compiled byte code!

Follow the instructions on this page to add the plugin to the Scala compiler.

Clone this wiki locally