Search in sources :

Example 66 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) {
    project.getTasks().register(GROOVYDOC_TASK_NAME, Groovydoc.class, groovyDoc -> {
        groovyDoc.setDescription("Generates Groovydoc API documentation for the main source code.");
        groovyDoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);
        SourceSet sourceSet = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
        groovyDoc.setClasspath(sourceSet.getOutput().plus(sourceSet.getCompileClasspath()));
        SourceDirectorySet groovySourceSet = sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class);
        groovyDoc.setSource(groovySourceSet);
    });
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet)

Example 67 with SourceSet

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

the class JavaLibraryPlugin method apply.

@Override
public void apply(Project project) {
    project.getPluginManager().apply(JavaPlugin.class);
    SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
    ConfigurationContainer configurations = project.getConfigurations();
    SourceSet sourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    JvmPluginsHelper.addApiToSourceSet(sourceSet, configurations);
    makeCompileOnlyApiVisibleToTests(configurations);
    jvmEcosystemUtilities.configureClassesDirectoryVariant(sourceSet.getApiElementsConfigurationName(), sourceSet);
    deprecateConfigurationsForDeclaration(sourceSets, configurations);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer)

Example 68 with SourceSet

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

the class DefaultJavaPluginExtension method withSourcesJar.

public void withSourcesJar() {
    TaskContainer tasks = project.getTasks();
    ConfigurationContainer configurations = project.getConfigurations();
    SourceSet main = getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    configureDocumentationVariantWithArtifact(SOURCES_ELEMENTS_CONFIGURATION_NAME, null, SOURCES, ImmutableList.of(), main.getSourcesJarTaskName(), main.getAllSource(), findJavaComponent(components), configurations, tasks, objectFactory, project.getFileResolver());
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) TaskContainer(org.gradle.api.tasks.TaskContainer) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer)

Example 69 with SourceSet

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

the class DefaultJvmVariantBuilder method build.

void build() {
    SourceSet sourceSet = this.sourceSet == null ? sourceSets.maybeCreate(name) : this.sourceSet;
    boolean mainSourceSet = SourceSet.isMain(sourceSet);
    String apiConfigurationName;
    String implementationConfigurationName;
    String apiElementsConfigurationName;
    String runtimeElementsConfigurationName;
    String compileOnlyConfigurationName;
    String compileOnlyApiConfigurationName;
    String runtimeOnlyConfigurationName;
    if (mainSourceSet) {
        apiConfigurationName = name + "Api";
        implementationConfigurationName = name + "Implementation";
        apiElementsConfigurationName = apiConfigurationName + "Elements";
        runtimeElementsConfigurationName = name + "RuntimeElements";
        compileOnlyConfigurationName = name + "CompileOnly";
        compileOnlyApiConfigurationName = name + "CompileOnlyApi";
        runtimeOnlyConfigurationName = name + "RuntimeOnly";
    } else {
        apiConfigurationName = sourceSet.getApiConfigurationName();
        implementationConfigurationName = sourceSet.getImplementationConfigurationName();
        apiElementsConfigurationName = sourceSet.getApiElementsConfigurationName();
        runtimeElementsConfigurationName = sourceSet.getRuntimeElementsConfigurationName();
        compileOnlyConfigurationName = sourceSet.getCompileOnlyConfigurationName();
        compileOnlyApiConfigurationName = sourceSet.getCompileOnlyApiConfigurationName();
        runtimeOnlyConfigurationName = sourceSet.getRuntimeOnlyConfigurationName();
    }
    String displayName = this.displayName == null ? name : this.displayName;
    // In the general case, the following configurations are already created
    // but if we're using the "main" source set, it means that the component we're creating shares
    // the same source set (main) but declares its dependencies in its own buckets, so we need
    // to create them
    Configuration implementation = bucket("Implementation", implementationConfigurationName, displayName);
    Configuration compileOnly = bucket("Compile-Only", compileOnlyConfigurationName, displayName);
    Configuration compileOnlyApi = bucket("Compile-Only API", compileOnlyApiConfigurationName, displayName);
    Configuration runtimeOnly = bucket("Runtime-Only", runtimeOnlyConfigurationName, displayName);
    TaskProvider<Task> jarTask = registerOrGetJarTask(sourceSet, displayName);
    Configuration api = exposeApi ? bucket("API", apiConfigurationName, displayName) : null;
    Configuration apiElements = exposeApi ? jvmPluginServices.createOutgoingElements(apiElementsConfigurationName, builder -> {
        builder.fromSourceSet(sourceSet).providesApi().withDescription("API elements for " + displayName).extendsFrom(api, compileOnlyApi).withCapabilities(capabilities).withClassDirectoryVariant().artifact(jarTask);
    }) : null;
    if (exposeApi) {
        implementation.extendsFrom(api);
    }
    Configuration runtimeElements = jvmPluginServices.createOutgoingElements(runtimeElementsConfigurationName, builder -> {
        builder.fromSourceSet(sourceSet).providesRuntime().withDescription("Runtime elements for " + displayName).extendsFrom(implementation, runtimeOnly).withCapabilities(capabilities).artifact(jarTask);
    });
    if (mainSourceSet) {
        // we need to wire the compile only and runtime only to the classpath configurations
        configurations.getByName(sourceSet.getCompileClasspathConfigurationName()).extendsFrom(implementation, compileOnly);
        configurations.getByName(sourceSet.getRuntimeClasspathConfigurationName()).extendsFrom(implementation, runtimeOnly);
        // and we also want the feature dependencies to be available on the test classpath
        configurations.getByName(JavaPlugin.TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME).extendsFrom(implementation, compileOnlyApi);
        configurations.getByName(JavaPlugin.TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME).extendsFrom(implementation, runtimeOnly);
    }
    final AdhocComponentWithVariants component = findJavaComponent();
    JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
    configureJavaDocTask(name, sourceSet, tasks, javaPluginExtension);
    if (javadocJar) {
        configureDocumentationVariantWithArtifact(sourceSet.getJavadocElementsConfigurationName(), mainSourceSet ? null : name, displayName, JAVADOC, sourceSet.getJavadocJarTaskName(), tasks.named(sourceSet.getJavadocTaskName()), component);
    }
    if (sourcesJar) {
        configureDocumentationVariantWithArtifact(sourceSet.getSourcesElementsConfigurationName(), mainSourceSet ? null : name, displayName, SOURCES, sourceSet.getSourcesJarTaskName(), sourceSet.getAllSource(), component);
    }
    if (published && component != null) {
        if (apiElements != null) {
            component.addVariantsFromConfiguration(apiElements, new JavaConfigurationVariantMapping("compile", true));
        }
        component.addVariantsFromConfiguration(runtimeElements, new JavaConfigurationVariantMapping("runtime", true));
    }
}
Also used : SOURCES(org.gradle.api.attributes.DocsType.SOURCES) JavaPlugin(org.gradle.api.plugins.JavaPlugin) BasePlugin(org.gradle.api.plugins.BasePlugin) AdhocComponentWithVariants(org.gradle.api.component.AdhocComponentWithVariants) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) LifecycleBasePlugin(org.gradle.language.base.plugins.LifecycleBasePlugin) Task(org.gradle.api.Task) Lists(com.google.common.collect.Lists) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) JavaConfigurationVariantMapping(org.gradle.api.plugins.internal.JavaConfigurationVariantMapping) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) TextUtil(org.gradle.util.internal.TextUtil) SoftwareComponentContainer(org.gradle.api.component.SoftwareComponentContainer) ProjectDerivedCapability(org.gradle.internal.component.external.model.ProjectDerivedCapability) Nullable(javax.annotation.Nullable) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) Jar(org.gradle.api.tasks.bundling.Jar) JAVADOC(org.gradle.api.attributes.DocsType.JAVADOC) List(java.util.List) JvmPluginsHelper.configureJavaDocTask(org.gradle.api.plugins.internal.JvmPluginsHelper.configureJavaDocTask) Capability(org.gradle.api.capabilities.Capability) TaskContainer(org.gradle.api.tasks.TaskContainer) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) InvalidUserDataException(org.gradle.api.InvalidUserDataException) SoftwareComponent(org.gradle.api.component.SoftwareComponent) SourceSet(org.gradle.api.tasks.SourceSet) Task(org.gradle.api.Task) JvmPluginsHelper.configureJavaDocTask(org.gradle.api.plugins.internal.JvmPluginsHelper.configureJavaDocTask) AdhocComponentWithVariants(org.gradle.api.component.AdhocComponentWithVariants) Configuration(org.gradle.api.artifacts.Configuration) JavaConfigurationVariantMapping(org.gradle.api.plugins.internal.JavaConfigurationVariantMapping) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension)

Example 70 with SourceSet

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

the class DefaultJvmPluginServices method registerClassesDirVariant.

private void registerClassesDirVariant(final SourceSet sourceSet, Configuration configuration) {
    // Define a classes variant to use for compilation
    ConfigurationPublications publications = configuration.getOutgoing();
    ConfigurationVariantInternal variant = (ConfigurationVariantInternal) publications.getVariants().maybeCreate("classes");
    variant.setDescription("Directories containing compiled class files for " + sourceSet.getName() + ".");
    variant.getAttributes().attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements.class, LibraryElements.CLASSES));
    variant.artifactsProvider(new Factory<List<PublishArtifact>>() {

        @Nullable
        @Override
        public List<PublishArtifact> create() {
            Set<File> classesDirs = sourceSet.getOutput().getClassesDirs().getFiles();
            DefaultSourceSetOutput output = Cast.uncheckedCast(sourceSet.getOutput());
            TaskDependency classesContributors = output.getClassesContributors();
            ImmutableList.Builder<PublishArtifact> artifacts = ImmutableList.builderWithExpectedSize(classesDirs.size());
            for (File classesDir : classesDirs) {
                // this is an approximation: all "compiled" sources will use the same task dependency
                artifacts.add(new JvmPluginsHelper.IntermediateJavaArtifact(ArtifactTypeDefinition.JVM_CLASS_DIRECTORY, classesContributors) {

                    @Override
                    public File getFile() {
                        return classesDir;
                    }
                });
            }
            return artifacts.build();
        }
    });
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Set(java.util.Set) SourceSet(org.gradle.api.tasks.SourceSet) HashSet(java.util.HashSet) ConfigurationVariantInternal(org.gradle.api.internal.artifacts.ConfigurationVariantInternal) ConfigurationPublications(org.gradle.api.artifacts.ConfigurationPublications) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultSourceSetOutput(org.gradle.api.internal.tasks.DefaultSourceSetOutput) LibraryElements(org.gradle.api.attributes.LibraryElements) File(java.io.File) Nullable(javax.annotation.Nullable)

Aggregations

SourceSet (org.gradle.api.tasks.SourceSet)76 File (java.io.File)34 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)31 Configuration (org.gradle.api.artifacts.Configuration)26 Project (org.gradle.api.Project)24 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)23 Task (org.gradle.api.Task)18 List (java.util.List)17 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)17 JavaPlugin (org.gradle.api.plugins.JavaPlugin)16 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)16 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)16 Plugin (org.gradle.api.Plugin)15 FileCollection (org.gradle.api.file.FileCollection)15 Action (org.gradle.api.Action)14 TaskProvider (org.gradle.api.tasks.TaskProvider)14 Set (java.util.Set)13 Jar (org.gradle.api.tasks.bundling.Jar)13 Collections (java.util.Collections)12 Collectors (java.util.stream.Collectors)12