2016-07-14 201 views
0

我試圖以運行多個任務:搖籃問題

task deleteTargetAndCopyfiles(type: Copy) {} 

--> then: 

task RunMavenCommands(type: Exec) {} 

--> then: 

task zipTheResults(type: Zip) {} 

其中運行Exec任務,我有一個問題。 如果我使用:

task RunMavenCommands(type: Exec) {} 
    println '*******************************' 

    standardOutput = new ByteArrayOutputStream() 

    ext { 

     def startingDir = 'target/gradle_assembly' 
     def mavenOpt = '-Dmaven.test.skip=true -DskipTests=true' 
     def mavenRepo = '-Dmaven.repo.local=../../Tools/local/repository' 
     environment "MAVEN_OPTS", "${mavenOpt} ${mavenRepo}" 

     workingDir 'target/gradle_assembly' 

     def command = commandLine 'mvn', 'verify' 
    } 


// doLast { 
//  println '*******************************' 
//  } 
} 

OR我運行:

task RunMavenCommands(type: Exec) {} 
    println '*******************************' 

    standardOutput = new ByteArrayOutputStream() 

    ext { 

     def startingDir = 'target/gradle_assembly' 
     def mavenOpt = '-Dmaven.test.skip=true -DskipTests=true' 
     def mavenRepo = '-Dmaven.repo.local=../../Tools/local/repository' 
     environment "MAVEN_OPTS", "${mavenOpt} ${mavenRepo}" 

     workingDir 'target/gradle_assembly' 

     def command = commandLine 'mvn', 'verify' 
    } 


    doLast { 
     println '*******************************' 
    } 
} 

我得到這個錯誤:

18:14:02.420 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING 18:14:02.421 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: command 'mvn'.

18:14:02.476 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED 18:14:02.477 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command 'mvn'' finished with exit value -1 (state: FAILED)

18:14:02.477 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':mavenExecute' 18:14:02.478 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :mavenExecute FAILED 18:14:02.478 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :mavenExecute (Thread[main,5,main]) completed. Took 0.067 secs. 18:14:02.478 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 0.067 secs, idle: 0.001 secs 18:14:02.483 [ERROR] [org.gradle.BuildExceptionReporter] 18:14:02.483 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception. 18:14:02.483 [ERROR] [org.gradle.BuildExceptionReporter] 18:14:02.483 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong: 18:14:02.484 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':mavenExecute'. 18:14:02.484 [ERROR] [org.gradle.BuildExceptionReporter] > A problem occurred starting process 'command 'mvn''

我一直在試圖破解任何可能的方式在過去的3天沒有成功,也沒有看到有任何人有適合我的工作解決方案。

回答

0

異常使我懷疑它的執行誤差與排序錯誤,而是要回答你的問題,規定:

如果命令總是需要的順序運行,使用dependsOn:

task deleteTargetAndCopyfiles(type: Copy) {} 

task RunMavenCommands(type: Exec) { 
    dependsOn deleteTargetAndCopyfiles 
} 

task zipTheResults(type: Zip) { 
    dependsOn RunMavenCommands 
} 

否則,在命令行中,你應該能夠以指定的所有目標:

gradle deleteTargetAndCopyfiles RunMavenCommands zipTheResults 
+0

我也有相關性,而deleteTargetAndCopyfiles任務始終運行,但RunMave nCommands maven任務總是失敗。 –

+0

上面的輸出是否使用'--stacktrace'運行?如果沒有,你可以添加輸出嗎? – romeara

+0

上面是運行--debug –