2014-04-04 4 views
0

선택한 빌드에 따라 파일 복사 대상 대상을 변경하고 싶습니다. 작업 그래프가 실행 단계에서 실행되었지만 copyTask가 구성 단계에서 설정 되었기 때문에 이는 작동하지 않습니다.복사 작업 대상 변경

어떻게하면됩니까?

gradle.taskGraph.whenReady { taskGraph -> 
    println('taskGraph') 
    if (taskGraph.hasTask(buildRelease)){ 
     File toDir=file('test/r') 
     println('Copy to: ' + toDir.getName()) 
    }else if (taskGraph.hasTask(buildDevel)) { 
     File toDir=file('test/d') 
     println('Copy to: ' + toDir.getName()) 
    } 

} 

task buildDevel (dependsOn: ['copyTask']){} 
task buildRelease (dependsOn: ['copyTask']){} 

task copyTask(type: Copy) { 
     from "test" 
     into toDir 
     include 'a.txt' 
} 

답변

0

이 당신을 도울 수있다 (당신은 build.gradle가 위치한 같은 수준에 a.txt 파일을 작성해야합니다 :

gradle.taskGraph.whenReady { taskGraph -> 

    def cp = project.copyTask 
    if (taskGraph.hasTask(buildRelease)){   
     cp.into 'lol1' 
    } else if (taskGraph.hasTask(buildDevel)) { 
     cp.into 'lol2' 
    } 
} 

task buildDevel (dependsOn: ['copyTask']){} 
task buildRelease (dependsOn: ['copyTask']){} 

task copyTask(type: Copy) { 
    from file('.') 
    include 'a.txt' 
} 

이것은 또한 작동합니다

task buildDevel 
task buildRelease 

buildDevel.doFirst { 
    cp('lol1') 
} 

buildRelease.doFirst { 
    cp('lol2') 
} 

def cp(to) { 
    copy { 
    from file('.') 
    into to 
    include 'a.txt' 
    } 
}