0
votes

I am trying to run several tasks in order:

task deleteTargetAndCopyfiles(type: Copy) {}

--> then:

task RunMavenCommands(type: Exec) {}

--> then:

task zipTheResults(type: Zip) {}

I am having an issue where running the Exec task. If I use:

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 I run:

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 '*******************************'
    }  
}

I get this error:

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''

I have been trying to hack any possible way for the past 3-days with zero success, and not see anyone that have a working solution that works for me.

1

1 Answers

0
votes

The exception makes me wonder if its execution error vs. an ordering error, but to answer your stated question:

If the commands always need to run in that order, use dependsOn:

task deleteTargetAndCopyfiles(type: Copy) {}

task RunMavenCommands(type: Exec) {
    dependsOn deleteTargetAndCopyfiles
}

task zipTheResults(type: Zip) {
    dependsOn RunMavenCommands
}

Otherwise, from the command line, you should be able to specify all targets in order:

gradle deleteTargetAndCopyfiles RunMavenCommands zipTheResults