Skip to content

Commit 982ead0

Browse files
added a guide on working integrating morphir with the jvm
1 parent a105c6b commit 982ead0

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
2+
# JVM: Executing morphir-cli
3+
4+
This document specifies all the necessary steps required to execute morphir-cli commands in a JVM project.
5+
6+
## Introduction
7+
8+
When using morphir generated code in a JVM project, it is sometimes the case that you need to execute morphir commands as part of your build process. While there are many ways to achieve this, we'll talk about the preferred way.
9+
10+
> The morphir cli is written in TypeScript and executes in a node environment, which means that node must be installed to run any morphir-cli command.
11+
12+
13+
## Execute npm scripts.
14+
15+
One of the ways, which is also the preferred way, you can achieve this is to setup *npm build scripts* in your morphir project that can be executed by as part of the your project build.
16+
17+
There are a few benefits of this approach:
18+
- Using npm build scripts ensures that the morphir version specified for the morphir project is used for compiling the *morphir IR*.
19+
- It also helps to reduce additional scripting code that would have been written if done in your project's build tool
20+
21+
> **_Note!_**
22+
> This is not a requirement for using Morphir, or using morphir-cli commands in a JVM project.
23+
24+
### Specifying npm scripts
25+
26+
Every node project must include a [package.json](https://docs.npmjs.com/cli/v9/configuring-npm/package-json) file which can contain a [scripts section](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#scripts) and defines the available [npm](https://docs.npmjs.com/about-npm) scripts for that node project.
27+
28+
*Example*
29+
```JSON
30+
{
31+
"name": "my-package",
32+
"version": "1.0",
33+
"scripts": {
34+
"make": "morphir make -f",
35+
"generate": "morphir scala-gen -o ./generated/src",
36+
"build": "npm run make && npm run generate"
37+
}
38+
}
39+
```
40+
41+
This is a simple `package.json` file that defines three scripts:
42+
- `make` - that can be run using `npm run make` and
43+
- `generate` - that can be run using `npm run generate`.
44+
- `build` - that can be run using `npm run build`.
45+
46+
## Examples
47+
48+
Here are a few examples with your favorite build tools that show execution of npm scripts.
49+
50+
### Maven Example
51+
52+
If you're using maven as your build tool for build tool, you can use [MojoHaus](https://www.mojohaus.org/) plugin to run executables.
53+
```xml
54+
<?xml version="1.0" encoding="UTF-8"?>
55+
<project xmlns="http://maven.apache.org/POM/4.0.0"
56+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
57+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
58+
<modelVersion>4.0.0</modelVersion>
59+
60+
<!-- other project configurations -->
61+
62+
<build>
63+
<plugins>
64+
<!-- you can specify other-plugins -->
65+
66+
<!-- using MojoHaus to run npm script -->
67+
<plugin>
68+
<groupId>org.codehaus.mojo</groupId>
69+
<artifactId>exec-maven-plugin</artifactId>
70+
<version>3.1.0</version>
71+
<execution>
72+
<id>morphir-build</id>
73+
<phase>generate-sources</phase>
74+
<goals>
75+
<goal>exec</goal>
76+
</goals>
77+
<configuration>
78+
<!-- we want to invoke npm executable -->
79+
<executable>npm</executable>
80+
<!-- specify the directory of the morphir project -->
81+
<workingDirectory>${project.basedir}</workingDirectory>
82+
<!-- running our build script defined in out package.json -->
83+
<arguments>
84+
<argument>run</argument>
85+
<argument>build</argument>
86+
</arguments>
87+
</configuration>
88+
</execution>
89+
</plugin>
90+
91+
<!-- maybe some more plugins -->
92+
</plugins>
93+
94+
<!-- maybe some more project configurations -->
95+
</build>
96+
</project>
97+
```

0 commit comments

Comments
 (0)