我无法创建自定义的春季启动启动器

时间:2019-04-09 08:19:40

标签: java spring spring-boot gradle spring-boot-starter

我尝试创建spring-boot-starter。我使用此Gradle文件创建了一个简单的spring-boot module

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

group = 'my.domain'
version = '0.0.1-SNAPSHOT'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    annotationProcessor "org.springframework.boot:spring-boot-autoconfigure-processor"
}

一个班级:

@SpringBootApplication
public class ApiSpringBootStarterApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiSpringBootStarterApplication.class, args);
    }

}

它构建成功。但是,如果我删除ApiSpringBootStarterApplication类,则会收到错误消息:

* What went wrong:
Execution failed for task ':api-spring-boot-starter:bootJar'.
> Main class name has not been configured and it could not be resolved

2 个答案:

答案 0 :(得分:0)

从插件中删除org.springframework.boot。 该插件旨在为您的项目构建可执行jar。如果是入门者,则无需这样做。

参考:https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/

类推,如果您使用的是maven和spring-boot-maven-plugin,情况也是如此。

答案 1 :(得分:-2)

JVM搜索主类以启动应用程序,而没有主类则无法启动应用程序。

为什么要删除ApiSpringBootStarterApplication? 是你的主要课程。

相关问题