Search code examples
angularspring-bootgradlebuildwatch

spring bootRun and Angular buildWatch using Gradle


I want to use angular 4 as client side framework in a spring boot multi module application. My application contains 3 modules

  1. domain module
  2. service module
  3. web module (a spring boot module)

the angular 4 root directory is within the web module.

I can launch bootRun to execute application with "ng build" command (which compile angular typescript file and copy result file in springBoot static resources directory) This work thine (In passing, thanks to Umesh Morsu for your excellent tutorial https://www.youtube.com/watch?v=nHRA7cbL0vk).

Bellow the gradle script I use to do that :

task buildClientDev(type: NpmTask, dependsOn: 'npmInstall') {
            group = 'build'
            description = 'Compile client side folder for development'
            args = ['run','buildDev']
        }


task buildClientWatch(type: NpmTask, dependsOn: 'npmInstall'){
            group = 'application'
            description = "Build and watches the client side assets for rebuilding"
            args = ['run','buildWatch']
}

bootRun{
    doFirst {
        tasks.buildClientDev.execute()
    }
}

The problem with doing so is I have to re-run bootRun when I modify a TypeScript file (to generate js file). I want this generation to be done automatically. So I'd like to call tasks.buildClientWatch.execute() which execute a "ng build watch=true". but when I do that springBoot Application can't start. When I use doLast instead of doFirst my Springboot app start well but the gradle call in doLast is neither executed.

So how can run both springBoot bootRun command and do ng build watch=true at same time?


Solution

  • after 3 years developping applications with angular I think the best thing to do in this situation is to totaly separate front from backend.

    So I can create an npm or gradle project for my angular frontend app. And for the backend I can create microservices and module as I like. I think this is the best pattern nowaday.