コード例 #1
0
  protected SourceSet addSourceSetTestIntegration(Project project) {
    SourceSet testIntegrationSourceSet =
        GradleUtil.addSourceSet(project, TEST_INTEGRATION_SOURCE_SET_NAME);

    Configuration testIntegrationCompileConfiguration =
        GradleUtil.getConfiguration(
            project, testIntegrationSourceSet.getCompileConfigurationName());

    Configuration testCompileConfiguration =
        GradleUtil.getConfiguration(project, JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME);

    testIntegrationCompileConfiguration.extendsFrom(testCompileConfiguration);

    Configuration testIntegrationRuntimeConfiguration =
        GradleUtil.getConfiguration(
            project, testIntegrationSourceSet.getRuntimeConfigurationName());

    Configuration testRuntimeConfiguration =
        GradleUtil.getConfiguration(project, JavaPlugin.TEST_RUNTIME_CONFIGURATION_NAME);

    testIntegrationRuntimeConfiguration.extendsFrom(
        testRuntimeConfiguration, testIntegrationCompileConfiguration);

    SourceSet mainSourceSet = GradleUtil.getSourceSet(project, SourceSet.MAIN_SOURCE_SET_NAME);

    FileCollection compileClasspath = testIntegrationSourceSet.getCompileClasspath();

    testIntegrationSourceSet.setCompileClasspath(compileClasspath.plus(mainSourceSet.getOutput()));

    FileCollection runtimeClasspath = testIntegrationSourceSet.getRuntimeClasspath();

    testIntegrationSourceSet.setRuntimeClasspath(runtimeClasspath.plus(mainSourceSet.getOutput()));

    return testIntegrationSourceSet;
  }
コード例 #2
0
 private ClassLoader buildRuntimeScopeClassLoader() {
   final ArrayList<URL> classPathUrls = new ArrayList<URL>();
   final SourceSet mainSourceSet =
       project
           .getConvention()
           .getPlugin(JavaPluginConvention.class)
           .getSourceSets()
           .findByName(SourceSet.MAIN_SOURCE_SET_NAME);
   for (File file : mainSourceSet.getRuntimeClasspath()) {
     try {
       classPathUrls.add(file.toURI().toURL());
     } catch (MalformedURLException e) {
       throw new InjectionException(
           "Could not determine artifact URL [" + file.getPath() + "]", e);
     }
   }
   return new URLClassLoader(
       classPathUrls.toArray(new URL[classPathUrls.size()]), getClass().getClassLoader());
 }