2017-11-16 15:31:52 +00:00
|
|
|
Building a CorDapp
|
|
|
|
==================
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
.. contents::
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
Cordapps run on the Corda platform and integrate with it and each other. This article explains how to build CorDapps.
|
|
|
|
To learn what a CorDapp is, please read :doc:`cordapp-overview`.
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
CorDapp format
|
|
|
|
--------------
|
|
|
|
A CorDapp is a semi-fat JAR that contains all of the CorDapp's dependencies *except* the Corda core libraries and any
|
|
|
|
other CorDapps it depends on.
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
For example, if a Cordapp depends on ``corda-core``, ``your-other-cordapp`` and ``apache-commons``, then the Cordapp
|
|
|
|
JAR will contain:
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
* All classes and resources from the ``apache-commons`` JAR and its dependencies
|
|
|
|
* *Nothing* from the other two JARs
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
Build tools
|
|
|
|
-----------
|
|
|
|
In the instructions that follow, we assume you are using ``gradle`` and the ``cordformation`` plugin to build your
|
|
|
|
CorDapp. See the `example build file <https://github.com/corda/cordapp-template-kotlin/blob/release-V1/build.gradle>`_
|
|
|
|
from the CorDapp template.
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
Setting your dependencies
|
|
|
|
-------------------------
|
2017-07-25 16:54:36 +00:00
|
|
|
|
|
|
|
Choosing your Corda version
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
The following two lines of the ``build.gradle`` file define the Corda version used to build your CorDapp:
|
|
|
|
|
|
|
|
.. sourcecode:: groovy
|
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
ext.corda_release_version = '1.0.0'
|
|
|
|
ext.corda_gradle_plugins_version = '1.0.0'
|
|
|
|
|
|
|
|
In this case, our CorDapp will use:
|
|
|
|
|
|
|
|
* Version 1.0 of Corda
|
|
|
|
* Version 1.0 of the Corda gradle plugins
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
You can find the latest published version of both here: https://bintray.com/r3/corda.
|
2017-07-25 16:54:36 +00:00
|
|
|
|
|
|
|
``corda_gradle_plugins_versions`` are given in the form ``major.minor.patch``. You should use the same ``major`` and
|
|
|
|
``minor`` versions as the Corda version you are using, and the latest ``patch`` version. A list of all the available
|
2017-10-09 19:08:08 +00:00
|
|
|
versions can be found here: https://bintray.com/r3/corda/cordapp.
|
2017-07-25 16:54:36 +00:00
|
|
|
|
|
|
|
In certain cases, you may also wish to build against the unstable Master branch. See :doc:`building-against-master`.
|
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
Corda dependencies
|
|
|
|
^^^^^^^^^^^^^^^^^^
|
|
|
|
The ``cordformation`` plugin adds:
|
|
|
|
|
|
|
|
* ``cordaCompile`` as a new configuration that ``compile`` extends from
|
|
|
|
* ``cordaRuntime`` which ``runtime`` extends from
|
|
|
|
|
|
|
|
To build against Corda you must add the following to your ``build.gradle`` file;
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
* The ``net.corda:corda:<version>`` JAR as a ``cordaRuntime`` dependency
|
|
|
|
* Each compile dependency (eg ``corda-core``) as a ``cordaCompile`` dependency
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
To use Corda's test facilities you must add ``net.corda:corda-test-utils:<version>`` as a ``testCompile`` dependency
|
|
|
|
(i.e. a default Java/Kotlin test compile task).
|
2017-07-25 16:54:36 +00:00
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
.. warning:: Never include ``corda-test-utils`` as a ``compile`` or ``cordaCompile`` dependency.
|
|
|
|
|
|
|
|
Dependencies on other CorDapps
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
Sometimes, a CorDapp you build will depend on states, contracts or flows defined in another CorDapp. You must include
|
|
|
|
the CorDapp your CorDapp depends upon as a ``cordapp`` dependency in your ``build.gradle`` file.
|
|
|
|
|
|
|
|
Other dependencies
|
|
|
|
^^^^^^^^^^^^^^^^^^
|
2017-07-25 16:54:36 +00:00
|
|
|
If your CorDapps have any additional external dependencies, they can be specified like normal Kotlin/Java dependencies
|
|
|
|
in Gradle. See the example below, specifically the ``apache-commons`` include.
|
|
|
|
|
|
|
|
For further information about managing dependencies, see
|
|
|
|
`the Gradle docs <https://docs.gradle.org/current/userguide/dependency_management.html>`_.
|
|
|
|
|
|
|
|
Example
|
2017-11-16 15:31:52 +00:00
|
|
|
^^^^^^^
|
|
|
|
The following is a sample of what a gradle dependencies block for a CorDapp could look like. The CorDapp template
|
2017-07-25 16:54:36 +00:00
|
|
|
is already correctly configured and this is for reference only;
|
|
|
|
|
|
|
|
.. container:: codeset
|
|
|
|
|
|
|
|
.. sourcecode:: groovy
|
|
|
|
|
|
|
|
dependencies {
|
|
|
|
// Corda integration dependencies
|
2017-07-27 16:53:51 +00:00
|
|
|
cordaCompile "net.corda:corda-core:$corda_release_version"
|
|
|
|
cordaCompile "net.corda:corda-finance:$corda_release_version"
|
|
|
|
cordaCompile "net.corda:corda-jackson:$corda_release_version"
|
|
|
|
cordaCompile "net.corda:corda-rpc:$corda_release_version"
|
|
|
|
cordaCompile "net.corda:corda-node-api:$corda_release_version"
|
|
|
|
cordaCompile "net.corda:corda-webserver-impl:$corda_release_version"
|
2017-07-25 16:54:36 +00:00
|
|
|
cordaRuntime "net.corda:corda:$corda_release_version"
|
|
|
|
cordaRuntime "net.corda:corda-webserver:$corda_release_version"
|
|
|
|
testCompile "net.corda:corda-test-utils:$corda_release_version"
|
|
|
|
|
|
|
|
// Corda Plugins: dependent flows and services
|
2017-11-16 15:31:52 +00:00
|
|
|
// Identifying a CorDapp by its module in the same project.
|
|
|
|
cordapp project(":cordapp-contracts-states")
|
|
|
|
// Identifying a CorDapp by its fully-qualified name.
|
2017-07-25 16:54:36 +00:00
|
|
|
cordapp "net.corda:bank-of-corda-demo:1.0"
|
|
|
|
|
|
|
|
// Some other dependencies
|
|
|
|
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
|
|
|
|
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
|
|
|
|
testCompile "junit:junit:$junit_version"
|
|
|
|
|
|
|
|
compile "org.apache.commons:commons-lang3:3.6"
|
|
|
|
}
|
|
|
|
|
2017-11-16 15:31:52 +00:00
|
|
|
Creating the CorDapp JAR
|
|
|
|
------------------------
|
|
|
|
The gradle ``jar`` task included in the CorDapp template build file will automatically build your CorDapp JAR correctly
|
|
|
|
as long as your dependencies are set correctly.
|
|
|
|
|
2017-11-29 17:07:13 +00:00
|
|
|
.. warning:: The hash of the generated CorDapp JAR is not deterministic, as it depends on variables such as the
|
|
|
|
timestamp at creation. Nodes running the same CorDapp must therefore ensure they are using the exact same CorDapp
|
|
|
|
jar, and not different versions of the JAR created from identical sources.
|
2017-11-16 15:31:52 +00:00
|
|
|
|
|
|
|
The filename of the JAR must include a unique identifier to deduplicate it from other releases of the same CorDapp.
|
|
|
|
This is typically done by appending the version string to the CorDapp's name. This unique identifier should not change
|
|
|
|
once the JAR has been deployed on a node. If it does, make sure no one is relying on ``FlowContext.appName`` in their
|
|
|
|
flows (see :doc:`versioning`).
|
|
|
|
|
|
|
|
Installing the CorDapp jar
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
.. note:: Before installing a CorDapp, you must create one or more nodes to install it on. For instructions, please see
|
2017-11-29 17:07:13 +00:00
|
|
|
:doc:`generating-a-node`.
|
2017-11-16 15:31:52 +00:00
|
|
|
|
|
|
|
At runtime, nodes will load any CorDapps present in their ``cordapps`` folder. Therefore in order to install a CorDapp on
|
|
|
|
a node, the CorDapp JAR must be added to the ``<node_dir>/cordapps/`` folder, where ``node_dir`` is the folder in which
|
|
|
|
the node's JAR and configuration files are stored.
|
|
|
|
|
|
|
|
The ``deployNodes`` gradle task, if correctly configured, will automatically place your CorDapp JAR as well as any
|
|
|
|
dependent CorDapp JARs specified into the ``cordapps`` folder automatically.
|