我很难理解分级的“任务”语法。
我遵循了一个howto并定义了一个build.gradle,用gradle构建一个Angular4 4/SpringBoot项目。
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启动,执行Gradle命令./gradlew bootRun
问题:
buildDev, build, buildWatch是NPM还是Gradle命令?gradlew bootrun命令的连接在哪里?Gradle如何知道,它们应该在gradlew bootrun之后执行?Full 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"中梯度bootRun的有向依赖图如下所示:
gradlew tasktree bootRun
> Task :taskTree
------------------------------------------------------------
Root project
------------------------------------------------------------
:bootRun
+--- :buildClientDev
| +--- :npmInstall
| | \--- :npmSetup
| | \--- :nodeSetup
| \--- :npmSetup
| \--- :nodeSetup
\--- :classes
+--- :compileJava
\--- :processResources发布于 2018-03-05 10:01:26
谁定义了这些任务块的语法?我申请的插件之一?
任务块中可用的属性和方法由任务的“类型”定义。在本例中,是NpmTask,它来自于com.moowork.node插件
buildDev、build、buildWatch NPM还是Gradle命令?
它们是gradle模型中的任务,类型为NpmTask (来自com.moowork.node插件)
如果这些是NPM命令-到Gradle的gradlew引导命令的连接在哪里?格拉德尔怎么知道,他们应该在毕业后执行?
再说一遍,bootRun不是核心级任务,它是由org.springframework.boot插件添加的。他们是连接在一起的格拉德尔的达格。我可以在您的dependsOn中看到两个build.gradle声明,它们连接在一起
bootRun.dependsOn(buildClientDev)task buildClientDev(type: NpmTask, dependsOn: 'npmInstall')如果您想要可视化DAG,我建议您添加任务树插件
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
\--- :processTestResourceshttps://stackoverflow.com/questions/49106285
复制相似问题