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

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

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

Project.getBuildscript介绍

暂无

代码示例

代码示例来源:origin: uber/okbuck

@Nullable
public static String findVersionInClasspath(Project project, String group, String module) {
 return project
   .getBuildscript()
   .getConfigurations()
   .getByName("classpath")
   .getIncoming()
   .getArtifacts()
   .getArtifacts()
   .stream()
   .flatMap(
     artifactResult ->
       artifactResult.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier
         ? Stream.of(
           (ModuleComponentIdentifier) artifactResult.getId().getComponentIdentifier())
         : Stream.empty())
   .filter(
     identifier ->
       (group.equals(identifier.getGroup()) && module.equals(identifier.getModule())))
   .findFirst()
   .map(ModuleComponentIdentifier::getVersion)
   .orElse(null);
}

代码示例来源:origin: diffplug/spotless

public static Provisioner fromProject(Project project) {
  Objects.requireNonNull(project);
  return (withTransitives, mavenCoords) -> {
    try {
      Dependency[] deps = mavenCoords.stream()
          .map(project.getBuildscript().getDependencies()::create)
          .toArray(Dependency[]::new);
      Configuration config = project.getRootProject().getBuildscript().getConfigurations().detachedConfiguration(deps);
      config.setDescription(mavenCoords.toString());
      config.setTransitive(withTransitives);
      return config.resolve();
    } catch (Exception e) {
      logger.log(Level.SEVERE,
          StringPrinter.buildStringFromLines("You probably need to add a repository containing the '" + mavenCoords + "' artifact in the 'build.gradle' of your root project.",
              "E.g.: 'buildscript { repositories { mavenCentral() }}'",
              "Note that included buildscripts (using 'apply from') do not share their buildscript repositories with the underlying project.",
              "You have to specify the missing repository explicitly in the buildscript of the root project."),
          e);
      throw e;
    }
  };
}

代码示例来源:origin: de.carne.common/java-gradle-plugins

public static DependencyMap fromBuildscript(Project project) {
  return new DependencyMap(project, project.getBuildscript());
}

代码示例来源:origin: gradle.plugin.de.acetous/gradle-require-dependency-compliance-plugin

/**
 * Get all buildscript's repositories of this project and it's subprojects.
 *
 * @return The buildscript's repositories.
 */
protected Set<RepositoryIdentifier> resolveBuildRepositories() {
  return getProject().getAllprojects().stream() //
      .flatMap(project -> project.getBuildscript().getRepositories().stream()) //
      .map(RepositoryIdentifier::new) //
      .filter(this::filterMavenLocal) //
      .collect(Collectors.toSet());
}

代码示例来源:origin: gradle.plugin.de.acetous/gradle-require-dependency-compliance-plugin

/**
 * Resolve all buildscript dependencies of this project and it's subprojects.
 *
 * @return All resolved buildscript dependencies.
 */
protected List<DependencyIdentifier> resolveBuildDependencies() {
  return getProject().getAllprojects().stream() //
      .map(project -> project.getBuildscript().getConfigurations().getByName(ScriptHandler.CLASSPATH_CONFIGURATION).getResolvedConfiguration()) //
      .flatMap(confguration -> confguration.getResolvedArtifacts().stream()) //
      .map(resolvedArtifact -> resolvedArtifact.getModuleVersion().getId()) //
      .map(DependencyIdentifier::new) //
      .distinct() //
      .filter(this::filterIgnoredDependencies) //
      .sorted(new DependencyIdentifierComparator()) //
      .collect(Collectors.toList());
}

代码示例来源:origin: javafxports/javafxmobile-plugin

public void exec() {
  project.javaexec(exec -> {
    exec.setClasspath(project.getBuildscript().getConfigurations().getByName("classpath"));
    String path = retrobufferClasspath.getAsPath();
    exec.setMain("org.javafxports.retrobuffer.Main");
    exec.setJvmArgs(Arrays.asList(
        "-Dretrobuffer.inputDir=" + inputDir,
        "-Dretrobuffer.outputDir=" + outputDir,
        "-Dretrobuffer.classpath=" + path
    ));
    if (classpathLengthGreaterThanLimit(path)) {
      try {
        File classpathFile = File.createTempFile("inc-", ".path");
        try (BufferedWriter writer = Files.newBufferedWriter(classpathFile.toPath(), StandardCharsets.UTF_8)) {
          for (File item : this.retrobufferClasspath) {
            writer.write(item.toString() + "\n");
          }
        }
        classpathFile.deleteOnExit();
        exec.getJvmArgs().add("-Dretrobuffer.classpathFile=" + classpathFile.getAbsolutePath());
      } catch (IOException e) {
      }
    } else {
      exec.getJvmArgs().add("-Dretrobuffer.classpath=" + path);
    }
    for (String arg : jvmArgs) {
      exec.getJvmArgs().add(arg);
    }
  });
}

代码示例来源:origin: EvoSuite/evosuite

for(org.gradle.api.artifacts.Configuration c : p.getBuildscript().getConfigurations()){
  System.out.println("Conf: "+c);

代码示例来源:origin: diffplug/goomph

/**
 * @param project    the project on which we'll call {@link Project#javaexec(Action)}.
 * @param input        the JavaExecable which we'll take as input and call run() on.
 * @param settings    any extra settings you'd like to set on the JavaExec (e.g. heap)
 * @return the JavaExecable after it has had run() called.
 */
public static <T extends JavaExecable> T exec(Project project, T input, Action<JavaExecSpec> settings) throws Throwable {
  // copy the classpath from the project's buildscript (and its parents)
  List<FileCollection> classpaths = TreeStream.toParent(ProjectPlugin.treeDef(), project)
      .map(p -> p.getBuildscript().getConfigurations().getByName(BUILDSCRIPT_CLASSPATH))
      .collect(Collectors.toList());
  // add the gradleApi, workaround from https://discuss.gradle.org/t/gradle-doesnt-add-the-same-dependencies-to-classpath-when-applying-plugins/9759/6?u=ned_twigg
  classpaths.add(project.getConfigurations().detachedConfiguration(project.getDependencies().gradleApi()));
  // add stuff from the local classloader too, to fix testkit's classpath
  classpaths.add(project.files(JavaExecableImp.fromLocalClassloader()));
  // run it
  return JavaExecableImp.execInternal(input, project.files(classpaths), settings, execSpec -> JavaExecWinFriendly.javaExec(project, execSpec));
}

代码示例来源:origin: com.android.tools.build/gradle-core

@Nullable
private String getJacocoVersion() {
  Project candidateProject = project;
  boolean shouldFailWithException = false;
  while (candidateProject != null) {
    Set<ResolvedArtifact> resolvedArtifacts =
        candidateProject.getBuildscript().getConfigurations().getByName("classpath")
            .getResolvedConfiguration().getResolvedArtifacts();
    for (ResolvedArtifact artifact : resolvedArtifacts) {
      ModuleVersionIdentifier moduleVersion = artifact.getModuleVersion().getId();
      if ("org.jacoco.core".equals(moduleVersion.getName())) {
        return moduleVersion.getVersion();
      }
    }
    if (!resolvedArtifacts.isEmpty()) {
      // not in the DSL test case, where nothing will have been resolved.
      shouldFailWithException = true;
    }
    candidateProject = candidateProject.getParent();
  }
  if (shouldFailWithException) {
    throw new IllegalStateException(
        "Could not find project build script dependency on org.jacoco.core");
  }
  project.getLogger().error(
      "No resolved dependencies found when searching for the jacoco version.");
  return DEFAULT_JACOCO_VERSION;
}

代码示例来源:origin: gradle.plugin.org.gosu-lang.gosu/gradle-gosu-plugin

private void addGosuRuntimeDependencies() {
 Set<ResolvedArtifact> buildScriptDeps = _project.getBuildscript().getConfigurations().getByName("classpath").getResolvedConfiguration().getResolvedArtifacts();
 ResolvedArtifact gosuCore = GosuPlugin.getArtifactWithName("gosu-core", buildScriptDeps);
 ResolvedArtifact gosuCoreApi = GosuPlugin.getArtifactWithName("gosu-core-api", buildScriptDeps);
 //inject Gosu jar dependencies into the classpath of the project implementing this plugin
 _project.getDependencies().add("runtime", gosuCore.getModuleVersion().getId().toString());
 _project.getDependencies().add("compile", gosuCoreApi.getModuleVersion().getId().toString());
}

代码示例来源:origin: de.carne.common/java-gradle-plugins

/**
 * Executes {@linkplain CheckDependencyVersionsTask}.
 */
@TaskAction
public void executeCheckDependencyVersions() {
  Project project = getProject();
  executeCheckDependencyVersions(DependencyMap.fromBuildscript(project),
      project.getBuildscript().getConfigurations()
          .findByName(CHECK_BUILDSCRIPT_DEPENDENCY_VERSIONS_CONFIGURATION_NAME),
      new CheckDependencyVersionsReport(project, CHECK_BUILDSCRIPT_DEPENDENCY_VERSIONS_REPORT_TITLE));
  executeCheckDependencyVersions(DependencyMap.fromProject(project),
      project.getConfigurations().findByName(CHECK_PROJECT_DEPENDENCY_VERSIONS_CONFIGURATION_NAME),
      new CheckDependencyVersionsReport(project, CHECK_PROJECT_DEPENDENCY_VERSIONS_REPORT_TITLE));
}

代码示例来源:origin: org.flywaydb/flyway-gradle-plugin

@SuppressWarnings("unused")
@TaskAction
public Object runTask() {
  try {
    Map<String, String> envVars = ConfigUtils.environmentVariablesToPropertyMap();
    Set<URL> extraURLs = new HashSet<>();
    if (isJavaProject()) {
      addClassesAndResourcesDirs(extraURLs);
      addConfigurationArtifacts(determineConfigurations(envVars), extraURLs);
    }
    ClassLoader classLoader = new URLClassLoader(
        extraURLs.toArray(new URL[0]),
        getProject().getBuildscript().getClassLoader());
    Flyway flyway = Flyway.configure(classLoader).configuration(createFlywayConfig(envVars)).load();
    Object result = run(flyway);
    ((DriverDataSource) flyway.getConfiguration().getDataSource()).shutdownDatabase();
    return result;
  } catch (Exception e) {
    throw new FlywayException(collectMessages(e, "Error occurred while executing " + getName()), e);
  }
}

代码示例来源:origin: de.carne.common/java-gradle-plugins

@Override
public void apply(Project project) {
  setGroup(CHECK_DEPENDENCY_VERSIONS_TASK_GROUP);
  setDescription(CHECK_DEPENDENCY_VERSIONS_TASK_DESCRIPTION);
  project.getBuildscript().getConfigurations().create(CHECK_BUILDSCRIPT_DEPENDENCY_VERSIONS_CONFIGURATION_NAME)
      .setVisible(false).setTransitive(false);
  project.getConfigurations().create(CHECK_PROJECT_DEPENDENCY_VERSIONS_CONFIGURATION_NAME).setVisible(false)
      .setTransitive(false);
}

代码示例来源:origin: gradle.plugin.io.sitoolkit.cv/sit-cv-gradle-plugin

public void configure() {
  setMain("io.sitoolkit.cv.app.SitCvApplication");
  FileCollection classpath = getProject().getBuildscript().getConfigurations()
      .findByName("classpath");
  setClasspath(classpath);
  setArgs(getCvArgsAsList());
  getConventionMapping().map("jvmArgs", new Callable<Iterable<String>>() {
    @SuppressWarnings("unchecked")
    @Override
    public Iterable<String> call() throws Exception {
      if (getProject().hasProperty("applicationDefaultJvmArgs")) {
        return (Iterable<String>) getProject().property("applicationDefaultJvmArgs");
      }
      return Collections.emptyList();
    }
  });
}

代码示例来源:origin: MinecraftForge/ForgeGradle

Configuration buildscriptClasspath = null;
while (parent != null && fgDepTemp == null) {
  buildscriptClasspath = parent.getBuildscript().getConfigurations().getByName("classpath");
  fgDepTemp = Iterables.getFirst(buildscriptClasspath.getDependencies().matching(new Spec<Dependency>() {
    @Override

相关文章