Search in sources :

Example 11 with JavaCompile

use of org.gradle.api.tasks.compile.JavaCompile in project gradle by gradle.

the class JavaBasePlugin method configureSourceSetDefaults.

private void configureSourceSetDefaults(Project project, final JavaPluginExtension javaPluginExtension) {
    javaPluginExtension.getSourceSets().all(sourceSet -> {
        ConventionMapping outputConventionMapping = ((IConventionAware) sourceSet.getOutput()).getConventionMapping();
        ConfigurationContainer configurations = project.getConfigurations();
        defineConfigurationsForSourceSet(sourceSet, configurations);
        definePathsForSourceSet(sourceSet, outputConventionMapping, project);
        createProcessResourcesTask(sourceSet, sourceSet.getResources(), project);
        TaskProvider<JavaCompile> compileTask = createCompileJavaTask(sourceSet, sourceSet.getJava(), project);
        createClassesTask(sourceSet, project);
        configureLibraryElements(compileTask, sourceSet, configurations, project.getObjects());
        configureTargetPlatform(compileTask, sourceSet, configurations);
        JvmPluginsHelper.configureOutputDirectoryForSourceSet(sourceSet, sourceSet.getJava(), project, compileTask, compileTask.map(JavaCompile::getOptions));
    });
}
Also used : ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) ConventionMapping(org.gradle.api.internal.ConventionMapping) IConventionAware(org.gradle.api.internal.IConventionAware) JavaCompile(org.gradle.api.tasks.compile.JavaCompile)

Example 12 with JavaCompile

use of org.gradle.api.tasks.compile.JavaCompile in project core-java by SpineEventEngine.

the class ModelVerifier method createClassLoaderForProject.

private static URLClassLoader createClassLoaderForProject(Project project) {
    final Collection<JavaCompile> tasks = allJavaCompile(project);
    final URL[] compiledCodePath = extractDestinationDirs(tasks);
    log().debug("Initializing ClassLoader for URLs: {}", deepToString(compiledCodePath));
    try {
        // Caught exception.
        @SuppressWarnings("ClassLoaderInstantiation") final URLClassLoader result = new URLClassLoader(compiledCodePath, ModelVerifier.class.getClassLoader());
        return result;
    } catch (SecurityException e) {
        throw new IllegalStateException("Cannot analyze project source code.", e);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) URL(java.net.URL)

Example 13 with JavaCompile

use of org.gradle.api.tasks.compile.JavaCompile in project gradle by gradle.

the class JavaBasePlugin method createCompileJavaTaskForBinary.

private void createCompileJavaTaskForBinary(final SourceSet sourceSet, final SourceDirectorySet sourceDirectorySet, final Project target) {
    JavaCompile compileTask = target.getTasks().create(sourceSet.getCompileJavaTaskName(), JavaCompile.class);
    compileTask.setDescription("Compiles " + sourceDirectorySet + ".");
    compileTask.setSource(sourceDirectorySet);
    ConventionMapping conventionMapping = compileTask.getConventionMapping();
    conventionMapping.map("classpath", new Callable<Object>() {

        public Object call() throws Exception {
            return sourceSet.getCompileClasspath();
        }
    });
    SourceSetUtil.configureAnnotationProcessorPath(sourceSet, compileTask.getOptions(), target);
    SourceSetUtil.configureOutputDirectoryForSourceSet(sourceSet, sourceDirectorySet, compileTask, target);
}
Also used : DslObject(org.gradle.api.internal.plugins.DslObject) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) ConventionMapping(org.gradle.api.internal.ConventionMapping)

Example 14 with JavaCompile

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

the class JavaPluginAction method configureAdditionalMetadataLocations.

private void configureAdditionalMetadataLocations(JavaCompile compile) {
    SourceSetContainer sourceSets = compile.getProject().getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
    sourceSets.stream().filter((candidate) -> candidate.getCompileJavaTaskName().equals(compile.getName())).map((match) -> match.getResources().getSrcDirs()).findFirst().ifPresent((locations) -> compile.doFirst(new AdditionalMetadataLocationsConfigurer(locations)));
}
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) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer)

Example 15 with JavaCompile

use of org.gradle.api.tasks.compile.JavaCompile in project gradle-apt-plugin by tbroyer.

the class AptPlugin34to42 method configureCompileTaskForSourceSet.

@Override
protected void configureCompileTaskForSourceSet(Project project, final SourceSet sourceSet, AbstractCompile task, CompileOptions compileOptions) {
    if (!(task instanceof JavaCompile)) {
        prevImpl.configureCompileTaskForSourceSet(project, sourceSet, task, compileOptions);
        return;
    }
    compileOptions.setAnnotationProcessorPath(project.files(new Callable<FileCollection>() {

        @Override
        public FileCollection call() {
            return new DslObject(sourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class).getAnnotationProcessorPath();
        }
    }));
    task.getConvention().getPlugin(AptPlugin.AptConvention.class).setGeneratedSourcesDestinationDir(new Callable<File>() {

        @Override
        public File call() {
            return new DslObject(sourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
        }
    });
}
Also used : DslObject(org.gradle.api.internal.plugins.DslObject) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) File(java.io.File) Callable(java.util.concurrent.Callable)

Aggregations

JavaCompile (org.gradle.api.tasks.compile.JavaCompile)17 File (java.io.File)10 SourceSet (org.gradle.api.tasks.SourceSet)7 Task (org.gradle.api.Task)6 Configuration (org.gradle.api.artifacts.Configuration)6 Action (org.gradle.api.Action)5 FileCollection (org.gradle.api.file.FileCollection)5 Jar (org.gradle.api.tasks.bundling.Jar)5 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)4 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)3 IdlOptions (com.linkedin.pegasus.gradle.PegasusOptions.IdlOptions)2 CompatibilityLogChecker (com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker)2 ChangedFileReportTask (com.linkedin.pegasus.gradle.tasks.ChangedFileReportTask)2 CheckIdlTask (com.linkedin.pegasus.gradle.tasks.CheckIdlTask)2 CheckPegasusSnapshotTask (com.linkedin.pegasus.gradle.tasks.CheckPegasusSnapshotTask)2 CheckRestModelTask (com.linkedin.pegasus.gradle.tasks.CheckRestModelTask)2 CheckSnapshotTask (com.linkedin.pegasus.gradle.tasks.CheckSnapshotTask)2 GenerateAvroSchemaTask (com.linkedin.pegasus.gradle.tasks.GenerateAvroSchemaTask)2 GenerateDataTemplateTask (com.linkedin.pegasus.gradle.tasks.GenerateDataTemplateTask)2 GeneratePegasusSnapshotTask (com.linkedin.pegasus.gradle.tasks.GeneratePegasusSnapshotTask)2