2016-06-08 56 views
2

我有很多from/include/exclude任务战争配置:如何在Gradle中重用任务配置?

task war { 
    exclude 
    exclude 
    ... 
    into ... from ... 
    into ... from ... 
} 

我还有一个任务战争配置,它只是一个exclude相同。 我不想重复这些配置。我怎样才能重用第一个配置?

回答

2

尝试:

ext.sharedCopyConf = { task, to -> 
    configure(task) { 
    into to 
    from 'a' 
    } 
} 

task copy1(type: Copy) { t -> 
    sharedCopyConf(t, 'b') 
} 

task copy2(type: Copy) { t -> 
    sharedCopyConf(t, 'c') 
} 

看一看的demo

0
ext.sharedWarConfig = { task-> 
    configure(task) { 
     from ... include ... 

    }} 

task warWithoutFile(type: War) { task -> 
    sharedWarConfig(task) 

    exclude ... 
} 

task warWithFile(type: War) { task -> sharedWarConfig(task) } 

jettyRunWar { 
    dependsOn warWithFile 
    dependsOn.remove("war") 

    webApp = warWithFile.archivePath 
}