Skip to content
Discussions/App Development/How can I import the generated Java classes from the Daml model into a Scala/sbt project?Forum ↗

How can I import the generated Java classes from the Daml model into a Scala/sbt project?

App Development4 posts435 views1 likesLast activity Apr 2023
GY
gyorgybalazsiOP
Apr 2023

My understanding of the sbt manual is that the steps are the following:

  1. generate the Java classes
  2. create a jar with the jar command
  3. create a lib folder in the Scala project root and place the jar into this folder
  4. refresh the project
  5. import the Java classes into the Scala files like this: import com.daml.sor.workflow.workflow.Product

I’m using IntelliJ IDEA.

I’ve done the steps above and get the error value daml is not a member of com.

What am I doing wrong?

ST
stefanobaghino-da
Apr 2023

If you didn’t fiddle with your unmanaged dependencies settings, sbt should indeed look for them in the lib directory. If you have a multi-module setup, you might want to check whether this is based on the root of the individual module rather than the root of the whole project.

Alternatively, you might want to consider the idea of generating the source files and putting them in a place where they can be picked up by sbt to make them available when you’re compiling the whole project (this is what happens with ScalaPB for Protobuf/gRPC for example, with the generated code going in the target directory alongside other build artifacts).

GY
gyorgybalazsi
Apr 2023

So far none of these seem to work, probably because I am doing something fundamentally wrong, continue the experimentation.

GY
gyorgybalazsi
Apr 2023

Thank you for the hints, these are the two lines I needed to add to build.stb for the generated files and the Java binding to be included:

Compile / unmanagedSourceDirectories += baseDirectory.value / "scala-test" / "generated-files"

libraryDependencies += "com.daml" % "bindings-rxjava" % "2.6.1"

I hope this is the beginning of a beautiful friendship between me and Scala.

← Back to Discussions