【发布时间】:2020-10-30 06:06:38
【问题描述】:
我有一个项目,它由两部分组成:Spring Boot 和 React。
在我的 Spring Boot build.gradle 配置中,我指定了应该执行哪些操作才能构建和运行应用程序。
如下所示:
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
当我运行 gradlew build 一切正常时,Gradle 执行 yarn install、yarn build 等。
但是,当我运行 gradlew bootRun 并只想编译和运行一个项目时,它会再次执行所有 yarn 操作并构建一个新的前端,这会导致多个可见的“更改文件” git 并且应该再次提交。
是否可以指定何时运行任务并仅在 gradlew build 而不是 gradlew bootRun 上运行它们?
【问题讨论】:
标签: java reactjs spring gradle build.gradle