Search in sources :

Example 1 with ApplicationPluginConvention

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

the class FindMainClassTask method findMainClass.

private String findMainClass() {
    Project project = getProject();
    String mainClass = null;
    // Try the SpringBoot extension setting
    SpringBootPluginExtension bootExtension = project.getExtensions().getByType(SpringBootPluginExtension.class);
    if (bootExtension.getMainClass() != null) {
        mainClass = bootExtension.getMainClass();
    }
    ApplicationPluginConvention application = (ApplicationPluginConvention) project.getConvention().getPlugins().get("application");
    if (mainClass == null && application != null) {
        // Try the Application extension setting
        mainClass = application.getMainClassName();
    }
    JavaExec runTask = findRunTask(project);
    if (mainClass == null && runTask != null) {
        mainClass = runTask.getMain();
    }
    if (mainClass == null) {
        Task bootRunTask = project.getTasks().findByName("bootRun");
        if (bootRunTask != null) {
            mainClass = (String) bootRunTask.property("main");
        }
    }
    if (mainClass == null) {
        // Search
        if (this.mainClassSourceSetOutput != null) {
            project.getLogger().debug("Looking for main in: " + this.mainClassSourceSetOutput.getClassesDir());
            try {
                mainClass = MainClassFinder.findSingleMainClass(this.mainClassSourceSetOutput.getClassesDir(), SPRING_BOOT_APPLICATION_CLASS_NAME);
                project.getLogger().info("Computed main class: " + mainClass);
            } catch (IOException ex) {
                throw new IllegalStateException("Cannot find main class", ex);
            }
        }
    }
    project.getLogger().info("Found main: " + mainClass);
    if (bootExtension.getMainClass() == null) {
        bootExtension.setMainClass(mainClass);
    }
    if (application != null && application.getMainClassName() == null) {
        application.setMainClassName(mainClass);
    }
    if (runTask != null && !runTask.hasProperty("main")) {
        runTask.setMain(mainClass);
    }
    return mainClass;
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) JavaExec(org.gradle.api.tasks.JavaExec) SpringBootPluginExtension(org.springframework.boot.gradle.SpringBootPluginExtension) ApplicationPluginConvention(org.gradle.api.plugins.ApplicationPluginConvention) IOException(java.io.IOException)

Example 2 with ApplicationPluginConvention

use of org.gradle.api.plugins.ApplicationPluginConvention in project gradle-eta by typelead.

the class EtaPlugin method configureApplicationPluginIfPresent.

private void configureApplicationPluginIfPresent() {
    project.getPlugins().all(plugin -> {
        if (ApplicationPlugin.class.isInstance(plugin)) {
            ApplicationPluginConvention pluginConvention = project.getConvention().getPlugin(ApplicationPluginConvention.class);
            pluginConvention.setMainClassName("eta.main");
        }
    });
}
Also used : ApplicationPluginConvention(org.gradle.api.plugins.ApplicationPluginConvention)

Example 3 with ApplicationPluginConvention

use of org.gradle.api.plugins.ApplicationPluginConvention in project wildfly-swarm by wildfly-swarm.

the class PackageTask method getMainClassName.

@Input
@Optional
private String getMainClassName() {
    Project project = getProject();
    SwarmExtension swarmExtension = getSwarmExtension();
    String mainClassName = swarmExtension.getMainClassName();
    if (mainClassName == null && project.getConvention().getPlugins().containsKey("application")) {
        ApplicationPluginConvention app = (ApplicationPluginConvention) project.getConvention().getPlugins().get("application");
        mainClassName = app.getMainClassName();
    }
    if (mainClassName != null && !mainClassName.equals("")) {
        getLogger().warn("\n------\n" + "Custom main() usage is intended to be deprecated in a future release and is no longer supported, \n" + "please refer to http://docs.wildfly-swarm.io for YAML configuration that replaces it." + "\n------");
    }
    return mainClassName;
}
Also used : Project(org.gradle.api.Project) ApplicationPluginConvention(org.gradle.api.plugins.ApplicationPluginConvention) Input(org.gradle.api.tasks.Input) Optional(org.gradle.api.tasks.Optional)

Aggregations

ApplicationPluginConvention (org.gradle.api.plugins.ApplicationPluginConvention)3 Project (org.gradle.api.Project)2 IOException (java.io.IOException)1 DefaultTask (org.gradle.api.DefaultTask)1 Task (org.gradle.api.Task)1 Input (org.gradle.api.tasks.Input)1 JavaExec (org.gradle.api.tasks.JavaExec)1 Optional (org.gradle.api.tasks.Optional)1 SpringBootPluginExtension (org.springframework.boot.gradle.SpringBootPluginExtension)1