当在依赖任务中再次调用GradleDependOn时不起作用

时间:2018-09-20 12:50:52

标签: gradle build.gradle

我想在每次调用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);
    }


}

1 个答案:

答案 0 :(得分:2)

没有一个以上的选项可以将任务添加到DAG(有向无环图-gradle在后台使用)。最多可以一次添加任务。因此,如果您定义从任务ABC的依赖关系,则执行顺序可能是:

  • C-> B-> A
  • C-> A-> B

但是C将只运行一次。