# Multi module project with gradle

**URL:** <https://forum.canton.network/t/multi-module-project-with-gradle/288>\
**Category:** App Development\
**Tags:** daml\
**Created:** [April 28, 2020, 5:59pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288 "2020-04-28T17:59:44Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![perbergman](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/perbergman/32/1804_2.png) [@perbergman](https://forum.canton.network/u/perbergman)\
**Post date:** [April 28, 2020, 5:59pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/1 "2020-04-28T17:59:44Z")

</div>

How can I separate the DAML files from multiple projects depending on them?

I.e.

1. DAML files project.
2. Front end npm/nodejs project depending on 1).
3. Back end java/gradle project depending on 1).

Thanks,  
Per

---

<div class="post-metadata">

**Author:** ![anthony](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/anthony/32/419_2.png) [@anthony](https://forum.canton.network/u/anthony)\
**Post date:** [April 28, 2020, 6:21pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/2 "2020-04-28T18:21:03Z")

</div>

The way I like to do it is to have my daml code in the root project directory and then supporting sections (like `/ui`) in their own folder. This is also what’s done with create-daml-app for example.

You can also take a look at reference apps like ex-inventory-management which puts a `daml` folder beside their `java` backend code.

> **[digital-asset/ex-inventory-management](https://github.com/digital-asset/ex-inventory-management/tree/master/src/main)**
>
> Crypto Inventory Management System has been designed to make it easy and safe for crypto funds to manage their crypto assets on public ledgers. - digital-asset/ex-inventory-management

Ultimately it’s up to you but a common thread is that `/daml`, `/ui`, and `/java` code folders are all beside each other in most projects.

---

<div class="post-metadata">

**Author:** ![perbergman](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/perbergman/32/1804_2.png) [@perbergman](https://forum.canton.network/u/perbergman)\
**Post date:** [April 28, 2020, 6:24pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/3 "2020-04-28T18:24:23Z")

</div>

Yes, but I want multiple dependent projects. One for DAML, one for frontend, and one for backend. The build and deploy system would detect changes and do the right thing.

---

<div class="post-metadata">

**Author:** ![anthony](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/anthony/32/419_2.png) [@anthony](https://forum.canton.network/u/anthony)\
**Post date:** [April 28, 2020, 6:27pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/4 "2020-04-28T18:27:20Z")

</div>

One possibility there is to use [git’s submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) which would enable you to have multiple repositories and then a master repository that handles building and deployment.

---

<div class="post-metadata">

**Author:** ![perbergman](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/perbergman/32/1804_2.png) [@perbergman](https://forum.canton.network/u/perbergman)\
**Post date:** [April 28, 2020, 6:30pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/5 "2020-04-28T18:30:59Z")

</div>

Yes, understood. But I mean really independent, which is quite common IMHO.

For example, say you have protobuf definitions in one project, N different frontend teams working of those, as well as M backend teams at the same time.  
You might not want to use git submodules for that, too coupled.

---

<div class="post-metadata">

**Author:** ![perbergman](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/perbergman/32/1804_2.png) [@perbergman](https://forum.canton.network/u/perbergman)\
**Post date:** [April 28, 2020, 6:35pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/6 "2020-04-28T18:35:55Z")

</div>

Anyway, I will look into submodules.

[submodule “daml”]  
path = daml  
url = [git@github.com](mailto:git@github.com):perbergman/daml.git

---

<div class="post-metadata">

**Author:** ![daniel](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/daniel/32/80_2.png) [@daniel](https://forum.canton.network/u/daniel)\
**Post date:** [April 28, 2020, 9:23pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/7 "2020-04-28T21:23:40Z")

</div>

@perbergman  
If you were looking for a gradle project structure, here is an idea (sample settings.gradle.kts)

```haskell
rootProject.name = "Sample"

include("daml-model")
include("daml-codegen-js")
include("daml-codegen-java")
include("front")
include("back")

```

Under each subfolder, you will have a build.gradle[.kts] to define the build tasks

1. daml-model  
daml source goes here  
e.g.  
`daml damlc ....`

2. daml-codegen-js  
daml codegen javascript source here  
e.g.  
`npm build ...`

3. daml-codegen-java  
daml codegen java source here  
e.g.  
`gradle assemble`

4. front  
you UI frontend source here  
This will depends on the modules from #2  
e.g.  
`npm build ...`

5. back  
This will depends on the modules from #3  
you Java backend source here  
e.g.  
`gradle assemble`

---

<div class="post-metadata">

**Author:** ![perbergman](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/perbergman/32/1804_2.png) [@perbergman](https://forum.canton.network/u/perbergman)\
**Post date:** [April 28, 2020, 9:55pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/8 "2020-04-28T21:55:15Z")

</div>

Yes, combining this with submodules might work.  
I am after a multi-developer setup with isolation of code, build and deploy. So lots of small repos, not a big one with all in.

---

<div class="post-metadata">

**Author:** ![Gary\_Verhaegen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/gary_verhaegen/32/81_2.png) [@Gary\_Verhaegen](https://forum.canton.network/u/Gary_Verhaegen)\
**Post date:** [April 29, 2020, 1:23pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/9 "2020-04-29T13:23:17Z")

</div>

My personal recommendation re: submodules is to just pretend they don’t exist. I’ve never seen them bring about anything but pain.

If you want multiple, independent projects, I believe you’ll be better off depending on released artifacts from other projects than from trying to tie together their source code. In the case of the DAML project, just have your build system export the corresponding dar file, and other projects can depend on that.

If you really do need source-level integration, I would still recommend a `git clone` ran by the build system over submodules for almost any situation.

---

<div class="post-metadata">

**Author:** ![perbergman](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/perbergman/32/1804_2.png) [@perbergman](https://forum.canton.network/u/perbergman)\
**Post date:** [April 29, 2020, 1:33pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/10 "2020-04-29T13:33:48Z")

</div>

Yes, I agree. Maybe put the DAR in Nexus?

---

<div class="post-metadata">

**Author:** ![perbergman](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/perbergman/32/1804_2.png) [@perbergman](https://forum.canton.network/u/perbergman)\
**Post date:** [April 29, 2020, 4:23pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/11 "2020-04-29T16:23:08Z")

</div>

gradle snippet:

```haskell
    def darFile = file(".daml/dist/iou-1.0.0.dar")
    def darArtifact = artifacts.add('archives', darFile) {
    type 'dar'
    builtBy 'dar'
    }
     
    task dar(type: Exec) {
        commandLine '/usr/local/bin/daml', 'build'
    }
    
    publishing {
        publications {
            maven(MavenPublication) {
                artifact darArtifact
            }
        }
    }

```

---

<div class="post-metadata">

**Author:** ![perbergman](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/perbergman/32/1804_2.png) [@perbergman](https://forum.canton.network/u/perbergman)\
**Post date:** [April 29, 2020, 5:40pm UTC](https://forum.canton.network/t/multi-module-project-with-gradle/288/12 "2020-04-29T17:40:36Z")

</div>

and to use:

```
configurations {
    damlDep
}

dependencies {
    damlDep 'damlsrc:damlsrc:1.0.0'
}

task copyDependencies(type: Copy) {
    from configurations.damlDep
    into '.daml/dist'
}

task codegen(type: Exec) {
    commandLine '/usr/local/bin/daml', 'codegen', 'java'
}
```
