我正在努力理解Gradle“任务”语法。
我遵循了一个howto并定义了一个build.gradle
,用gradle构建一个Angular4 / SpringBoots项目。
build.gradle
包含多个task
块:
// add our development build NpmTask named buildClientDev
task buildClientDev(type: NpmTask, dependsOn: 'npmInstall') {
group = 'build'
description = 'Compile client side folder for development'
args = ['run', 'buildDev']
}
task buildClient(type: NpmTask, dependsOn: 'npmInstall') {
group = 'build'
description = "Compile client side folder for production"
args = ['run', 'build']
}
// setup watcher on this ng build to link to our overall java development build.
task buildClientWatch(type: NpmTask, dependsOn: 'npmInstall') {
group = 'application'
description = "Build and watches the client side assets for rebuilding"
args = ['run', 'buildWatch']
}
通过执行Gradle命令./gradlew bootRun
问题:
buildDev, build, buildWatch
NPM还是Gradle命令?gradlew bootrun
命令的连接在哪里? Gradle如何知道它们应该在gradlew bootrun
之后执行?完全build.gradle:
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
jcenter()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "com.moowork.gradle:gradle-node-plugin:1.1.1"
}
}
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
// enable building wars: gradlew BootWar
apply plugin: 'war'
// fuilding frontend with npm
apply plugin: "com.moowork.node"
// add our development build NpmTask named buildClientDev
task buildClientDev(type: NpmTask, dependsOn: 'npmInstall') {
group = 'build'
description = 'Compile client side folder for development'
args = ['run', 'buildDev']
}
task buildClient(type: NpmTask, dependsOn: 'npmInstall') {
group = 'build'
description = "Compile client side folder for production"
args = ['run', 'build']
}
// setup watcher on this ng build to link to our overall java development build.
task buildClientWatch(type: NpmTask, dependsOn: 'npmInstall') {
group = 'application'
description = "Build and watches the client side assets for rebuilding"
args = ['run', 'buildWatch']
}
bootRun.dependsOn(buildClientDev)
jar.dependsOn(buildClient)
npm_run_build.inputs.dir new File(projectDir, "frontend")
npm_run_build.outputs.dir new File(projectDir, "build/dist")
group = 'de.webapp.spring'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url 'https://repo.spring.io/libs-snapshot' }
}
dependencies {
// makes the web application startable
compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework.boot:spring-boot-starter-web")
testCompile('org.springframework.boot:spring-boot-starter-test')
//data
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-data-rest")
// RepositoryRestConfigurerAdapter
compile "org.springframework.data:spring-data-rest-core"
compile "org.springframework.data:spring-data-rest-webmvc"
compile "org.springframework:spring-context"
// enables HAL browser
compile "org.springframework.data:spring-data-rest-hal-browser"
// entity requirements
compile "com.h2database:h2"
compile "javax.xml.bind:jaxb-api"
}
更新:
执行gradlew bootRun
gradlew bootRun
命令> bootRun.dependsOn(buildClientDev)
。 > args = ['run', 'buildDev']
> buildDev": "ng
build"
gradlew bootRun的定向依赖图如下所示:
gradlew tasktree bootRun
> Task :taskTree
------------------------------------------------------------
Root project
------------------------------------------------------------
:bootRun
+--- :buildClientDev
| +--- :npmInstall
| | \--- :npmSetup
| | \--- :nodeSetup
| \--- :npmSetup
| \--- :nodeSetup
\--- :classes
+--- :compileJava
\--- :processResources
答案 0 :(得分:3)
谁定义了这些任务块的语法?我申请的其中一个插件?
任务块中可用的属性和方法由任务的“类型”定义。在这种情况下,NpmTask
来自com.moowork.node
插件
是buildDev,build,buildWatch NPM还是Gradle命令?
它们是gradle模型中的任务,类型为NpmTask
(来自com.moowork.node
插件)
如果这些是NPM命令 - 与Gradle的gradlew bootrun命令的连接在哪里? Gradle如何知道,他们应该在gradlew bootrun之后执行?
同样,bootRun
不是核心Gradle任务,它是由org.springframework.boot
插件添加的。它们在Gradle的DAG中连接在一起。我可以在dependsOn
中看到两个build.gradle
声明,它们将它们连接在一起
bootRun.dependsOn(buildClientDev)
task buildClientDev(type: NpmTask, dependsOn: 'npmInstall')
如果您想要显示DAG,我建议您添加task-tree插件
plugins {
id "com.dorongold.task-tree" version "1.3"
}
然后你可以运行
./gradlew taskTree bootRun
你会得到一个类似于以下的任务树(注意:这个例子用于完全不同的任务树)
:build
+---- :assemble
| \--- :jar
| \--- :classes
| +--- :compileJava
| \--- :processResources
\--- :check
\--- :test
+--- :classes
| +--- :compileJava
| \--- :processResources
\--- :testClasses
+--- :compileTestJava
| \--- :classes
| +--- :compileJava
| \--- :processResources
\--- :processTestResources