I have a project that consists of two parts: Spring Boot and React.
In my Spring Boot build.gradle
config I specified what actions should be performed in order to build and run the application.
Here is how it looks like:
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id "com.github.node-gradle.node" version "2.2.4"
}
group = 'com.vtti'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.apache.poi:poi:3.10-FINAL'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
compile 'org.apache.poi:poi:3.10-FINAL'
compile 'org.apache.poi:poi-ooxml:3.10-FINAL'
compile 'com.sendgrid:sendgrid-java:4.1.2'
compile 'org.json:json:20190722'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.11.0'
}
test {
useJUnitPlatform()
}
node {
// Version of node to use.
version = '10.16.3'
// Version of Yarn to use.
yarnVersion = '1.21.1'
// Base URL for fetching node distributions (change if you have a mirror).
distBaseUrl = 'https://nodejs.org/dist'
// If true, it will download node using above parameters.
// If false, it will try to use globally installed node.
download = true
// Set the work directory for unpacking node
workDir = file("${project.buildDir}/nodejs")
// Set the work directory for YARN
yarnWorkDir = file("${project.buildDir}/yarn")
// Set the work directory where node_modules should be located
nodeModulesDir = file("${project.projectDir}")
}
task appYarnInstall(type: YarnTask) {
description = "Install all dependencies from package.json"
workingDir = file("${project.projectDir}/src/main/client")
args = ["install"]
}
task appYarnBuild(type: YarnTask) {
description = "Build production version of the React client"
workingDir = file("${project.projectDir}/src/main/client")
args = ["run", "build"]
}
task copyClient(type: Copy) {
from 'src/main/client/build'
// into 'build/resources/main/static/.'
into 'src/main/resources/static/.'
}
appYarnBuild.dependsOn appYarnInstall
copyClient.dependsOn appYarnBuild
compileJava.dependsOn copyClient
When I run gradlew build
everything works properly, Gradle performs yarn install
, yarn build
, etc.
However, when I run gradlew bootRun
and want just to compile and run a project, it performs all the yarn
actions again and builds a new front-end, which leads in multiple "changed files" that are visible for git and should be committed again.
Is that possible to specify when tasks should be run and run them only on gradlew build
and not on gradlew bootRun
?