2017-04-10 94 views
2

目前,我在gradle这个是这样的创建可执行任务的gradle

class MyTask extends DefaultTask { 
    @TaskAction 
    public void run() { 

    } 
} 

像这样的事情,我可以做的build.gradle

task stopTomcat(type:Exec) { 
    workingDir '../tomcat/bin' 

    //on windows: 
    commandLine 'cmd', '/c', 'stop.bat' 

    //on linux 
    commandLine './stop.sh' 

    //store the output instead of printing to the console: 
    standardOutput = new ByteArrayOutputStream() 

    //extension method stopTomcat.output() can be used to obtain the output: 
    ext.output = { 
    return standardOutput.toString() 
    } 
} 

一个任务,我想使这个任务执行访问commandLine,workingDir等。我该如何做到这一点?

+0

你是什么意思的可执行做?你是什​​么意思_“访问commandLine,workingDir等”_ –

+0

@tim_yates。在问题的主体中增加了更多信息 – user12331

回答

0

(如果那是你的意思),你可以做这样的事情:

class MyTask extends DefaultTask { 
    private workingDir 
    private commandLine 

    void workingDir(String workingDir) { 
     this.workingDir = workingDir 
    } 

    void commandLine(String commandLine) { 
     this.commandLine = commandLine 
    } 

    @TaskAction 
    void run() { 
     println "I will run $commandLine in $workingDir" 
    } 
}