Search in sources :

Example 26 with SourceSet

use of org.gradle.api.tasks.SourceSet in project spring-boot by spring-projects.

the class ConfigurationPropertiesPlugin method configureAdditionalMetadataLocationsCompilerArgument.

private void configureAdditionalMetadataLocationsCompilerArgument(Project project) {
    JavaCompile compileJava = project.getTasks().withType(JavaCompile.class).getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME);
    ((Task) compileJava).getInputs().files(project.getTasks().getByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME)).withPathSensitivity(PathSensitivity.RELATIVE).withPropertyName("processed resources");
    SourceSet mainSourceSet = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    compileJava.getOptions().getCompilerArgs().add("-Aorg.springframework.boot.configurationprocessor.additionalMetadataLocations=" + StringUtils.collectionToCommaDelimitedString(mainSourceSet.getResources().getSourceDirectories().getFiles().stream().map(project.getRootProject()::relativePath).collect(Collectors.toSet())));
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) JavaCompile(org.gradle.api.tasks.compile.JavaCompile)

Example 27 with SourceSet

use of org.gradle.api.tasks.SourceSet in project spring-boot by spring-projects.

the class ConfigurationPropertiesPlugin method addMetadataArtifact.

private void addMetadataArtifact(Project project) {
    SourceSet mainSourceSet = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    project.getConfigurations().maybeCreate(CONFIGURATION_PROPERTIES_METADATA_CONFIGURATION_NAME);
    project.afterEvaluate((evaluatedProject) -> evaluatedProject.getArtifacts().add(CONFIGURATION_PROPERTIES_METADATA_CONFIGURATION_NAME, mainSourceSet.getJava().getDestinationDirectory().dir("META-INF/spring-configuration-metadata.json"), (artifact) -> artifact.builtBy(evaluatedProject.getTasks().getByName(mainSourceSet.getClassesTaskName()))));
}
Also used : JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Configuration(org.gradle.api.artifacts.Configuration) Task(org.gradle.api.Task) Project(org.gradle.api.Project) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) PathSensitivity(org.gradle.api.tasks.PathSensitivity) JavaPlugin(org.gradle.api.plugins.JavaPlugin) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Plugin(org.gradle.api.Plugin) SourceSet(org.gradle.api.tasks.SourceSet) StringUtils(org.springframework.util.StringUtils) SourceSet(org.gradle.api.tasks.SourceSet)

Example 28 with SourceSet

use of org.gradle.api.tasks.SourceSet in project gradle by gradle.

the class GroovyPlugin method configureGroovydoc.

private void configureGroovydoc(final Project project) {
    Groovydoc groovyDoc = project.getTasks().create(GROOVYDOC_TASK_NAME, Groovydoc.class);
    groovyDoc.setDescription("Generates Groovydoc API documentation for the main source code.");
    groovyDoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
    JavaPluginConvention convention = project.getConvention().getPlugin(JavaPluginConvention.class);
    SourceSet sourceSet = convention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    groovyDoc.setClasspath(sourceSet.getOutput().plus(sourceSet.getCompileClasspath()));
    GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class);
    groovyDoc.setSource(groovySourceSet.getGroovy());
}
Also used : GroovySourceSet(org.gradle.api.tasks.GroovySourceSet) SourceSet(org.gradle.api.tasks.SourceSet) GroovySourceSet(org.gradle.api.tasks.GroovySourceSet) DslObject(org.gradle.api.internal.plugins.DslObject) Groovydoc(org.gradle.api.tasks.javadoc.Groovydoc)

Example 29 with SourceSet

use of org.gradle.api.tasks.SourceSet in project gradle by gradle.

the class JavaBasePlugin method configureSourceSetDefaults.

private BridgedBinaries configureSourceSetDefaults(final JavaPluginConvention pluginConvention) {
    final Project project = pluginConvention.getProject();
    final List<ClassDirectoryBinarySpecInternal> binaries = Lists.newArrayList();
    pluginConvention.getSourceSets().all(new Action<SourceSet>() {

        public void execute(final SourceSet sourceSet) {
            ConventionMapping outputConventionMapping = ((IConventionAware) sourceSet.getOutput()).getConventionMapping();
            ConfigurationContainer configurations = project.getConfigurations();
            defineConfigurationsForSourceSet(sourceSet, configurations);
            definePathsForSourceSet(sourceSet, outputConventionMapping, project);
            createProcessResourcesTaskForBinary(sourceSet, sourceSet.getResources(), project);
            createCompileJavaTaskForBinary(sourceSet, sourceSet.getJava(), project);
            createBinaryLifecycleTask(sourceSet, project);
            DefaultComponentSpecIdentifier binaryId = new DefaultComponentSpecIdentifier(project.getPath(), sourceSet.getName());
            ClassDirectoryBinarySpecInternal binary = instantiator.newInstance(DefaultClassDirectoryBinarySpec.class, binaryId, sourceSet, javaToolChain, DefaultJavaPlatform.current(), instantiator, taskFactory);
            Classpath compileClasspath = new SourceSetCompileClasspath(sourceSet);
            DefaultJavaSourceSet javaSourceSet = instantiator.newInstance(DefaultJavaSourceSet.class, binaryId.child("java"), sourceSet.getJava(), compileClasspath);
            JvmResourceSet resourceSet = instantiator.newInstance(DefaultJvmResourceSet.class, binaryId.child("resources"), sourceSet.getResources());
            binary.addSourceSet(javaSourceSet);
            binary.addSourceSet(resourceSet);
            attachTasksToBinary(binary, sourceSet, project);
            binaries.add(binary);
        }
    });
    return new BridgedBinaries(binaries);
}
Also used : ClassDirectoryBinarySpecInternal(org.gradle.api.internal.jvm.ClassDirectoryBinarySpecInternal) ConventionMapping(org.gradle.api.internal.ConventionMapping) SourceSetCompileClasspath(org.gradle.api.internal.tasks.SourceSetCompileClasspath) JvmResourceSet(org.gradle.language.jvm.JvmResourceSet) DefaultJvmResourceSet(org.gradle.api.internal.java.DefaultJvmResourceSet) Project(org.gradle.api.Project) ProjectSourceSet(org.gradle.language.base.ProjectSourceSet) DefaultJavaSourceSet(org.gradle.api.internal.java.DefaultJavaSourceSet) SourceSet(org.gradle.api.tasks.SourceSet) DefaultJvmResourceSet(org.gradle.api.internal.java.DefaultJvmResourceSet) DefaultJavaSourceSet(org.gradle.api.internal.java.DefaultJavaSourceSet) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) DefaultClassDirectoryBinarySpec(org.gradle.api.internal.jvm.DefaultClassDirectoryBinarySpec) Classpath(org.gradle.jvm.Classpath) SourceSetCompileClasspath(org.gradle.api.internal.tasks.SourceSetCompileClasspath) DefaultComponentSpecIdentifier(org.gradle.platform.base.internal.DefaultComponentSpecIdentifier)

Example 30 with SourceSet

use of org.gradle.api.tasks.SourceSet in project gradle by gradle.

the class DefaultSourceSetContainerTest method createsASourceSet.

@Test
public void createsASourceSet() {
    SourceSet set = container.create("main");
    assertThat(set, instanceOf(DefaultSourceSet.class));
    assertThat(set.getName(), equalTo("main"));
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) Test(org.junit.Test)

Aggregations

SourceSet (org.gradle.api.tasks.SourceSet)55 File (java.io.File)28 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)24 Project (org.gradle.api.Project)20 Configuration (org.gradle.api.artifacts.Configuration)19 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)18 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)15 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)14 List (java.util.List)13 Task (org.gradle.api.Task)13 JavaPlugin (org.gradle.api.plugins.JavaPlugin)12 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)12 Set (java.util.Set)11 Collectors (java.util.stream.Collectors)11 Collections (java.util.Collections)10 Action (org.gradle.api.Action)10 Plugin (org.gradle.api.Plugin)10 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)10 Jar (org.gradle.api.tasks.bundling.Jar)10 HashSet (java.util.HashSet)9