Search in sources :

Example 1 with JavaToolchainService

use of org.gradle.jvm.toolchain.JavaToolchainService in project spring-boot by spring-projects.

the class JavaPluginAction method configureToolchainConvention.

private void configureToolchainConvention(Project project, BootRun run) {
    JavaToolchainSpec toolchain = project.getExtensions().getByType(JavaPluginExtension.class).getToolchain();
    JavaToolchainService toolchainService = project.getExtensions().getByType(JavaToolchainService.class);
    run.getJavaLauncher().convention(toolchainService.launcherFor(toolchain));
}
Also used : JavaToolchainSpec(org.gradle.jvm.toolchain.JavaToolchainSpec) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService)

Example 2 with JavaToolchainService

use of org.gradle.jvm.toolchain.JavaToolchainService in project gradle by gradle.

the class ScalaBasePlugin method getToolchainTool.

private <T> Provider<T> getToolchainTool(Project project, BiFunction<JavaToolchainService, JavaToolchainSpec, Provider<T>> toolMapper) {
    final JavaPluginExtension extension = extensionOf(project, JavaPluginExtension.class);
    final JavaToolchainService service = extensionOf(project, JavaToolchainService.class);
    return toolMapper.apply(service, extension.getToolchain());
}
Also used : JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService)

Example 3 with JavaToolchainService

use of org.gradle.jvm.toolchain.JavaToolchainService 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)

Example 4 with JavaToolchainService

use of org.gradle.jvm.toolchain.JavaToolchainService in project gradle by gradle.

the class JavaBasePlugin method getToolchainTool.

private <T> Provider<T> getToolchainTool(Project project, BiFunction<JavaToolchainService, JavaToolchainSpec, Provider<T>> toolMapper) {
    final JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
    final JavaToolchainService service = project.getExtensions().getByType(JavaToolchainService.class);
    return toolMapper.apply(service, extension.getToolchain());
}
Also used : DefaultJavaPluginExtension(org.gradle.api.plugins.internal.DefaultJavaPluginExtension) JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService) DefaultJavaToolchainService(org.gradle.jvm.toolchain.internal.DefaultJavaToolchainService)

Example 5 with JavaToolchainService

use of org.gradle.jvm.toolchain.JavaToolchainService in project gradle by gradle.

the class ApplicationPlugin method getToolchainTool.

private <T> Provider<T> getToolchainTool(Project project, BiFunction<JavaToolchainService, JavaToolchainSpec, Provider<T>> toolMapper) {
    final JavaPluginExtension extension = project.getExtensions().getByType(JavaPluginExtension.class);
    final JavaToolchainService service = project.getExtensions().getByType(JavaToolchainService.class);
    return toolMapper.apply(service, extension.getToolchain());
}
Also used : JavaToolchainService(org.gradle.jvm.toolchain.JavaToolchainService)

Aggregations

JavaToolchainService (org.gradle.jvm.toolchain.JavaToolchainService)7 Inject (javax.inject.Inject)2 Plugin (org.gradle.api.Plugin)2 Project (org.gradle.api.Project)2 LibraryElements (org.gradle.api.attributes.LibraryElements)2 FileCollection (org.gradle.api.file.FileCollection)2 SourceDirectorySet (org.gradle.api.file.SourceDirectorySet)2 ModuleRegistry (org.gradle.api.internal.classpath.ModuleRegistry)2 DslObject (org.gradle.api.internal.plugins.DslObject)2 DefaultSourceSet (org.gradle.api.internal.tasks.DefaultSourceSet)2 ObjectFactory (org.gradle.api.model.ObjectFactory)2 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)2 JvmPluginsHelper (org.gradle.api.plugins.internal.JvmPluginsHelper)2 JvmEcosystemUtilities (org.gradle.api.plugins.jvm.internal.JvmEcosystemUtilities)2 JvmPluginServices (org.gradle.api.plugins.jvm.internal.JvmPluginServices)2 Provider (org.gradle.api.provider.Provider)2 GroovyCompile (org.gradle.api.tasks.compile.GroovyCompile)2 JavaToolchainSpec (org.gradle.jvm.toolchain.JavaToolchainSpec)2 Sets (com.google.common.collect.Sets)1 Closure (groovy.lang.Closure)1