Multi module project with gradle

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

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.

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.

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.

One possibility there is to use git’s submodules which would enable you to have multiple repositories and then a master repository that handles building and deployment.

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.

1 Like

Anyway, I will look into submodules.

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

1 Like

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

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

2 Likes

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.

1 Like

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.

1 Like

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

1 Like

gradle snippet:

    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
            }
        }
    }
1 Like

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'
}
1 Like