javanode.jsnx-monorepo

NX Release process for Node.js and Java applications


I am using nx monorepo from https://nx.dev/

My project consists of:

So far, I can successfully build my entire project (both backend and frontend like this)

nx run-many -t install

Now, I want to make a release - but the release process fails

nx release patch --dry-run --first-release

relevant part of nx.json:

  "release": {
    "projects": ["apps/**"]
  },

Result: release fails on the Java app


 NX   The project "my-java-service" does not have a package.json
      available at apps\java\my-java-service\package.json.

To fix this you will either need to add a package.json file at that location, or configure
"release" within your nx.json to exclude "my-java-service" from the current release group,
or amend the packageRoot configuration to point to where the package.json should be.

It seems the release process works fine for my frontend apps, but it is expecting my Java app to have a package.json. Obviously, my Java apps do not have package.json (they have a pom.xml)

How can I configure nx release to work with my Java apps?

It's so nice to have apps\node and apps\java in the same monorepo. I'd rather build and release them all together from same monorepo (if possible).


Solution

  • "release": { "projects": ["apps/**"] }, In here, you should excluse java part. Which means you could do :

    { "release": { "projects": ["apps/node/**"] } }

    However to release, you should probably make steps, you could use nx to release node part, and use maven for java. (Since you mentioned pom.xml)

    For maven, there is something like nx-maven : https://github.com/khalilou88/jnxplus/tree/main/packages/nx-maven https://dev.to/gridou/smooth-maven-project-onboarding-ehf

    But i would combine both.

    A custom release script would something like :

    #!/bin/bash
    
    # Release Node.js projects
    nx release patch --dry-run --first-release
    
    # Release Java projects
    cd apps/java/my-java-service
    mvn release:prepare
    mvn release:perform