【Java】springBoot2.0 gradle 多模块项目打包问题。

项目是用springBoot+gradle生成的,后来改成了多模块,结果打包的时候报错:The value of a manifest attribute must not be null (Key=Start-Class)
这个start-class应该就是springboot启动的application类,不知道是不是因为我改成了多模块项目,gradle配置文件没写好,所以导致拿不到start-class。

以下是build.gradle文件(springboot版本原本是2.0.0 M7,后来改成了2.0.1.BUILD-SNAPSHOT):

apply from: "./libraries.gradle"

buildscript {

ext {

springBootVersion = '2.0.1.BUILD-SNAPSHOT'

mybatisGeneratorVersion = '1.4'

}

repositories {

mavenCentral()

maven { url "https://repo.spring.io/snapshot" }

maven { url "https://repo.spring.io/milestone" }

dependencies {

classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")

}

}

apply plugin: 'java'

apply plugin: 'idea'

apply plugin: 'eclipse'

apply plugin: 'org.springframework.boot'

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

/*group = 'com.psy'

version = '0.0.1-SNAPSHOT'

sourceCompatibility = 1.8*/

/*repositories {

mavenCentral()

maven { url "https://repo.spring.io/snapshot" }

maven { url "https://repo.spring.io/milestone" }

}*/

//configuration for all projects

allprojects {

apply plugin: 'java'

group 'com.psy'

version = '0.0.1-SNAPSHOT'

sourceCompatibility = 1.8

targetCompatibility = 1.8

repositories {

mavenCentral()

maven { url "https://repo.spring.io/snapshot" }

maven { url "https://repo.spring.io/milestone" }

}

/*jar {

enabled = true

baseName = 'psy'

version = '0.5.0'

manifest {

attributes "Manifest-Version": 1.0,

'Main-Class': 'org.springframework.boot.loader.JarLauncher',

'Start-Class': 'com.psy.metrics.MetricsApplication'

}

}*/

/*bootJar {

classifier = 'app'

baseName = 'psy'

version = '0.5.0'

manifest {

attributes "Manifest-Version": 1.0,

'Main-Class': 'org.springframework.boot.loader.JarLauncher',

'Start-Class': 'com.psy.metrics.MetricsApplication'

}

}*/

}

//find out the java projects

ext.javaProjects = subprojects.findAll { project -> project.name != 'docs' && project.name != 'manual' && project.name != 'guides'}

project("web") {

description = "The web module of metrics project"

dependencies {

compile(project(":service"))

compile(project(":common"))

compile(libraries.shiro_spring)

compile(libraries.shiro_redis)

compile(libraries.spring_boot_redis)

compile(libraries.spring_boot_starter_actuator)

compile(libraries.spring_boot_starter)

compile(libraries.spring_boot_starter_web)

testCompile(libraries.spring_boot_starter_test)

}

}

project("dao") {

description = "The dao module of metrics project"

dependencies {

compile(project(":common"))

compile(libraries.mysql_connector_java)

}

}

project("service") {

description = "The service module of metrics project"

dependencies {

compile(project(":common"))

compile(project(":dao"))

}

}

project("common") {

description = "The common module of metrics project"

dependencies {

compile(libraries.lombok)

compile(libraries.orika_core)

compile(libraries.spring_boot_redis)

compile(libraries.spring_boot_starter)

compile(libraries.commons_lang3)

compile(libraries.guava)

compile(libraries.javax_validation)

compile(libraries.poi)

compile(libraries.poi_ooxml)

compile(libraries.commons_beanutils)

}

}

settings.gradle:

rootProject.name = 'metrics'

include 'web'

include 'service'

include 'dao'

include 'common'

报错信息:

【Java】springBoot2.0 gradle 多模块项目打包问题。

有试过在build.gradle里面覆盖bootJar的命令,把start-class强行写上去,虽然能生成jar包,但是并不完整。

求大神们指出一下是哪里出了问题,需要怎么改,万分感谢T T

回答

问题解决了,最根本的原因还是build.gradle构建部分的配置放在了根目录下,没放在启动类所在的模块下,打包bootJar时提示找不到启动类。
另外就算强行把启动类的包名.类名写在start-class上,因为实际上并没有找到这个启动类,所以打出来的包是残缺的。
只要在启动类所在的模块增加一个build.gradle,并把构建部分的配置移过去,就可以正常打包了。
问题解决有赖于:https://my.oschina.net/tangdu...

以上是 【Java】springBoot2.0 gradle 多模块项目打包问题。 的全部内容, 来源链接: utcz.com/a/86670.html

回到顶部