Search in sources :

Example 61 with SourceSet

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

the class BootRun method sourceResources.

/**
 * Adds the {@link SourceDirectorySet#getSrcDirs() source directories} of the given
 * {@code sourceSet's} {@link SourceSet#getResources() resources} to the start of the
 * classpath in place of the {@link SourceSet#getOutput output's}
 * {@link SourceSetOutput#getResourcesDir() resources directory}.
 * @param sourceSet the source set
 */
public void sourceResources(SourceSet sourceSet) {
    File resourcesDir = sourceSet.getOutput().getResourcesDir();
    Set<File> srcDirs = sourceSet.getResources().getSrcDirs();
    setClasspath(getProject().files(srcDirs, getClasspath()).filter((file) -> !file.equals(resourcesDir)));
}
Also used : SourceSetOutput(org.gradle.api.tasks.SourceSetOutput) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) Property(org.gradle.api.provider.Property) Set(java.util.Set) JavaExec(org.gradle.api.tasks.JavaExec) Input(org.gradle.api.tasks.Input) JavaLauncher(org.gradle.jvm.toolchain.JavaLauncher) Method(java.lang.reflect.Method) File(java.io.File) DisableCachingByDefault(org.gradle.work.DisableCachingByDefault) SourceSet(org.gradle.api.tasks.SourceSet) File(java.io.File)

Example 62 with SourceSet

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

the class JavaPluginAction method configureBootJarTask.

private TaskProvider<BootJar> configureBootJarTask(Project project) {
    SourceSet mainSourceSet = javaPluginExtension(project).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    Configuration developmentOnly = project.getConfigurations().getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
    Configuration productionRuntimeClasspath = project.getConfigurations().getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
    Callable<FileCollection> classpath = () -> mainSourceSet.getRuntimeClasspath().minus((developmentOnly.minus(productionRuntimeClasspath))).filter(new JarTypeFileSpec());
    TaskProvider<ResolveMainClassName> resolveMainClassName = ResolveMainClassName.registerForTask(SpringBootPlugin.BOOT_JAR_TASK_NAME, project, classpath);
    return project.getTasks().register(SpringBootPlugin.BOOT_JAR_TASK_NAME, BootJar.class, (bootJar) -> {
        bootJar.setDescription("Assembles an executable jar archive containing the main classes and their dependencies.");
        bootJar.setGroup(BasePlugin.BUILD_GROUP);
        bootJar.classpath(classpath);
        Provider<String> manifestStartClass = project.provider(() -> (String) bootJar.getManifest().getAttributes().get("Start-Class"));
        bootJar.getMainClass().convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent() ? manifestStartClass : resolveMainClassName.get().readMainClassName()));
    });
}
Also used : BootRun(org.springframework.boot.gradle.tasks.run.BootRun) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) Callable(java.util.concurrent.Callable) JavaPlugin(org.gradle.api.plugins.JavaPlugin) BasePlugin(org.gradle.api.plugins.BasePlugin) FileCollection(org.gradle.api.file.FileCollection) ApplicationPlugin(org.gradle.api.plugins.ApplicationPlugin) LibraryElements(org.gradle.api.attributes.LibraryElements) SourceSet(org.gradle.api.tasks.SourceSet) BootBuildImage(org.springframework.boot.gradle.tasks.bundling.BootBuildImage) Bundling(org.gradle.api.attributes.Bundling) Configuration(org.gradle.api.artifacts.Configuration) Task(org.gradle.api.Task) Provider(org.gradle.api.provider.Provider) AttributeContainer(org.gradle.api.attributes.AttributeContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) BootJar(org.springframework.boot.gradle.tasks.bundling.BootJar) Usage(org.gradle.api.attributes.Usage) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) Jar(org.gradle.api.tasks.bundling.Jar) Action(org.gradle.api.Action) Project(org.gradle.api.Project) Set(java.util.Set) File(java.io.File) JavaToolchainSpec(org.gradle.jvm.toolchain.JavaToolchainSpec) List(java.util.List) ObjectFactory(org.gradle.api.model.ObjectFactory) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) Collections(java.util.Collections) Plugin(org.gradle.api.Plugin) StringUtils(org.springframework.util.StringUtils) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) FileCollection(org.gradle.api.file.FileCollection)

Example 63 with SourceSet

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

the class JavaPlugin method apply.

@Override
public void apply(final Project project) {
    if (project.getPluginManager().hasPlugin("java-platform")) {
        throw new IllegalStateException("The \"java\" or \"java-library\" plugin cannot be applied together with the \"java-platform\" plugin. " + "A project is either a platform or a library but cannot be both at the same time.");
    }
    final ProjectInternal projectInternal = (ProjectInternal) project;
    project.getPluginManager().apply(JavaBasePlugin.class);
    project.getPluginManager().apply("org.gradle.jvm-test-suite");
    JavaPluginExtension javaExtension = project.getExtensions().getByType(JavaPluginExtension.class);
    projectInternal.getServices().get(ComponentRegistry.class).setMainComponent(new BuildableJavaComponentImpl(project, javaExtension));
    BuildOutputCleanupRegistry buildOutputCleanupRegistry = projectInternal.getServices().get(BuildOutputCleanupRegistry.class);
    SourceSet mainSourceSet = javaExtension.getSourceSets().create(SourceSet.MAIN_SOURCE_SET_NAME);
    configureSourceSets(project, javaExtension, buildOutputCleanupRegistry, mainSourceSet);
    configureConfigurations(project, javaExtension, mainSourceSet);
    configureJavadocTask(project, javaExtension);
    configureArchivesAndComponent(project, javaExtension);
    configureBuild(project);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) BuildOutputCleanupRegistry(org.gradle.internal.execution.BuildOutputCleanupRegistry) ComponentRegistry(org.gradle.api.internal.component.ComponentRegistry) ProjectInternal(org.gradle.api.internal.project.ProjectInternal)

Example 64 with SourceSet

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

the class JavaPlugin method configureJavadocTask.

private void configureJavadocTask(Project project, JavaPluginExtension javaPluginExtension) {
    SourceSet main = mainSourceSetOf(javaPluginExtension);
    configureJavaDocTask(null, main, project.getTasks(), javaPluginExtension);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet)

Example 65 with SourceSet

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

the class JavaTestFixturesPlugin method createImplicitTestFixturesDependencies.

private void createImplicitTestFixturesDependencies(Project project, JavaPluginExtension extension) {
    DependencyHandler dependencies = project.getDependencies();
    dependencies.add(TEST_FIXTURES_API, dependencies.create(project));
    SourceSet testSourceSet = findTestSourceSet(extension);
    ProjectDependency testDependency = (ProjectDependency) dependencies.add(testSourceSet.getImplementationConfigurationName(), dependencies.create(project));
    testDependency.capabilities(new ProjectTestFixtures(project));
    // Overwrite what the Java plugin defines for test, in order to avoid duplicate classes
    // see gradle/gradle#10872
    ConfigurationContainer configurations = project.getConfigurations();
    testSourceSet.setCompileClasspath(project.getObjects().fileCollection().from(configurations.getByName(TEST_COMPILE_CLASSPATH_CONFIGURATION_NAME)));
    testSourceSet.setRuntimeClasspath(project.getObjects().fileCollection().from(testSourceSet.getOutput(), configurations.getByName(TEST_RUNTIME_CLASSPATH_CONFIGURATION_NAME)));
}
Also used : DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) SourceSet(org.gradle.api.tasks.SourceSet) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) ProjectTestFixtures(org.gradle.internal.component.external.model.ProjectTestFixtures)

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