Skip to content

Instantly share code, notes, and snippets.

@jsrois
Created March 7, 2022 09:10
Show Gist options
  • Save jsrois/519421cf1d780bcaf107ffa0d8c0ba69 to your computer and use it in GitHub Desktop.
Save jsrois/519421cf1d780bcaf107ffa0d8c0ba69 to your computer and use it in GitHub Desktop.
How to create frontend+backend project with gradle

We will assume that we have two folders in the project, "frontend" and "backend".

In the main folder, settings.gradle must contain:

rootProject.name = 'my-project'
include ':frontend', ':backend'

In the backend folder, the build.gradle file must contain:

dependencies {
  // ...
	runtimeOnly project(':frontend')
}

task copyWebApplication(type: Copy) {
	from project(':frontend').file('build')
	into('./src/main/resources/static')
}

build.dependsOn(copyWebApplication)
copyWebApplication.dependsOn(':frontend:build')

And the frontend folder must contain a build.gradle file with the following:

plugins {
    id 'base'
    id "com.github.node-gradle.node" version "3.2.1"
}

task npmBuild(type: NpmTask) {
    args = ['run', 'build']
}

task dev(type: NpmTask){
    args= ['start']
}

assemble.dependsOn(npmBuild)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment