Gradle version of quickstart-java template

hi all,

our shop does not use Maven i.e. we are totally a Gradle shop, would like to figure out away of creating a Java gradle template, preferably a Groovy quickstart template that uses Gradle as its build mechanism

Maybe Groovy is too much ask :slight_smile: although quite popular but Gradle is practically ubiquitous .

Any hope ?

thanks

-Charles

1 Like

I use this one (stripped down):

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.3.3.RELEASE")
    }
}

plugins {
    id 'org.springframework.boot' version '2.3.3.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
    id 'idea'
}

group 'com.example'
version = '1.0.0'

sourceCompatibility = 11
targetCompatibility = 11

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

def daSdk = '100.13.55'

repositories {
    maven { url "https://digitalassetsdk.bintray.com/DigitalAssetSDK" }
    maven { url "https://repo.maven.apache.org/maven2" }
}

sourceSets.main.resources.includes = [ "**" ]

dependencies {

    implementation 'org.springframework.boot:spring-boot-starter'
    compile('org.springframework.boot:spring-boot-starter-web')
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    compile group: 'com.daml.java', name: 'codegen', version:"${daSdk}"
    compile (group: 'com.daml.ledger', name: 'bindings-rxjava', version:"${daSdk}") {
        exclude(module: 'protobuf-lite')
    }
    implementation 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
}

task dar(type: Exec) {
    commandLine 'daml', 'build'
}

task codegen(type: Exec) {
    commandLine 'daml', 'codegen', 'java'
}
3 Likes

Cool, i take it that’s the current release.
I was sniffing around maven central

also still quite new to this, I also assume the rx-bindings is a ledger api alternative to using a json/http binding.

I’ll note since possibly you can point me in the right direction , is that right now I’m trying to emulate the initial interactive tutorials and instead of using React I would use JavaFX, I believe that ledger api are built into the libs accessible to the React app, so can I achieve the same with the ledger rx-bindings ? or do I have to make json/http calls ?

Anyhow, thanks for the build file, it will definitely get me started.

1 Like

Yes, 100.13.55 is the latest non-snapshot AFAIK for the java bindings AFAIK. Note that this is not the same as the daml SDK version, which is 1.11.1 right now.

The SDK for the ledger API is via Java/scala. For a React app you need to use the JSON API Service: HTTP JSON API Service — Daml SDK 1.11.1 documentation.

1 Like

@perbergman That’s not quite right. The 100.* stuff was only used before SDK 1.0.0. Starting from that, the Java libraries have exactly the same version as the SDK. So the latest version is 1.11.1. You also no longer need Bintray, everything is published to Maven central. I highly recommend switching to a newer version.

The libraries changed name slightly.

  1. com.daml.java:codegen is now com.daml:codegen-java but you shouldn’ t actually need a dependency on that at all. You only need the daml codegen java command which comes from your SDK installation and not from Maven.
  2. com.daml.ledger:bindings-rxjava is now com.daml:bindings-rxjava.
1 Like

Ah, thanks for the clarification. I should definitely update.

“If you have no problems, buy a goat.”

Per

2 Likes

great all, thanks , I will try to setup the build file.
To be clear, not interested in using React for the presentation but rather JavaFX , so therefore I guess all i need in the java ledger api

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.3.3.RELEASE")
    }
}

plugins {
    id 'org.springframework.boot' version '2.3.3.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
    id 'idea'
}

group 'com.example'
version = '1.0.0'

sourceCompatibility = 11
targetCompatibility = 11

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

def daSdk = '1.11.1'

repositories {
    maven { url "https://repo.maven.apache.org/maven2" }
}

sourceSets.main.resources.includes = [ "**" ]

dependencies {

    implementation 'org.springframework.boot:spring-boot-starter'
    compile('org.springframework.boot:spring-boot-starter-web')
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    compile (group: 'com.daml', name: 'bindings-rxjava', version:"${daSdk}") {
        exclude(module: 'protobuf-lite')
    }
    implementation 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
}

task dar(type: Exec) {
    commandLine 'daml', 'build'
}

task codegen(type: Exec) {
    commandLine 'daml', 'codegen', 'java'
}
2 Likes

don’t you just need here mavenCentral () ?

1 Like

Yes, this was my ‘legacy’ build file :slight_smile:

1 Like

so the test-java project specifies a Spark class , and unfortunately I deleted the pom file, doees any one know the appropriate maven central coordinates for this lib ? thanks

1 Like

I"m having a general issue with building from Gradle.

First of all , I understand that one has to run “daml build” to code generate from the daml artifact, but one would hope that the generated code would put in the classpath so that Gradle could see it i.e. that would probably be the case if there was actually a gradle plugin for daml
Anyhow gradle builds fail since it can’t find the daml artifact

1 Like

daml.yaml needs to be set correctly, for example:

codegen:
  java:
    package-prefix: com.example.foo
    output-directory: src/main/java
    verbosity: 2
1 Like

thanks, this is what was included by the template, however running daml build did not generate the folder nor related source files:

codegen:
java:
package-prefix: com.daml.quickstart.model
output-directory: target/generated-sources/iou
decoderClass: com.daml.quickstart.iou.TemplateDecoder

however daml build , will generated the respective quicstart-0.0.1.dar

1 Like

daml build will not generate the daml artifacts, you’ll need to run daml codegen java to do that.

ah, so I think I am just starting this adventure in the wrong place i.e. I found the interactive tutorials, I’m trying to mimic them, I used the project generation skeleton etc.

I’m confused as to where I would go to learn how to do something from scratch i.e. I do plan on emulating the IOU project i.e. use the IOU project daml assets, be able to create a sandbox and then via JavaFX generate a UI that effectively goes thru the same user - system dialogue as the React app, I do need to translate this to Groovy , running on Gradle as the build system but I know how to do that given that I know the coordinates for the various dependencies, I just need to understand the bits of daml to do this

also the generated sources need to be made accessible i.e. put on the classpath , right ?

This quickstart project confuses me , a closer look at it and it seems that all it is i.e. IOUMain.java , what I would probably be doing from JavaFX UI

therefore I think I need a project that is all about setting up the daml artifact and running codegen and daml build, so that I can then spawn the test sandbox

as far as unit testing again if setting up for example Spock I would need the generated source in the class path

with IDEA I know how to do that

it would be great if there was an external tool not tied to VSCode that could visualize the sandboxed ledger

I just did this to force it under the customary classPath for Java projects

codegen:
java:
package-prefix: com.daml.quickstart.model
output-directory: src/main/java/
decoderClass: com.daml.quickstart.iou.TemplateDecoder

1 Like

well I am becoming happier now.

by doing the above I can now mix Groovy and generated daml Java source code which led me to find out that the quickstart tutorial is using deprecated code e.g.

DamlLedgerClient.forHostWithLedgerIdDiscovery()

1 Like

ok, I just found about Navigator which of course is not tied up to VSCode, so even happier

1 Like