use of org.gradle.api.tasks.SourceSet in project gradle by gradle.
the class JavaGradlePluginPlugin method configureTaskPropertiesValidation.
private void configureTaskPropertiesValidation(Project project) {
ValidateTaskProperties validator = project.getTasks().create(VALIDATE_TASK_PROPERTIES_TASK_NAME, ValidateTaskProperties.class);
validator.setGroup(PLUGIN_DEVELOPMENT_GROUP);
validator.setDescription(VALIDATE_TASK_PROPERTIES_TASK_DESCRIPTION);
validator.getOutputFile().set(project.getLayout().getBuildDirectory().file("reports/task-properties/report.txt"));
final SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
validator.setClasses(mainSourceSet.getOutput().getClassesDirs());
validator.setClasspath(mainSourceSet.getCompileClasspath());
validator.dependsOn(mainSourceSet.getOutput());
project.getTasks().getByName(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(validator);
}
use of org.gradle.api.tasks.SourceSet in project gradle by gradle.
the class JavaLibraryPlugin method addApiToMainSourceSet.
private void addApiToMainSourceSet(Project project, JavaPluginConvention convention, ConfigurationContainer configurations) {
SourceSet sourceSet = convention.getSourceSets().getByName("main");
Configuration apiConfiguration = configurations.maybeCreate(sourceSet.getApiConfigurationName());
apiConfiguration.setVisible(false);
apiConfiguration.setDescription("API dependencies for " + sourceSet + ".");
apiConfiguration.setCanBeResolved(false);
apiConfiguration.setCanBeConsumed(false);
Configuration apiElementsConfiguration = configurations.getByName(sourceSet.getApiElementsConfigurationName());
apiElementsConfiguration.extendsFrom(apiConfiguration);
final JavaCompile javaCompile = (JavaCompile) project.getTasks().getByPath(COMPILE_JAVA_TASK_NAME);
// Define a classes variant to use for compilation
ConfigurationPublications publications = apiElementsConfiguration.getOutgoing();
ConfigurationVariant variant = publications.getVariants().create("classes");
variant.getAttributes().attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_API_CLASSES));
variant.artifact(new JavaPlugin.IntermediateJavaArtifact(ArtifactTypeDefinition.JVM_CLASS_DIRECTORY, javaCompile) {
@Override
public File getFile() {
return javaCompile.getDestinationDir();
}
});
Configuration implementationConfiguration = configurations.getByName(sourceSet.getImplementationConfigurationName());
implementationConfiguration.extendsFrom(apiConfiguration);
Configuration compileConfiguration = configurations.getByName(sourceSet.getCompileConfigurationName());
apiConfiguration.extendsFrom(compileConfiguration);
}
use of org.gradle.api.tasks.SourceSet in project checkstyle-idea by jshiell.
the class CustomSourceSetCreator method establishCsAccessTestSourceSet.
public CustomSourceSetCreator establishCsAccessTestSourceSet() {
final SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
final SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
final SourceSet csaccessSourceSet = sourceSets.getByName(CSACCESS_SOURCESET_NAME);
final SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
// Create the 'csaccess' source set
final SourceSet csaccessTestSourceSet = sourceSets.create(CSACCESSTEST_SOURCESET_NAME);
csaccessTestSourceSet.setCompileClasspath(csaccessTestSourceSet.getCompileClasspath().plus(mainSourceSet.getOutput()).plus(csaccessSourceSet.getOutput()));
csaccessTestSourceSet.setRuntimeClasspath(csaccessTestSourceSet.getRuntimeClasspath().plus(mainSourceSet.getOutput()).plus(csaccessSourceSet.getOutput()));
sourceSets.add(csaccessTestSourceSet);
// Derive all its configurations from 'test' and 'csaccess'
final ConfigurationContainer configurations = project.getConfigurations();
final Configuration csaccessCompileConfig = configurations.getByName(csaccessSourceSet.getCompileConfigurationName());
final Configuration csaccessCompileOnlyConfig = configurations.getByName(csaccessSourceSet.getCompileOnlyConfigurationName());
final Configuration csaccessCompileClasspathConfig = configurations.getByName(csaccessSourceSet.getCompileClasspathConfigurationName());
final Configuration csaccessRuntimeConfig = configurations.getByName(csaccessSourceSet.getRuntimeConfigurationName());
final Configuration testCompileConfig = configurations.getByName(testSourceSet.getCompileConfigurationName());
final Configuration testCompileOnlyConfig = configurations.getByName(testSourceSet.getCompileOnlyConfigurationName());
final Configuration testCompileClasspathConfig = configurations.getByName(testSourceSet.getCompileClasspathConfigurationName());
final Configuration testRuntimeConfig = configurations.getByName(testSourceSet.getRuntimeConfigurationName());
configurations.getByName(csaccessTestSourceSet.getCompileConfigurationName()).extendsFrom(csaccessCompileConfig, testCompileConfig);
configurations.getByName(csaccessTestSourceSet.getCompileOnlyConfigurationName()).extendsFrom(csaccessCompileOnlyConfig, testCompileOnlyConfig);
configurations.getByName(csaccessTestSourceSet.getCompileClasspathConfigurationName()).extendsFrom(csaccessCompileClasspathConfig, testCompileClasspathConfig);
configurations.getByName(csaccessTestSourceSet.getRuntimeConfigurationName()).extendsFrom(csaccessRuntimeConfig, testRuntimeConfig);
// Wire task dependencies to match the classpath dependencies (arrow means "depends on"):
// - compileCsaccessTestJava -> compileCsaccessJava
// - csaccessTestClasses -> csaccessClasses
final TaskContainer tasks = project.getTasks();
tasks.getByName(csaccessTestSourceSet.getCompileJavaTaskName()).dependsOn(tasks.getByName(csaccessSourceSet.getCompileJavaTaskName()));
tasks.getByName(csaccessTestSourceSet.getClassesTaskName()).dependsOn(tasks.getByName(csaccessSourceSet.getClassesTaskName()));
return this;
}
use of org.gradle.api.tasks.SourceSet in project crnk-framework by crnk-project.
the class RuntimeClassLoaderFactory method getProjectLibraries.
public Set<File> getProjectLibraries() {
Set<File> classpath = new HashSet<>();
SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
if (sourceSets != null) {
SortedSet<String> availableSourceSetNames = sourceSets.getNames();
for (String sourceSetName : Arrays.asList("main", "test", "integrationTest")) {
if (availableSourceSetNames.contains(sourceSetName)) {
SourceSet sourceSet = sourceSets.getByName(sourceSetName);
classpath.add(sourceSet.getOutput().getClassesDir());
}
}
}
// add dependencies from configured gradle configuration to url (usually test or integrationTest)
TSGeneratorConfig generatorConfiguration = project.getExtensions().getByType(TSGeneratorConfig.class);
String configurationName = generatorConfiguration.getRuntime().getConfiguration();
ConfigurationContainer configurations = project.getConfigurations();
Configuration runtimeConfiguration = configurations.findByName(configurationName + "Runtime");
if (runtimeConfiguration == null) {
runtimeConfiguration = configurations.getByName(configurationName);
}
classpath.addAll(runtimeConfiguration.getFiles());
for (File file : classpath) {
LOGGER.debug("classpath entry: {}", file);
}
return classpath;
}
use of org.gradle.api.tasks.SourceSet in project Entitas-Java by Rubentxu.
the class TestProject method getSrcDirs.
@Override
public List<String> getSrcDirs() {
SourceSetContainer sourceSets = javaConvention.getSourceSets();
SourceSet mainSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
return mainSourceSet.getAllSource().getSrcDirs().stream().map(f -> {
try {
return f.getCanonicalPath();
} catch (IOException e) {
return "";
}
}).collect(Collectors.toList());
}
Aggregations