从 Gradle 多项目构建构建完全可执行的 Spring Boot 1.3 war
Building a fully executable Spring Boot 1.3 war from a Gradle multi project build
我正在尝试根据 https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html 使用 Spring Boot 1.3 构建一个完全可执行文件 WAR。如果我构建一个 Gradle 项目,一切正常,但我有一个多项目构建,其中我有一个 "root" 项目,然后在它下面有几个项目,我无法让它构建任何东西,但一个标准的 "fat" WAR 文件,没有 Jetty 的 providedRuntime,也没有使它成为 运行.
的脚本
有人知道怎么做吗?
在我的根项目中,我有以下内容(删节):
buildscript {
repositories {
mavenCentral()
}
ext {
springBootVersion = '1.3.0.RELEASE'
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
}
}
allprojects {
//Put instructions for all projects
repositories {
mavenCentral() // jcenter is missing spring-orm.4.1.6.RELEASE jar file so try mavenCentral first
jcenter {
url "http://jcenter.bintray.com/"
}
maven { url 'http://repo.opensourceagility.com/release' }
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'spring-boot'
}
然后在我正在尝试构建的 Web 项目子项目中,我有:
apply plugin: 'war'
dependencies {
// Include related projects
compile project(':project-model')
compile project(':project-dynamoDB')
// Core Spring Boot - note version is set in main build.gradle file
compile 'org.springframework.boot:spring-boot-starter-web'
// Remove Tomcat (included in -web) and include Jetty instead
providedRuntime 'org.springframework.boot:spring-boot-starter-jetty'
// Other Spring modules
compile 'org.springframework.boot:spring-boot-starter-social-facebook'
compile 'org.springframework.boot:spring-boot-starter-social-linkedin'
compile 'org.springframework.social:spring-social-google:1.0.0.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.springframework:spring-context'
compile 'org.springframework:spring-context-support'
}
configurations {
providedRuntime.exclude group: 'org.springframework.boot', module:'spring-boot-starter-tomcat'
all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' // exclude when using log4j
}
springBoot {
mainClass = 'rs.web.Weblication'
executable = true
}
bootRun {
addResources = true
}
processResources {
// exclude resources if they look like they're profile dependent but don't match the current env/profile
eachFile { d ->
if(d.name.endsWith('.xml') || d.name.endsWith('.yaml') || d.name.endsWith('.properties')) {
//def fname = d.name.replaceFirst(~/\.[^\.]+$/, '')
//if(fname.indexOf("-") > -1 && ! fname.endsWith("-" + environment)) {
// d.exclude()
//} else {
// replace @variables@ listed below in properties/config files
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
activeProfiles: environment
])
//}
}
}
}
war {
baseName = 'project-web'
version = '1.0.0'
manifest {
attributes 'Implementation-Title': baseName,
'Implementation-Version': version
}
webXml = file('src/main/resources/web.xml')
// rename the war task which has profiles appended from warName-profile,profile2.war
// to warName-profile.profile2.war
classifier = environment.replaceAll(',','-')
}
但是当我构建它时(./gradlew build
,或 ./gradlew subprojectname:build
),一切都很好并且创建了一个工作的 WAR,但不是可执行的。
对于单个项目,我可以正常工作。
啊哈,好吧,我构建了一个测试多项目构建并且运行正常,所以显然是上面的配置。
我完成了一个排除过程,结果发现有问题的地方是那条线
classifier = environment.replaceAll(',','-')
用于重命名包含环境变量的文件作为名称的一部分。这个过程似乎妨碍了脚本的添加;如果确实有必要,也许可以在以后应用。
我正在尝试根据 https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html 使用 Spring Boot 1.3 构建一个完全可执行文件 WAR。如果我构建一个 Gradle 项目,一切正常,但我有一个多项目构建,其中我有一个 "root" 项目,然后在它下面有几个项目,我无法让它构建任何东西,但一个标准的 "fat" WAR 文件,没有 Jetty 的 providedRuntime,也没有使它成为 运行.
的脚本有人知道怎么做吗?
在我的根项目中,我有以下内容(删节):
buildscript {
repositories {
mavenCentral()
}
ext {
springBootVersion = '1.3.0.RELEASE'
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
}
}
allprojects {
//Put instructions for all projects
repositories {
mavenCentral() // jcenter is missing spring-orm.4.1.6.RELEASE jar file so try mavenCentral first
jcenter {
url "http://jcenter.bintray.com/"
}
maven { url 'http://repo.opensourceagility.com/release' }
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'spring-boot'
}
然后在我正在尝试构建的 Web 项目子项目中,我有:
apply plugin: 'war'
dependencies {
// Include related projects
compile project(':project-model')
compile project(':project-dynamoDB')
// Core Spring Boot - note version is set in main build.gradle file
compile 'org.springframework.boot:spring-boot-starter-web'
// Remove Tomcat (included in -web) and include Jetty instead
providedRuntime 'org.springframework.boot:spring-boot-starter-jetty'
// Other Spring modules
compile 'org.springframework.boot:spring-boot-starter-social-facebook'
compile 'org.springframework.boot:spring-boot-starter-social-linkedin'
compile 'org.springframework.social:spring-social-google:1.0.0.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.springframework:spring-context'
compile 'org.springframework:spring-context-support'
}
configurations {
providedRuntime.exclude group: 'org.springframework.boot', module:'spring-boot-starter-tomcat'
all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' // exclude when using log4j
}
springBoot {
mainClass = 'rs.web.Weblication'
executable = true
}
bootRun {
addResources = true
}
processResources {
// exclude resources if they look like they're profile dependent but don't match the current env/profile
eachFile { d ->
if(d.name.endsWith('.xml') || d.name.endsWith('.yaml') || d.name.endsWith('.properties')) {
//def fname = d.name.replaceFirst(~/\.[^\.]+$/, '')
//if(fname.indexOf("-") > -1 && ! fname.endsWith("-" + environment)) {
// d.exclude()
//} else {
// replace @variables@ listed below in properties/config files
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
activeProfiles: environment
])
//}
}
}
}
war {
baseName = 'project-web'
version = '1.0.0'
manifest {
attributes 'Implementation-Title': baseName,
'Implementation-Version': version
}
webXml = file('src/main/resources/web.xml')
// rename the war task which has profiles appended from warName-profile,profile2.war
// to warName-profile.profile2.war
classifier = environment.replaceAll(',','-')
}
但是当我构建它时(./gradlew build
,或 ./gradlew subprojectname:build
),一切都很好并且创建了一个工作的 WAR,但不是可执行的。
对于单个项目,我可以正常工作。
啊哈,好吧,我构建了一个测试多项目构建并且运行正常,所以显然是上面的配置。
我完成了一个排除过程,结果发现有问题的地方是那条线
classifier = environment.replaceAll(',','-')
用于重命名包含环境变量的文件作为名称的一部分。这个过程似乎妨碍了脚本的添加;如果确实有必要,也许可以在以后应用。