我需要将使用Spring Boot创建的所有微服务打包到一个大EAR中。
该项目的组织方式如下:
/root
build.gradle
settings.gradle
/project1
build.gradle
...
/project3
build.gradle
...
/project3
build.gradle
...
root settings.gradle包含:
rootProject.name = "mysystem"
include("project1")
include("project2")
include("project3")
root中的build.gradle包含
apply plugin: 'ear'
allprojects {
group = 'de.example'
}
dependencies {
deploy project(path:':project1', configuration:'archives')
deploy project(path:':project2', configuration:'archives')
deploy project(path:':project3', configuration:'archives')
}
ear {
deploymentDescriptor {
applicationName = "myproject"
initializeInOrder = true
displayName = "My Project"
description = "My Project EAR"
}
}
build.gradle项目看起来像
buildscript {
ext {
springBootVersion = '2.0.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
defaultTasks 'bootWar'
repositories {
mavenCentral()
// Maven Spring Repository for Milestone Releases (optional for development but don't use it in Production)
maven { url 'https://repo.spring.io/libs-milestone-local' }
// Maven Spring Repository for Stable Releases
maven { url 'https://repo.spring.io/libs-release-local' }
}
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Finchley.RELEASE'
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter") {
}
compile('org.springframework.boot:spring-boot-starter-json')
compile("org.springframework.boot:spring-boot-starter-web") {
}
providedCompile('org.springframework.boot:spring-boot-starter-tomcat')
}
当我为每个项目运行gradle bootWar时,它会在每个项目的build / lib中生成WAR。
但是当我在根项目中运行gradle ear时,输出如下:
Working Directory: D:\Workspace\root
Gradle User Home: D:\Workspace\.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 4.3
Java Home: C:\Programme\Java\jdk8
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: ear
Parallel execution with configuration on demand is an incubating feature.
:project1:compileJava
:project2:compileJava
:project3:compileJava
:project1:processResources
:project1:classes
:project1:war SKIPPED
:project2:processResources
:project2:classes
:project2:war SKIPPED
:project3:processResources
:project3:classes
:project3:war SKIPPED
:ear
BUILD SUCCESSFUL in 2s
7 actionable tasks: 7 executed
结果是大小为1k的EAR。每个项目都不会生成WAR。当我在每个项目上运行gradle bootWar并运行gradle ear时,它都可以工作,并且生成的EAR具有130Mb并包含所有WAR。
有没有办法,我只需要运行gradle ear,它就可以从bootWar生成WAR?
答案 0 :(得分:1)
在gradle Spring Boot项目中,禁用了“ war”任务来代替“ bootWar”任务。
在父build.gradle中设置“ ear”任务以依赖于“ bootWar”任务。
const visitLocationAction = (characterId, location) => {
return (dispatch) => {
return dispatch(visitLocation(characterId, location))
.then(() => dispatch({
type: 'VISIT_LOCATION_SECOND_TIME'
payload: fetchSomething()
}));
};
};