Gradle Multi-Project Build - How to handle local npm project dependencies

889 Views Asked by At

The project is building an Angular application.

I need the App build to use the result of another local project which is a javascript library.

Gradle is used to build both projects with the help of com.github.node-gradle.node node plugin.

The Project structure is simple

root
- Project App
- Project Library

Where App depends on the output of Library.

To be more precise the App need the output of "npm pack" on project Library.

In the App project i'm declaring a local npm dependency to the library project which is the result of the npm pack. ( .tgz file)

 "dependencies": {
    "library": "file:../library/build/library-0.0.1.tgz"
 }

How can i declare the result of the library project as build output and declare it as a dependency input for the App project ?

Using the java-library plugin it will be something like this :

dependencies {
  api(project(":library"))
}

The goal is that gradle will first build the Library project before the App project. It's even better if he can check if the library source code have changed or not to trigger a build on it or not when asking for a build of App.

Build on both project is done like this :

  tasks{
    register<com.moowork.gradle.node.npm.NpmTask>("build") {
        dependsOn("npmInstall")
        setArgs(setOf("run-script", "build"))
    }
}

And the build script for the library project in package.json is

  "scripts": {
     "build": "ng-packagr -p ng-package.json && cd ./build && npm pack ../dist"
  }

I have seen lot of documentation on how to do it whith the java plugin but i didn't find any good exemples for non java projects.

Any help will be appreciated, using kotlin dsl will be even better :-)

0

There are 0 best solutions below