Gradle 运行 复制任务以在 build/classes 中添加 js 文件到 IDE(intellj) compile/make 项目之后

Gradle run copy task to add js files in build/classes after IDE(intellj) compile/make project

大家好,感谢您抽出时间提前提供帮助。这是我发布的第一个问题,如果可以改进,请告诉我。
我是 gradle 的新手,这是我的第一个项目。 我在底部包含 gradle.build 从 nexus repo 下载 tar 然后我有任务要取消 tar 并将文件复制到 $buildDir/classes/main/static/sisplayer。然后我有一个 war.dependsOn copyPlayer 准备好将文件添加到其中。问题是我可以获取要包含在 war 中的文件以在服务器上工作,并让 bootRun{}.dependsOn copyPlayer 在 运行 通过 gradle bootRun 应用程序之前拥有这些文件 但是当我 运行 使用 main class 上的 intellij 应用程序时,我没有得到文件。我假设我需要在编译项目之前连接要执行的任务,所以我尝试了

compileJava.dependsOn copyPlayer

但这是给出错误。我也尝试过使用像

这样的钩子
gradle.projectsEvaluated {
    preBuild.dependsOn copyPlayer
}

here 中所建议,但这也出现了错误。有人可以帮忙吗?我试图查找但找不到解决方案。

由于这是我的第一个 gradle 项目,配置中还有其他我可以改进的东西。 整个配置如下。

 buildscript {
    ext {
        springBootVersion = '1.4.1.RELEASE'
    }
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'org.springframework:springloaded:1.2.6.RELEASE'
    }
}


plugins {
    id "org.sonarqube" version "2.2.1"
    id "net.saliman.cobertura" version "2.3.2"
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'

sourceCompatibility = 1.8
targetCompatibility = 1.8
def playerVersion= "0.4.0-36"
idea {
    module {
        inheritOutputDirs = false
        outputDir = file("$buildDir/classes/main/")
    }

}

war {

    baseName = 'streaming_demo'
    version = '0.0.1-SNAPSHOT'
    from("$buildDir/classes/main/static/jsplayer"){
        into("WEB-INF/classes/static/jsplayer")
    }

}

repositories {
    maven {
        url "http://example.com:6590/nexus/content/repositories/frontend-artifacts"
    }

    maven {
        url "example.com:6590/nexus/content/groups/public/"
    }
    maven {
        url "http://example.com:6590/nexus/content/repositories/releases/"
    }
    maven {
        url "http://example.com:6590/nexus/content/repositories/thirdparty/" 
    }
    maven { url "http://oss.sonatype.org/content/repositories/snapshots/"
    }

    mavenCentral()
    }

    configurations {
        jsPlayer
        providedRuntime
    }
    dependencies {
    //  compile group: 'javax.el', name: 'javax.el-api', version: '2.2.4'
        sisPlayer "com.example:jsplayer:$playerVersion@tar.gz"
        compile('org.springframework.boot:spring-boot-starter-data-jpa')
        compile('org.springframework.boot:spring-boot-devtools')
        compile('org.springframework.boot:spring-boot-starter-jdbc')
        compile('org.springframework.boot:spring-boot-starter-web') {
            exclude module: "spring-boot-starter-tomcat"
        }
        compile('org.springframework.boot:spring-boot-starter-web-services')
        compile("org.springframework.boot:spring-boot-starter-thymeleaf")
        compile("org.springframework.boot:spring-boot-starter-security")
        compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4")
        runtime 'mysql:mysql-connector-java:5.1.24'
        compile 'com.microsoft.sqlserver:sqljdbc41:4.1'

        runtime('com.h2database:h2')
    testCompile('org.springframework.boot:spring-boot-starter-test')

    //  dependencies for using Spock
    compile "org.codehaus.groovy:groovy-all:2.4.1"
    testCompile "org.spockframework:spock-core:1.0-groovy-2.4"

    testRuntime "cglib:cglib-nodep:3.1"          // allows mocking of 

    classes (in addition to interfaces)
        testRuntime "org.objenesis:objenesis:2.1"
        // allows mocking of classes without default constructor (together with CGLIB)
    }
    task wrapper(type: Wrapper) {
        gradleVersion = '3.1'
    }
    task extractPlayer(type: Copy){
        from tarTree(configurations.jsPlayer.singleFile)
        into "$buildDir/testplayerDownload/"

    }
    task copyPlayer(type: Copy) {
        dependsOn extractPlayer
        from "$buildDir/testplayerDownload/dist"
        into "$buildDir/classes/main/static/jsplayer"
        doLast {
            delete("$buildDir/testplayerDownload/")
        }
    }

    build{}.doLast{
        tasks.extractPlayer.execute()
        tasks.copyPlayer.execute()
    }

    war.dependsOn copyPlayer

    bootRun {}.dependsOn copyPlayer

    gradle.projectsEvaluated {
        preBuild.dependsOn copyPlayer
    }
     cobertura {
        coverageFormats = ['xml']
    }

经过大量谷歌搜索后,我能够从 Gradle 开发团队的一位开发人员那里获得帮助,并发现它不属于 Gradle 的 scope/responsibility 来执行任务在 intelliJ 编译代码之前。这是因为 intelliJ 使用自己的编译器而不是 Gradle 的 Build/Compile 任务。在编译前使用 intelliJ 运行 任务的一种简单方法是,在编译前从 Gradle View in intelliJ 和 select [=10] 中右键单击要 运行 的任务=]