Spring boot with Angular4


(Kishore Kumar Krishnamurthy) #1

Hi Guys,
I created my project with below hierarchy

Parent
a. Backend (Java, Spring boot)
b. Frontend (Angular4 with CLI)

I need to write a parent gradle task where first it should run frontend task like ng build then backend.

I am new to gradle, any help much appreciated.

Thanks,
Kris


(Jean-Baptiste Nizet) #2

We’re doing exactly that by having a multi-project build, with two subprojects, backend and frontend.

In the frontend, we apply the base plugin and the com.moowork.node plugin. Running an ng build simply consists in adding "build": "ng build --prod" in the scripts section of the package.json file, and using

npm_run_build {
  dependsOn 'yarn_install'
  inputs.dir 'src'
  outputs.dir 'dist'
}

in the frontend gradle build.

In the backend gradle build, we use the spring-boot-gradle-plugin, and simply customize the jar task so that it includes the files generated by the frontend build:

jar {
    dependsOn ':frontend:npm_run_build'
    
    into('static') {
        from "${project(':frontend').projectDir}/dist"
    }
}

Hope it helps.


(Kishore Kumar Krishnamurthy) #3

Thank you for the solution. One change i made it, instead of yarn_install, i am saying npm_install


(Bandham Manikanta) #4

Hi,

Same Configuration I’m doing now, front end angular 5 and backend is springboot java application.

@jnizet, Here, I have the configuration you have mentioned. and I’m trying to build a single war file with both front and backend together, that war file I have to deploy it to external tomcat.

Please guide me to achieve the same.

thanks in advance.

Happy coding.


(Bandham Manikanta) #5

Hi @KrisMuree,

Hope you achieve the proper solution.
Could you please share me the configuration (as it is.) may be through github.

Thank you in advance. :slight_smile:

Happy coding.