Search in sources :

Example 1 with GroovyCompile

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

the class AptPlugin method apply.

@Override
public void apply(final Project project) {
    configureCompileTasks(project, JavaCompile.class, new GetCompileOptions<JavaCompile>() {

        @Override
        public CompileOptions getCompileOptions(JavaCompile task) {
            return task.getOptions();
        }
    });
    configureCompileTasks(project, GroovyCompile.class, new GetCompileOptions<GroovyCompile>() {

        @Override
        public CompileOptions getCompileOptions(GroovyCompile task) {
            return task.getOptions();
        }
    });
    project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {

        @Override
        public void execute(JavaBasePlugin javaBasePlugin) {
            final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            javaConvention.getSourceSets().all(new Action<SourceSet>() {

                @Override
                public void execute(final SourceSet sourceSet) {
                    AptSourceSetConvention convention = IMPL.createAptSourceSetConvention(project, sourceSet);
                    new DslObject(sourceSet).getConvention().getPlugins().put(PLUGIN_ID, convention);
                    AptSourceSetOutputConvention outputConvention = new AptSourceSetOutputConvention(project);
                    outputConvention.setGeneratedSourcesDir(new File(project.getBuildDir(), "generated/source/apt/" + sourceSet.getName()));
                    new DslObject(sourceSet.getOutput()).getConvention().getPlugins().put(PLUGIN_ID, outputConvention);
                    ensureConfigurations(project, sourceSet, convention);
                    configureCompileTaskForSourceSet(project, sourceSet, sourceSet.getCompileJavaTaskName(), JavaCompile.class, new GetCompileOptions<JavaCompile>() {

                        @Override
                        public CompileOptions getCompileOptions(JavaCompile task) {
                            return task.getOptions();
                        }
                    });
                }
            });
        }
    });
    project.getPlugins().withType(GroovyBasePlugin.class, new Action<GroovyBasePlugin>() {

        @Override
        public void execute(GroovyBasePlugin groovyBasePlugin) {
            JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
            javaConvention.getSourceSets().all(new Action<SourceSet>() {

                @Override
                public void execute(SourceSet sourceSet) {
                    AptSourceSetConvention convention = new DslObject(sourceSet).getConvention().getPlugin(AptSourceSetConvention.class);
                    configureCompileTaskForSourceSet(project, sourceSet, sourceSet.getCompileTaskName("groovy"), GroovyCompile.class, new GetCompileOptions<GroovyCompile>() {

                        @Override
                        public CompileOptions getCompileOptions(GroovyCompile task) {
                            return task.getOptions();
                        }
                    });
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) DslObject(org.gradle.api.internal.plugins.DslObject) GroovyCompile(org.gradle.api.tasks.compile.GroovyCompile) CompileOptions(org.gradle.api.tasks.compile.CompileOptions) SourceSet(org.gradle.api.tasks.SourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) GroovyBasePlugin(org.gradle.api.plugins.GroovyBasePlugin) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) File(java.io.File)

Example 2 with GroovyCompile

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

the class GroovyBasePlugin method configureSourceSetDefaults.

@SuppressWarnings("deprecation")
private void configureSourceSetDefaults() {
    javaPluginExtension().getSourceSets().all(sourceSet -> {
        final DefaultGroovySourceSet groovySourceSet = new DefaultGroovySourceSet("groovy", ((DefaultSourceSet) sourceSet).getDisplayName(), objectFactory);
        addSourceSetExtension(sourceSet, groovySourceSet);
        final SourceDirectorySet groovySource = groovySourceSet.getGroovy();
        groovySource.srcDir("src/" + sourceSet.getName() + "/groovy");
        // Explicitly capture only a FileCollection in the lambda below for compatibility with configuration-cache.
        @SuppressWarnings("UnnecessaryLocalVariable") final FileCollection groovySourceFiles = groovySource;
        sourceSet.getResources().getFilter().exclude(spec(element -> groovySourceFiles.contains(element.getFile())));
        sourceSet.getAllJava().source(groovySource);
        sourceSet.getAllSource().source(groovySource);
        final TaskProvider<GroovyCompile> compileTask = project.getTasks().register(sourceSet.getCompileTaskName("groovy"), GroovyCompile.class, compile -> {
            JvmPluginsHelper.configureForSourceSet(sourceSet, groovySource, compile, compile.getOptions(), project);
            compile.setDescription("Compiles the " + sourceSet.getName() + " Groovy source.");
            compile.setSource(groovySource);
            compile.getJavaLauncher().convention(getToolchainTool(project, JavaToolchainService::launcherFor));
            compile.getGroovyOptions().getDisabledGlobalASTTransformations().convention(Sets.newHashSet("groovy.grape.GrabAnnotationTransformation"));
        });
        String compileClasspathConfigurationName = sourceSet.getCompileClasspathConfigurationName();
        JvmPluginsHelper.configureOutputDirectoryForSourceSet(sourceSet, groovySource, project, compileTask, compileTask.map(GroovyCompile::getOptions));
        useDefaultTargetPlatformInference(compileTask, compileClasspathConfigurationName);
        useDefaultTargetPlatformInference(compileTask, sourceSet.getRuntimeClasspathConfigurationName());
        // TODO: `classes` should be a little more tied to the classesDirs for a SourceSet so every plugin
        // doesn't need to do this.
        project.getTasks().named(sourceSet.getClassesTaskName(), task -> task.dependsOn(compileTask));
        // Explain that Groovy, for compile, also needs the resources (#9872)
        project.getConfigurations().getByName(compileClasspathConfigurationName).attributes(attrs -> attrs.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.getObjects().named(LibraryElements.class, LibraryElements.CLASSES_AND_RESOURCES)));
    });
}
Also used : ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) DefaultSourceSet(org.gradle.api.internal.tasks.DefaultSourceSet) Groovydoc(org.gradle.api.tasks.javadoc.Groovydoc) BiFunction(java.util.function.BiFunction) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) FileCollection(org.gradle.api.file.FileCollection) LibraryElements(org.gradle.api.attributes.LibraryElements) DslObject(org.gradle.api.internal.plugins.DslObject) Inject(javax.inject.Inject) Provider(org.gradle.api.provider.Provider) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet) TaskProvider(org.gradle.api.tasks.TaskProvider) ModuleRegistry(org.gradle.api.internal.classpath.ModuleRegistry) GroovyRuntime(org.gradle.api.tasks.GroovyRuntime) ReportingExtension(org.gradle.api.reporting.ReportingExtension) Project(org.gradle.api.Project) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) JvmPluginsHelper(org.gradle.api.plugins.internal.JvmPluginsHelper) DefaultGroovySourceSet(org.gradle.api.internal.tasks.DefaultGroovySourceSet) Sets(com.google.common.collect.Sets) JavaToolchainSpec(org.gradle.jvm.toolchain.JavaToolchainSpec) JvmEcosystemUtilities(org.gradle.api.plugins.jvm.internal.JvmEcosystemUtilities) ObjectFactory(org.gradle.api.model.ObjectFactory) SerializableLambdas.spec(org.gradle.api.internal.lambdas.SerializableLambdas.spec) GroovyCompile(org.gradle.api.tasks.compile.GroovyCompile) Plugin(org.gradle.api.Plugin) JvmPluginServices(org.gradle.api.plugins.jvm.internal.JvmPluginServices) GroovyCompile(org.gradle.api.tasks.compile.GroovyCompile) DefaultGroovySourceSet(org.gradle.api.internal.tasks.DefaultGroovySourceSet) GroovySourceDirectorySet(org.gradle.api.tasks.GroovySourceDirectorySet) SourceDirectorySet(org.gradle.api.file.SourceDirectorySet) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) FileCollection(org.gradle.api.file.FileCollection)

Aggregations

DslObject (org.gradle.api.internal.plugins.DslObject)2 GroovyCompile (org.gradle.api.tasks.compile.GroovyCompile)2 Sets (com.google.common.collect.Sets)1 File (java.io.File)1 BiFunction (java.util.function.BiFunction)1 Inject (javax.inject.Inject)1 Action (org.gradle.api.Action)1 Plugin (org.gradle.api.Plugin)1 Project (org.gradle.api.Project)1 LibraryElements (org.gradle.api.attributes.LibraryElements)1 ConfigurableFileCollection (org.gradle.api.file.ConfigurableFileCollection)1 FileCollection (org.gradle.api.file.FileCollection)1 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)1 ModuleRegistry (org.gradle.api.internal.classpath.ModuleRegistry)1 SerializableLambdas.spec (org.gradle.api.internal.lambdas.SerializableLambdas.spec)1 DefaultGroovySourceSet (org.gradle.api.internal.tasks.DefaultGroovySourceSet)1 DefaultSourceSet (org.gradle.api.internal.tasks.DefaultSourceSet)1 ObjectFactory (org.gradle.api.model.ObjectFactory)1 GroovyBasePlugin (org.gradle.api.plugins.GroovyBasePlugin)1 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)1