Java Code Examples for org.gradle.api.tasks.SourceSet#setRuntimeClasspath()

The following examples show how to use org.gradle.api.tasks.SourceSet#setRuntimeClasspath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaBasePlugin.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void defineConfigurationsForSourceSet(SourceSet sourceSet, ConfigurationContainer configurations) {
    Configuration compileConfiguration = configurations.maybeCreate(sourceSet.getCompileConfigurationName());
    compileConfiguration.setVisible(false);
    compileConfiguration.setDescription("Dependencies for " + sourceSet + ".");

    Configuration runtimeConfiguration = configurations.maybeCreate(sourceSet.getRuntimeConfigurationName());
    runtimeConfiguration.setVisible(false);
    runtimeConfiguration.extendsFrom(compileConfiguration);
    runtimeConfiguration.setDescription("Runtime dependencies for " + sourceSet + ".");

    Configuration compileOnlyConfiguration = configurations.maybeCreate(sourceSet.getCompileOnlyConfigurationName());
    compileOnlyConfiguration.setVisible(false);
    compileOnlyConfiguration.extendsFrom(compileConfiguration);
    compileOnlyConfiguration.setDescription("Compile dependencies for " + sourceSet + ".");

    Configuration compileClasspathConfiguration = configurations.maybeCreate(sourceSet.getCompileClasspathConfigurationName());
    compileClasspathConfiguration.setVisible(false);
    compileClasspathConfiguration.extendsFrom(compileOnlyConfiguration);
    compileClasspathConfiguration.setDescription("Compile classpath for " + sourceSet + ".");

    sourceSet.setCompileClasspath(compileClasspathConfiguration);
    sourceSet.setRuntimeClasspath(sourceSet.getOutput().plus(runtimeConfiguration));
}
 
Example 2
Source File: JavaPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureSourceSets(final JavaPluginConvention pluginConvention) {
    final Project project = pluginConvention.getProject();

    SourceSet main = pluginConvention.getSourceSets().create(SourceSet.MAIN_SOURCE_SET_NAME);

    SourceSet test = pluginConvention.getSourceSets().create(SourceSet.TEST_SOURCE_SET_NAME);
    test.setCompileClasspath(project.files(main.getOutput(), project.getConfigurations().getByName(TEST_COMPILE_CONFIGURATION_NAME)));
    test.setRuntimeClasspath(project.files(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(TEST_RUNTIME_CONFIGURATION_NAME)));
}
 
Example 3
Source File: JavaPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureSourceSets(final JavaPluginConvention pluginConvention) {
    final Project project = pluginConvention.getProject();

    SourceSet main = pluginConvention.getSourceSets().create(SourceSet.MAIN_SOURCE_SET_NAME);

    SourceSet test = pluginConvention.getSourceSets().create(SourceSet.TEST_SOURCE_SET_NAME);
    test.setCompileClasspath(project.files(main.getOutput(), project.getConfigurations().getByName(TEST_COMPILE_CONFIGURATION_NAME)));
    test.setRuntimeClasspath(project.files(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(TEST_RUNTIME_CONFIGURATION_NAME)));
}
 
Example 4
Source File: PwtLibPlugin.java    From putnami-gradle-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void includeSourcesForTest(Project project) {
	JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
	SourceSet mainSourset = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
	SourceSet testSourset = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);

	FileCollection testClasspath = project
		.files(mainSourset.getAllSource().getSrcDirs().toArray())
		.plus(project.files(testSourset.getAllSource().getSrcDirs().toArray()))
		.plus(testSourset.getRuntimeClasspath());
	testSourset.setRuntimeClasspath(testClasspath);

	Test test = project.getTasks().withType(Test.class).getByName("test");
	test.getSystemProperties().put("gwt.persistentunitcachedir", project.getBuildDir() + "/putnami/test");
}
 
Example 5
Source File: JavaPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureSourceSets(final JavaPluginConvention pluginConvention) {
    final Project project = pluginConvention.getProject();

    SourceSet main = pluginConvention.getSourceSets().create(SourceSet.MAIN_SOURCE_SET_NAME);

    SourceSet test = pluginConvention.getSourceSets().create(SourceSet.TEST_SOURCE_SET_NAME);
    test.setCompileClasspath(project.files(main.getOutput(), project.getConfigurations().getByName(TEST_COMPILE_CONFIGURATION_NAME)));
    test.setRuntimeClasspath(project.files(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(TEST_RUNTIME_CONFIGURATION_NAME)));
}
 
Example 6
Source File: JavaPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureSourceSets(final JavaPluginConvention pluginConvention) {
    final Project project = pluginConvention.getProject();

    SourceSet main = pluginConvention.getSourceSets().create(SourceSet.MAIN_SOURCE_SET_NAME);

    SourceSet test = pluginConvention.getSourceSets().create(SourceSet.TEST_SOURCE_SET_NAME);
    test.setCompileClasspath(project.files(main.getOutput(), project.getConfigurations().getByName(TEST_COMPILE_CONFIGURATION_NAME)));
    test.setRuntimeClasspath(project.files(test.getOutput(), main.getOutput(), project.getConfigurations().getByName(TEST_RUNTIME_CONFIGURATION_NAME)));
}
 
Example 7
Source File: ClojureCommonPlugin.java    From clojurephant with Apache License 2.0 4 votes vote down vote up
private void configureDev(Project project, SourceSetContainer sourceSets) {
  SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
  SourceSet test = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
  SourceSet dev = sourceSets.create(DEV_SOURCE_SET_NAME);

  Configuration nrepl = project.getConfigurations().create(NREPL_CONFIGURATION_NAME);
  project.getDependencies().add(NREPL_CONFIGURATION_NAME, "nrepl:nrepl:0.6.0");

  project.getConfigurations().getByName(dev.getCompileClasspathConfigurationName()).extendsFrom(nrepl);
  project.getConfigurations().getByName(dev.getRuntimeClasspathConfigurationName()).extendsFrom(nrepl);

  Function<SourceSet, FileCollection> nonClojureOutput = sourceSet -> {
    FileCollection allOutput = sourceSet.getOutput();
    return allOutput.filter((File file) -> {
      return project.getTasks().stream()
          .filter(task -> task instanceof ClojureCompile || task instanceof ClojureScriptCompile || task instanceof ProcessResources)
          .allMatch(task -> !task.getOutputs().getFiles().contains(file));
    });
  };

  dev.setCompileClasspath(project.files(
      test.getOutput(),
      main.getOutput(),
      project.getConfigurations().getByName(dev.getCompileClasspathConfigurationName())));
  dev.setRuntimeClasspath(project.files(
      dev.getAllSource().getSourceDirectories(),
      nonClojureOutput.apply(dev),
      nonClojureOutput.apply(test),
      nonClojureOutput.apply(main),
      project.getConfigurations().getByName(dev.getRuntimeClasspathConfigurationName())));

  Consumer<Function<SourceSet, String>> devExtendsTest = getConfName -> {
    Configuration devConf = project.getConfigurations().getByName(getConfName.apply(dev));
    Configuration testConf = project.getConfigurations().getByName(getConfName.apply(test));
    devConf.extendsFrom(testConf);
  };

  devExtendsTest.accept(SourceSet::getImplementationConfigurationName);
  devExtendsTest.accept(SourceSet::getRuntimeOnlyConfigurationName);

  TaskProvider<ClojureNRepl> repl = project.getTasks().register(NREPL_TASK_NAME, ClojureNRepl.class, task -> {
    task.setGroup("run");
    task.setDescription("Starts an nREPL server.");
    task.setClasspath(dev.getRuntimeClasspath());
  });

  // if you only ask for the REPL task, don't pre-compile/check the Clojure code (besides the dev one
  // for the user namespace)
  project.getGradle().getTaskGraph().whenReady(graph -> {
    // using this string concat approach to avoid realizing the task provider, if it's not needed
    if (!graph.hasTask(project.getPath() + NREPL_TASK_NAME)) {
      return;
    }
    Set<Task> selectedTasks = new HashSet<>(graph.getAllTasks());

    Queue<Task> toProcess = new LinkedList<>();
    toProcess.add(repl.get());

    Set<Task> toDisable = new HashSet<>();

    while (!toProcess.isEmpty()) {
      Task next = toProcess.remove();
      selectedTasks.remove(next);

      if (next instanceof ClojureCompile || next instanceof ClojureScriptCompile) {
        toDisable.add(next);
      } else if (next instanceof ClojureCheck && !"checkDevClojure".equals(next.getName())) {
        toDisable.add(next);
      }

      graph.getDependencies(next).forEach(toProcess::add);
    }

    // if empty, only the REPL was requested to run, so we can optimize for that use case
    if (selectedTasks.isEmpty()) {
      toDisable.forEach(task -> task.setEnabled(false));
    }
  });
}