Search in sources :

Example 81 with Project

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

the class DeployedPlugin method apply.

@Override
@SuppressWarnings("deprecation")
public void apply(Project project) {
    project.getPlugins().apply(MavenPublishPlugin.class);
    project.getPlugins().apply(MavenRepositoryPlugin.class);
    PublishingExtension publishing = project.getExtensions().getByType(PublishingExtension.class);
    MavenPublication mavenPublication = publishing.getPublications().create("maven", MavenPublication.class);
    project.afterEvaluate((evaluated) -> {
        project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> {
            if (((Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME)).isEnabled()) {
                project.getComponents().matching((component) -> component.getName().equals("java")).all((javaComponent) -> mavenPublication.from(javaComponent));
            }
        });
    });
    project.getPlugins().withType(JavaPlatformPlugin.class).all((javaPlugin) -> project.getComponents().matching((component) -> component.getName().equals("javaPlatform")).all((javaComponent) -> mavenPublication.from(javaComponent)));
}
Also used : PublishingExtension(org.gradle.api.publish.PublishingExtension) Jar(org.gradle.api.tasks.bundling.Jar) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin) Project(org.gradle.api.Project) MavenPublishPlugin(org.gradle.api.publish.maven.plugins.MavenPublishPlugin) JavaPlugin(org.gradle.api.plugins.JavaPlugin) MavenPublication(org.gradle.api.publish.maven.MavenPublication) Plugin(org.gradle.api.Plugin) MavenPublication(org.gradle.api.publish.maven.MavenPublication) JavaPlugin(org.gradle.api.plugins.JavaPlugin) Jar(org.gradle.api.tasks.bundling.Jar) PublishingExtension(org.gradle.api.publish.PublishingExtension) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin)

Example 82 with Project

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

the class JavaConventions method configureJarManifestConventions.

private void configureJarManifestConventions(Project project) {
    ExtractResources extractLegalResources = project.getTasks().create("extractLegalResources", ExtractResources.class);
    extractLegalResources.getDestinationDirectory().set(project.getLayout().getBuildDirectory().dir("legal"));
    extractLegalResources.setResourcesNames(Arrays.asList("LICENSE.txt", "NOTICE.txt"));
    extractLegalResources.property("version", project.getVersion().toString());
    SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
    Set<String> sourceJarTaskNames = sourceSets.stream().map(SourceSet::getSourcesJarTaskName).collect(Collectors.toSet());
    Set<String> javadocJarTaskNames = sourceSets.stream().map(SourceSet::getJavadocJarTaskName).collect(Collectors.toSet());
    project.getTasks().withType(Jar.class, (jar) -> project.afterEvaluate((evaluated) -> {
        jar.metaInf((metaInf) -> metaInf.from(extractLegalResources));
        jar.manifest((manifest) -> {
            Map<String, Object> attributes = new TreeMap<>();
            attributes.put("Automatic-Module-Name", project.getName().replace("-", "."));
            attributes.put("Build-Jdk-Spec", SOURCE_AND_TARGET_COMPATIBILITY);
            attributes.put("Built-By", "Spring");
            attributes.put("Implementation-Title", determineImplementationTitle(project, sourceJarTaskNames, javadocJarTaskNames, jar));
            attributes.put("Implementation-Version", project.getVersion());
            manifest.attributes(attributes);
        });
    }));
}
Also used : Arrays(java.util.Arrays) CheckFormat(io.spring.javaformat.gradle.tasks.CheckFormat) OptionalDependenciesPlugin(org.springframework.boot.build.optional.OptionalDependenciesPlugin) TestRetryTaskExtension(org.gradle.testretry.TestRetryTaskExtension) JavaPlugin(org.gradle.api.plugins.JavaPlugin) TestFailuresPlugin(org.springframework.boot.build.testing.TestFailuresPlugin) DependencySet(org.gradle.api.artifacts.DependencySet) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Map(java.util.Map) Test(org.gradle.api.tasks.testing.Test) CheckstylePlugin(org.gradle.api.plugins.quality.CheckstylePlugin) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Checkstyle(org.gradle.api.plugins.quality.Checkstyle) CheckClasspathForProhibitedDependencies(org.springframework.boot.build.classpath.CheckClasspathForProhibitedDependencies) Jar(org.gradle.api.tasks.bundling.Jar) Project(org.gradle.api.Project) Set(java.util.Set) Collectors(java.util.stream.Collectors) JavaVersion(org.gradle.api.JavaVersion) TestRetryPlugin(org.gradle.testretry.TestRetryPlugin) List(java.util.List) SpringJavaFormatPlugin(io.spring.javaformat.gradle.SpringJavaFormatPlugin) CoreJavadocOptions(org.gradle.external.javadoc.CoreJavadocOptions) TreeMap(java.util.TreeMap) Format(io.spring.javaformat.gradle.tasks.Format) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) CheckstyleExtension(org.gradle.api.plugins.quality.CheckstyleExtension) Collections(java.util.Collections) Dependency(org.gradle.api.artifacts.Dependency) ToolchainPlugin(org.springframework.boot.build.toolchain.ToolchainPlugin) StringUtils(org.springframework.util.StringUtils) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 83 with Project

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

the class WarPluginAction method configureBootWarTask.

private TaskProvider<BootWar> configureBootWarTask(Project project) {
    Configuration developmentOnly = project.getConfigurations().getByName(SpringBootPlugin.DEVELOPMENT_ONLY_CONFIGURATION_NAME);
    Configuration productionRuntimeClasspath = project.getConfigurations().getByName(SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_CONFIGURATION_NAME);
    Callable<FileCollection> classpath = () -> project.getExtensions().getByType(SourceSetContainer.class).getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath().minus(providedRuntimeConfiguration(project)).minus((developmentOnly.minus(productionRuntimeClasspath))).filter(new JarTypeFileSpec());
    TaskProvider<ResolveMainClassName> resolveMainClassName = ResolveMainClassName.registerForTask(SpringBootPlugin.BOOT_WAR_TASK_NAME, project, classpath);
    TaskProvider<BootWar> bootWarProvider = project.getTasks().register(SpringBootPlugin.BOOT_WAR_TASK_NAME, BootWar.class, (bootWar) -> {
        bootWar.setGroup(BasePlugin.BUILD_GROUP);
        bootWar.setDescription("Assembles an executable war archive containing webapp" + " content, and the main classes and their dependencies.");
        bootWar.providedClasspath(providedRuntimeConfiguration(project));
        bootWar.setClasspath(classpath);
        Provider<String> manifestStartClass = project.provider(() -> (String) bootWar.getManifest().getAttributes().get("Start-Class"));
        bootWar.getMainClass().convention(resolveMainClassName.flatMap((resolver) -> manifestStartClass.isPresent() ? manifestStartClass : resolveMainClassName.get().readMainClassName()));
    });
    bootWarProvider.map((bootWar) -> bootWar.getClasspath());
    return bootWarProvider;
}
Also used : LazyPublishArtifact(org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact) Action(org.gradle.api.Action) Project(org.gradle.api.Project) Callable(java.util.concurrent.Callable) WarPlugin(org.gradle.api.plugins.WarPlugin) BootWar(org.springframework.boot.gradle.tasks.bundling.BootWar) BasePlugin(org.gradle.api.plugins.BasePlugin) FileCollection(org.gradle.api.file.FileCollection) SourceSet(org.gradle.api.tasks.SourceSet) BootBuildImage(org.springframework.boot.gradle.tasks.bundling.BootBuildImage) Configuration(org.gradle.api.artifacts.Configuration) Provider(org.gradle.api.provider.Provider) War(org.gradle.api.tasks.bundling.War) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Plugin(org.gradle.api.Plugin) BootWar(org.springframework.boot.gradle.tasks.bundling.BootWar) Configuration(org.gradle.api.artifacts.Configuration) FileCollection(org.gradle.api.file.FileCollection) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer)

Example 84 with Project

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

the class SpringBootExtension method buildInfo.

/**
 * Creates a new {@link BuildInfo} task named {@code bootBuildInfo} and configures the
 * Java plugin's {@code classes} task to depend upon it. The task is passed to the
 * given {@code configurer} for further configuration.
 * <p>
 * By default, the task's destination dir will be a directory named {@code META-INF}
 * beneath the main source set's resources output directory, and the task's project
 * artifact will be the base name of the {@code bootWar} or {@code bootJar} task.
 * @param configurer the task configurer
 */
public void buildInfo(Action<BuildInfo> configurer) {
    TaskContainer tasks = this.project.getTasks();
    TaskProvider<BuildInfo> bootBuildInfo = tasks.register("bootBuildInfo", BuildInfo.class, this::configureBuildInfoTask);
    this.project.getPlugins().withType(JavaPlugin.class, (plugin) -> {
        tasks.named(JavaPlugin.CLASSES_TASK_NAME).configure((task) -> task.dependsOn(bootBuildInfo));
        this.project.afterEvaluate((evaluated) -> bootBuildInfo.configure((buildInfo) -> {
            BuildInfoProperties properties = buildInfo.getProperties();
            if (properties.getArtifact() == null) {
                properties.setArtifact(determineArtifactBaseName());
            }
        }));
    });
    if (configurer != null) {
        bootBuildInfo.configure(configurer);
    }
}
Also used : Action(org.gradle.api.Action) Project(org.gradle.api.Project) Jar(org.gradle.jvm.tasks.Jar) BuildInfo(org.springframework.boot.gradle.tasks.buildinfo.BuildInfo) JavaPlugin(org.gradle.api.plugins.JavaPlugin) BasePlugin(org.gradle.api.plugins.BasePlugin) File(java.io.File) SourceSet(org.gradle.api.tasks.SourceSet) TaskContainer(org.gradle.api.tasks.TaskContainer) TaskProvider(org.gradle.api.tasks.TaskProvider) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) Property(org.gradle.api.provider.Property) BuildInfoProperties(org.springframework.boot.gradle.tasks.buildinfo.BuildInfoProperties) TaskContainer(org.gradle.api.tasks.TaskContainer) BuildInfo(org.springframework.boot.gradle.tasks.buildinfo.BuildInfo) BuildInfoProperties(org.springframework.boot.gradle.tasks.buildinfo.BuildInfoProperties)

Example 85 with Project

use of org.gradle.api.Project in project tomee by apache.

the class TomEEEmbeddedTask method fixConfig.

private void fixConfig() {
    final Project project = getProject();
    // defaults
    if (classpath == null) {
        try {
            classpath.add(project.getConfigurations().getByName(TomEEEmbeddedExtension.ALIAS).fileCollection());
        } catch (final UnknownConfigurationException uce) {
            classpath = project.getConfigurations().getByName(TomEEEmbeddedExtension.NAME);
        }
    }
    if (docBase == null) {
        docBase = new File(project.getProjectDir(), "src/main/webapp");
    }
    if (workDir == null) {
        workDir = new File(project.getBuildDir(), "tomee-embedded/work");
    }
    if (dir == null) {
        dir = new File(project.getBuildDir(), "tomee-embedded/run").getAbsolutePath();
    }
    if (modules == null || modules.isEmpty()) {
        final File main = new File(project.getBuildDir(), "classes/main");
        if (main.isDirectory()) {
            modules = new ArrayList<>(singletonList(main));
        }
    }
    // extension override
    for (final String name : asList(TomEEEmbeddedExtension.NAME, TomEEEmbeddedExtension.ALIAS)) {
        final TomEEEmbeddedExtension extension = TomEEEmbeddedExtension.class.cast(project.getExtensions().findByName(name));
        if (extension != null) {
            for (final Field f : TomEEEmbeddedTask.class.getDeclaredFields()) {
                if (f.isAnnotationPresent(Input.class)) {
                    try {
                        final Field extField = TomEEEmbeddedExtension.class.getDeclaredField(f.getName());
                        if (!extField.isAccessible()) {
                            extField.setAccessible(true);
                        }
                        final Object val = extField.get(extension);
                        if (val != null) {
                            if (!f.isAccessible()) {
                                f.setAccessible(true);
                            }
                            f.set(this, val);
                        }
                    } catch (final IllegalAccessException | NoSuchFieldException e) {
                        getLogger().warn("No field " + f.getName() + " in " + extension, e);
                    }
                }
            }
        }
    }
}
Also used : Project(org.gradle.api.Project) UnknownConfigurationException(org.gradle.api.artifacts.UnknownConfigurationException) Field(java.lang.reflect.Field) File(java.io.File)

Aggregations

Project (org.gradle.api.Project)269 File (java.io.File)98 Task (org.gradle.api.Task)71 Plugin (org.gradle.api.Plugin)69 Configuration (org.gradle.api.artifacts.Configuration)53 List (java.util.List)40 ArrayList (java.util.ArrayList)39 SourceSet (org.gradle.api.tasks.SourceSet)38 TaskProvider (org.gradle.api.tasks.TaskProvider)38 IOException (java.io.IOException)35 Map (java.util.Map)35 Action (org.gradle.api.Action)34 Set (java.util.Set)32 JavaPlugin (org.gradle.api.plugins.JavaPlugin)31 FileCollection (org.gradle.api.file.FileCollection)30 Provider (org.gradle.api.provider.Provider)27 HashMap (java.util.HashMap)26 Collectors (java.util.stream.Collectors)26 ObjectFactory (org.gradle.api.model.ObjectFactory)25 Collections (java.util.Collections)24