大家好,感谢您抽出时间提前帮忙。这是我发布的第一个问题,如果可以改进,请告诉我
我是一个新手,这是我的第一个项目。
我在底部包含 gradle.build ,它从nexus repo下载tar,然后我有任务解压缩并将文件复制到$buildDir/classes/main/static/sisplayer
。然后我有一个war.dependsOn copyPlayer
来准备好添加文件。问题是,我可以将文件包含在战争中以在服务器上工作,并bootRun{}.dependsOn copyPlayer
在gradle bootRun
运行应用程序之前获取文件
但是当我使用主类在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']
}
答案 0 :(得分:0)
经过大量谷歌搜索后,我能够从Gradle开发团队的一名开发人员那里获得帮助,并且在smartJ编译代码之前,他发现了Gradle的职责范围/责任来执行任务。这是因为intelliJ使用自己的编译器而不是Gradle的Build / Compile任务。在编译之前让intelliJ运行任务的简单方法是在从IntelliJ中的Gradle View编译之前右键单击要运行的任务,然后选择Run Before Build