org.gradle.api.Project.sync()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中org.gradle.api.Project.sync()方法的一些代码示例,展示了Project.sync()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Project.sync()方法的具体详情如下:
包路径:org.gradle.api.Project
类名称:Project
方法名:sync

Project.sync介绍

暂无

代码示例

代码示例来源:origin: io.freefair.gradle/jsass-plugin

@TaskAction
  public void extractWebjars() {
    getProject().sync(sync -> {
      sync.into(outputDirectory);

      sync.setDuplicatesStrategy(DuplicatesStrategy.WARN);

      webjars.filter(File::isFile).getFiles().forEach(file ->
          sync.from(getProject().zipTree(file), jarSpec -> {
            jarSpec.include("META-INF/resources/webjars/**");
            jarSpec.setIncludeEmptyDirs(false);
            jarSpec.eachFile(fcd -> fcd.setPath(fcd.getPath().replaceFirst("META-INF/resources/webjars/(.*?)/(.*?)/", "$1/")));

          })
      );
    });
  }
}

代码示例来源:origin: io.freefair.gradle/war-plugin

private void configureOverlay(WarOverlay overlay, ExternalDependency dependency) {
  War warTask = overlay.getWarTask();
  String capitalizedWarTaskName = StringGroovyMethods.capitalize((CharSequence) warTask.getName());
  String capitalizedOverlayName = StringGroovyMethods.capitalize((CharSequence) overlay.getName());
  dependency.setTransitive(false);
  Configuration configuration = project.getConfigurations().create(overlay.getConfigurationName());
  configuration.setDescription(String.format("Contents of the overlay '%s' for the task '%s'.", overlay.getName(), warTask.getName()));
  configuration.getDependencies().add(dependency);
  File destinationDir = new File(project.getBuildDir(), String.format("overlays/%s/%s", warTask.getName(), overlay.getName()));
  Action<CopySpec> extractOverlay = copySpec -> {
    copySpec.into(destinationDir);
    copySpec.from((Callable<FileTree>) () -> project.zipTree(configuration.getSingleFile()));
  };
  Sync extractOverlayTask = project.getTasks().create(String.format("extract%s%sOverlay", capitalizedOverlayName, capitalizedWarTaskName), Sync.class, extractOverlay);
  overlay.getWarCopySpec().from(extractOverlayTask);
  if (overlay.isEnableCompilation()) {
    if (!destinationDir.exists() || isEmpty(destinationDir)) {
      project.sync(extractOverlay);
    }
    project.getTasks().getByName(CLEAN_TASK_NAME).finalizedBy(extractOverlayTask);
    ConfigurableFileCollection classes = project.files(new File(destinationDir, "WEB-INF/classes"))
        .builtBy(extractOverlayTask);
    project.getDependencies().add(COMPILE_CLASSPATH_CONFIGURATION_NAME, classes);
    project.getDependencies().add(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, classes);
    FileTree libs = project.files(extractOverlayTask).builtBy(extractOverlayTask).getAsFileTree()
        .matching(patternFilterable -> patternFilterable.include("WEB-INF/lib/**"));
    project.getDependencies().add(COMPILE_CLASSPATH_CONFIGURATION_NAME, libs);
    project.getDependencies().add(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME, libs);
  }
}

相关文章