我如何自动执行要在bootRun任务之前运行的nmp_run_build或npm_test gradle任务?

时间:2019-06-30 11:17:46

标签: reactjs spring-boot gradle

  

我有一个包含Java Spring Boot和javascript react代码的项目   可以使用bootRun构建并启动spring引导代码   可以使用gradle npm_test命令测试React代码   可以使用gradle npm__run_build命令来构建React代码   我想定义一个任务:    1)测试反应码    2)建立反应代码    3)将构建复制到/ srs / main / resource    4)运行gradle bootRun命令    

是我尝试通过使用未完成的任务来完成的。
gradle.buld
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE")
    }
}
plugins { 
    id 'java'
    id 'org.springframework.boot' version '2.1.5.RELEASE'
    id "com.moowork.node" version "1.3.1"
    id 'jacoco'
}


apply plugin: 'io.spring.dependency-management'

jacoco {
    toolVersion = "0.8.3"
    reportsDir = file("$buildDir/customJacocoReportDir")
}

jacocoTestReport { 
    reports {
        xml.enabled = true
    }   
}

group = 'com.steinko.reactspringboottutorial.webserver'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

repositories {
    mavenCentral()
}

test {
    useJUnitPlatform()
}

sourceSets {
  main {
    resources {
       srcDirs = [ 
                   'src/main/resources'       
                ]
    }
  }
}

ext {
    set('springCloudVersion', "Greenwich.SR1")
}



dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.cloud:spring-cloud-gcp-starter'
    implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
    implementation 'org.springframework.boot:spring-boot-starter-log4j2' 

    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
    testImplementation 'org.junit.jupiter:junit-jupiter-params:5.2.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}



dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
}



node {
    /* gradle-node-plugin configuration
       https://github.com/srs/gradle-node-plugin/blob/master/docs/node.md
       Task name pattern:
       ./gradlew npm_<command> Executes an NPM command.
    */
    // Version of node to use.
    version = '10.16.0'
    // Version of npm to use.
    npmVersion = '6.9.0'
    // If true, it will download node using above parameters.
    // If false, it will try to use globally installed node.
    download = false
}

task copyBuild(type: Copy) { 
    dependsOn 'runBuild'
    println 'copy build files'
    from "$buildDir/build/static"
    into "$buildDir/src/main/resources/static/build/static"
}

task runTest { 
    doLast {
         tasks.npm_test
         println 'test react'
     }
}

task runBuild { 

    dependsOn 'runTest'
    doLast { 
        tasks.npm_run_build
        println 'build react'
    }
}

task runBootRun { 
    dependsOn 'copyBuild'
    doLast { 
     tasks.bootRun  
     println 'boot run'
  }
}
  

运行此脚本时,得到以下结果   gradle runBootRun

     
    

配置项目:     复制构建文件

         

任务:runTest     测试反应

         

任务:runBuild     建立反应

         

任务:runBootRun     开机运行

  
     

但尚未执行任何run_build run_test bootRun副本   我怎样才能满满我的规格?

0 个答案:

没有答案