将一个cordapp作为corda jar依赖项添加到其他corda项目

时间:2018-10-30 17:35:24

标签: corda

添加了一个cordApp作为其他corda项目中的依赖项。我想将其jar作为一个Corda项目对其他项目的依赖项包括在内。

这是具有以下依赖顺序的项目结构:

  1. 合同国
  2. flownormal
  3. flowobserver
  4. api

enter image description here

我已经尝试将其添加为deployNodes cordapps中的依赖项,如下所示:

task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
    directory "./build/nodes"
    node {
        name "O=Notary,L=London,C=GB"
        notary = [validating : false]
        p2pPort 10006
        cordapps = ["$corda_release_distribution:corda-finance:$corda_release_version", ":contractstate", ":flowobserver", project(":flownormal")]
    }
    node {
        name "O=PartyA,L=London,C=GB,CN=PartyA"
        p2pPort 10007
        rpcSettings {
            address("localhost:10008")
            adminAddress("localhost:10048")
        }
        webPort 10009
        cordapps = ["$corda_release_distribution:corda-finance:$corda_release_version", ":contractstate", ":flowobserver", ":flownormal"]
        rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
    node {
        name "O=PartyB,L=New York,C=US,CN=PartyB"
        p2pPort 10010
        rpcSettings {
            address("localhost:10011")
            adminAddress("localhost:10051")
        }
        webPort 10012
        cordapps = ["$corda_release_distribution:corda-finance:$corda_release_version", ":contractstate", ":flowobserver", ":flownormal"]
        rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
    node {
        name "O=PartyC,L=Paris,C=FR,CN=PartyC"
        p2pPort 10013
        rpcSettings {
            address("localhost:10014")
            adminAddress("localhost:10054")
        }
        webPort 10015
        cordapps = ["$corda_release_distribution:corda-finance:$corda_release_version", ":contractstate", ":flowobserver"]
        rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
    }
}

运行tsk后,检查每个节点内部的cordapps会生成单个jar:

enter image description here

Cordapp还必须包括其他相关的Corda项目jar ...为了做到这一点,需要做些什么?

需要添加其他corda项目jar作为依赖项,与金融jar相同。

1 个答案:

答案 0 :(得分:1)

从Corda 3开始,您需要使用以下语法在deployNodes cordapps块中包含CorDapps:

cordapps = [
    "net.corda.examples.oracle:base:$version", 
    "net.corda.examples.oracle:client:$version"
]

您还需要在build.gradle文件的dependencies块中将CorDapps设置为依赖项。您可以使用:

  • cordapp project(":another-cordapp")

    • 如果另一个CorDapp是在同一项目的模块中定义的,请使用此
  • cordapp "net.corda:another-cordapp:1.0"

    • 否则使用此

如果您要使用的是CorDapp,则取决于在另一个存储库中定义的位置(在这里不是这种情况),则必须将CorDapp JAR放置在build.gradle文件的{{ 1}}块。例如,您可以将CorDapp JAR放置在项目中的repositories文件夹中,然后将以下内容添加到libs块中:

repositories