我正在使用Spring boot gradle插件版本1.5.1 RELEASE,如下所示 . 在webProject抱怨缺少属性'mainClass ' and works only when I run ' webProject:build '时,构建失败 . 这是预期用途吗?
Edit :更新了构建脚本并从allProjects中删除了'spring-boot'插件 . 不得不在Web项目中添加'bootRepackage',因为它在此步骤失败 - 具有相同的错误 . 添加'bootRepackage'没有帮助 .
buildscript {
ext {
springBootVersion = '1.5.1.RELEASE'
}
repositories {
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE")
}
}
plugins {
id 'org.springframework.boot' version '1.5.1.RELEASE'
}
defaultTasks 'clean', 'build'
apply plugin: 'java'
apply plugin: 'war'
sourceCompatibility = 1.7
targetCompatibility = 1.7
allprojects {
apply plugin: 'java'
//apply plugin: 'org.springframework.boot' -- Commented out based on the answer
repositories {
mavenLocal()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
//all dependencies
}
}
project('aProject') {
dependencies {
compile(project(':bProject'))
}
}
project('webProject') {
apply plugin: 'war'
apply plugin: 'org.springframework.boot'
war {
baseName = 'webProject'
version = '1.0.0-SNAPSHOT'
}
dependencies {
compile(project(':aproject'))
compile(project(':bProject'))
compile 'org.springframework.boot:spring-boot-starter-tomcat'
}
springBoot {
mainClass = 'com.abc.SomeApplication'
}
bootRepackage{
enabled = false
mainClass = 'com.abc.SomeApplication'
}
}
2 回答
我在多模块Spring启动项目中遇到了类似的问题 . 编译没有主类的模块A.主类在不同的模块中(模块B) .
我在该模块A的build.gradle中添加了一个插件 .
然后它工作 .
不要在主项目中使用Spring Boot gradle插件,只能在
webProject
子模块中使用 .