bogon:smart wangxizhong$ gradle build -x test
Loading.....
:server:compileJava UP-TO-DATE
:server:processResources UP-TO-DATE
:server:classes UP-TO-DATE
:server:jar
:client:compileJava
:client:processResources UP-TO-DATE
:client:classes
:client:findMainClass FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':client:findMainClass'.
> Unable to find a single main class from the following candidates [smart.server.ServerApplication, smart.client.ClientApplication]
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Loading.....
:server:compileJava UP-TO-DATE
:server:processResources UP-TO-DATE
:server:classes UP-TO-DATE
:server:jar
:client:compileJava
:client:processResources UP-TO-DATE
:client:classes
:client:findMainClass FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':client:findMainClass'.
> Unable to find a single main class from the following candidates [smart.server.ServerApplication, smart.client.ClientApplication]
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
环境:Boot多项目构建,出现了多个application入口,gradle无法识别主main
解决方案:在gradle.build文件中添加以下代码
mainClassName = 'smart.client.ClientApplication'
apply plugin: 'application' 修改后的文件:buildscript { ext { springBootVersion = '1.5.2.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } ext { applicationInfo = [ 'author' : 'WangXiZhong', 'language' : 'java', 'crateDate': '2017/03/22' ] } allprojects { version = '1.0.0-SNAPSHOT' apply plugin: 'idea' } subprojects { group = 'smart' apply plugin: 'java' apply plugin: 'application' apply plugin: 'org.springframework.boot' sourceCompatibility = 1.8 targetCompatibility = 1.8 mainClassName = 'smart.client.ClientApplication' buildDir=new File(rootProject.getBuildDir().getAbsolutePath()) dependencies { compile('org.springframework.boot:spring-boot-starter') compile('org.springframework.boot:spring-boot-starter-aop') compile('org.springframework.boot:spring-boot-starter-data-redis') compile('org.springframework.boot:spring-boot-starter-web') runtime('mysql:mysql-connector-java') testCompile('junit:junit:4.12') } repositories { mavenCentral() } dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR6" } } }