我想在每次调用superParent
下的build.gradle
中运行task superParent {
doLast {
println 'Hello Super Parent Last'
}
}
task helloParent {
dependsOn superParent
description 'Hello task is Dependent on helloParent Task'
doFirst {
println 'Hello Parent First'
}
doLast {
println 'Hello Parent Last'
}
}
task hello {
description 'Just prints Hello..'
dependsOn helloParent,superParent
doFirst {
println 'Hello First'
}
doLast {
println 'Hello Last'
}
}
任务。
gradlew hello
当我执行> Task :superParent
Hello Super Parent Last
> Task :helloParent
Hello Parent First
Hello Parent Last
> Task :hello
Hello First
Hello Last
时,得到以下输出
superParent
hello
任务不会再次调用> Task :superParent
Hello Super Parent Last
> Task :helloParent
Hello Parent First
Hello Parent Last
> Task :superParent
Hello Super Parent Last
> Task :hello
Hello First
Hello Last
任务。我期望这样的输出
预期结果
@PutMapping("user/{id}")
public boolean updateUser(@PathVariable id, @RequestBody User user) {
User currentUser = userRepo.findOne(id);
user = (User) PersistenceUtils.partialUpdate(currentUser, user);
return userRepo.save(user);
}
public class PersistenceUtils {
public static Object partialUpdate(Object dbObject, Object partialUpdateObject){
String[] ignoredProperties = getNullPropertyNames(partialUpdateObject);
BeanUtils.copyProperties(partialUpdateObject, dbObject, ignoredProperties);
return dbObject;
}
private static String[] getNullPropertyNames(Object object) {
final BeanWrapper wrappedSource = new BeanWrapperImpl(object);
return Stream.of(wrappedSource.getPropertyDescriptors())
.map(FeatureDescriptor::getName)
.filter(propertyName -> wrappedSource.getPropertyValue(propertyName) == null)
.toArray(String[]::new);
}
}
答案 0 :(得分:2)
没有一个以上的选项可以将任务添加到DAG(有向无环图-gradle在后台使用)。最多可以一次添加任务。因此,如果您定义从任务A
和B
到C
的依赖关系,则执行顺序可能是:
C
-> B
-> A
C
-> A
-> B
但是C
将只运行一次。