Java 具有war文件依赖项的Gradle ear构建
我正试图从一个java多项目构建一个EAR。 此项目中有三个不同的WAR项目和多个JAR项目。当我构建项目时,JAR的所有依赖项都导入到ear lib中,WAR项目的所有依赖项都导入到各自的WEB-INF/lib中。但是所有WAR项目都使用许多常见的依赖项。有了这些依赖项,结果EAR变得非常大(>100MB)。是否有任何方法可以将所有依赖项添加到一个EAR文件中,而在WAR文件中不添加任何依赖项 我的耳朵构造。gradle如下所示Java 具有war文件依赖项的Gradle ear构建,java,gradle,war,ear,Java,Gradle,War,Ear,我正试图从一个java多项目构建一个EAR。 此项目中有三个不同的WAR项目和多个JAR项目。当我构建项目时,JAR的所有依赖项都导入到ear lib中,WAR项目的所有依赖项都导入到各自的WEB-INF/lib中。但是所有WAR项目都使用许多常见的依赖项。有了这些依赖项,结果EAR变得非常大(>100MB)。是否有任何方法可以将所有依赖项添加到一个EAR文件中,而在WAR文件中不添加任何依赖项 我的耳朵构造。gradle如下所示 apply plugin: 'ear' apply plugin
apply plugin: 'ear'
apply plugin: 'java'
configurations {
earLib.extendsFrom runtime
earLib.transitive = true
}
description = 'JavaEE6 Assembly'
dependencies {
deploy project(path: ':WAR1', configuration: 'archives')
deploy project(path: ':WAR2', configuration: 'archives')
deploy project(path: ':WAR3', configuration: 'archives')
earlib project(':CommonJAR1')
earlib project(':CommonJAR2')
// Writing as below does not work in this case
// earLib group: 'io.springfox', name: 'springfox-swagger2', version:'2.1.1'
}
ear {
archiveName='EARNAME.ear'
libDirName 'lib'
into("META-INF"){
from("META-INF")
}
}
以下是WAR文件build.gradle中的一个
apply plugin: 'war'
description = 'WAR2'
dependencies {
compile project(':CommonJAR1')
compile group: 'commons-beanutils', name: 'commons-beanutils', version:'1.9.2'
compile group: 'org.springframework', name: 'spring-jdbc', version:'4.0.5.RELEASE'
compile group: 'org.springframework', name: 'spring-core', version:'4.0.5.RELEASE'
compile group: 'org.springframework', name: 'spring-beans', version:'4.0.5.RELEASE'
compile group: 'org.springframework', name: 'spring-webmvc', version:'4.0.5.RELEASE'
compile group: 'org.springframework', name: 'spring-oxm', version:'4.0.5.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version:'4.0.5.RELEASE'
compile group: 'org.springframework', name: 'spring-context-support', version:'4.0.5.RELEASE'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.2.3'
compile group: 'org.json', name: 'json', version:'20090211'
compile(group: 'org.springframework', name: 'spring-context', version:'4.0.5.RELEASE') {
exclude(module: 'commons-logging')
}
compile group: 'org.aspectj', name: 'aspectjrt', version:'1.7.4'
compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.5'
compile(group: 'log4j', name: 'log4j', version:'1.2.15') {
exclude(module: 'mail')
exclude(module: 'jms')
exclude(module: 'jmxtools')
exclude(module: 'jmxri')
}
compile group: 'javax.inject', name: 'javax.inject', version:'1'
compile group: 'javax.servlet', name: 'jstl', version:'1.2'
runtime group: 'io.springfox', name: 'springfox-swagger2', version:'2.1.1'
runtime group: 'org.springframework', name: 'spring-web', version:'4.0.5.RELEASE'
runtime group: 'org.slf4j', name: 'jcl-over-slf4j', version:'1.7.5'
runtime group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.7.5'
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
providedCompile group: 'javax.servlet.jsp', name: 'jsp-api', version:'2.1'
}
我尝试过任何我能找到的资源来做同样的事情,但都没有成功。请建议。该项目将部署在WAS8.5上,我早些时候找到了这个解决方案,但时间很短,所以现在就回答了 ear的build.gradle应如下所示
apply plugin: 'ear'
apply plugin: 'java'
description = 'JavaEE6 Assembly'
dependencies {
deploy project(path: ':WAR1', configuration: 'archives')
deploy project(path: ':WAR2', configuration: 'archives')
deploy project(path: ':WAR3', configuration: 'archives')
earlib project(':CommonJAR')
}
def deployedModules = [ 'WAR1', 'WAR2', 'WAR3' ]
deployedModules.forEach {
def projectPath = ":${it}"
evaluationDependsOn(projectPath)
findProject(projectPath).configurations.providedCompile.allDependencies.forEach {
boolean isEarModule = it instanceof ProjectDependency &&
(it as ProjectDependency).dependencyProject.name in deployedModules
if (!isEarModule) {
dependencies.add('earlib', it)
}
}
}
ear {
archiveName='EARNAME.ear'
libDirName 'lib'
into("META-INF"){
from("META-INF")
}
}
apply plugin: 'war'
apply plugin: 'java'
description = 'WAR1'
dependencies {
providedCompile project(':CommonJAR')
providedCompile group: 'commons-beanutils', name: 'commons-beanutils', version:'1.9.2'
providedCompile group: 'org.springframework', name: 'spring-jdbc', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-core', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-beans', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-webmvc', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-oxm', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-orm', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-context-support', version:'4.0.5.RELEASE'
providedCompile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.2.3'
providedCompile group: 'org.json', name: 'json', version:'20090211'
providedCompile(group: 'org.springframework', name: 'spring-context', version:'4.0.5.RELEASE') {
exclude(module: 'commons-logging')
}
providedCompile group: 'commons-logging', name: 'commons-logging', version: '1.2'
providedCompile group: 'org.aspectj', name: 'aspectjrt', version:'1.7.4'
providedCompile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.5'
compile(group: 'log4j', name: 'log4j', version:'1.2.15') {
exclude(module: 'jms')
exclude(module: 'jmxtools')
exclude(module: 'jmxri')
}
providedCompile group: 'javax.inject', name: 'javax.inject', version:'1'
providedCompile group: 'javax.servlet', name: 'jstl', version:'1.2'
providedCompile group: 'io.springfox', name: 'springfox-swagger2', version:'2.1.1'
providedCompile group: 'org.springframework', name: 'spring-web', version:'4.0.5.RELEASE'
providedCompile group: 'org.slf4j', name: 'jcl-over-slf4j', version:'1.7.5'
providedCompile group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.7.5'
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
providedCompile group: 'javax.servlet.jsp', name: 'jsp-api', version:'2.1'
providedCompile group: 'org.apache.axis', name: 'axis', version:'1.4'
}
war{
manifest {
attributes(
"Manifest-Version": "1.0",
"Class-Path": configurations.providedCompile.collect {" lib/" + it.getName() }.join(' ')
)
}
}
war文件的build.gradle应如下所示
apply plugin: 'ear'
apply plugin: 'java'
description = 'JavaEE6 Assembly'
dependencies {
deploy project(path: ':WAR1', configuration: 'archives')
deploy project(path: ':WAR2', configuration: 'archives')
deploy project(path: ':WAR3', configuration: 'archives')
earlib project(':CommonJAR')
}
def deployedModules = [ 'WAR1', 'WAR2', 'WAR3' ]
deployedModules.forEach {
def projectPath = ":${it}"
evaluationDependsOn(projectPath)
findProject(projectPath).configurations.providedCompile.allDependencies.forEach {
boolean isEarModule = it instanceof ProjectDependency &&
(it as ProjectDependency).dependencyProject.name in deployedModules
if (!isEarModule) {
dependencies.add('earlib', it)
}
}
}
ear {
archiveName='EARNAME.ear'
libDirName 'lib'
into("META-INF"){
from("META-INF")
}
}
apply plugin: 'war'
apply plugin: 'java'
description = 'WAR1'
dependencies {
providedCompile project(':CommonJAR')
providedCompile group: 'commons-beanutils', name: 'commons-beanutils', version:'1.9.2'
providedCompile group: 'org.springframework', name: 'spring-jdbc', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-core', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-beans', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-webmvc', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-oxm', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-orm', version:'4.0.5.RELEASE'
providedCompile group: 'org.springframework', name: 'spring-context-support', version:'4.0.5.RELEASE'
providedCompile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.2.3'
providedCompile group: 'org.json', name: 'json', version:'20090211'
providedCompile(group: 'org.springframework', name: 'spring-context', version:'4.0.5.RELEASE') {
exclude(module: 'commons-logging')
}
providedCompile group: 'commons-logging', name: 'commons-logging', version: '1.2'
providedCompile group: 'org.aspectj', name: 'aspectjrt', version:'1.7.4'
providedCompile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.5'
compile(group: 'log4j', name: 'log4j', version:'1.2.15') {
exclude(module: 'jms')
exclude(module: 'jmxtools')
exclude(module: 'jmxri')
}
providedCompile group: 'javax.inject', name: 'javax.inject', version:'1'
providedCompile group: 'javax.servlet', name: 'jstl', version:'1.2'
providedCompile group: 'io.springfox', name: 'springfox-swagger2', version:'2.1.1'
providedCompile group: 'org.springframework', name: 'spring-web', version:'4.0.5.RELEASE'
providedCompile group: 'org.slf4j', name: 'jcl-over-slf4j', version:'1.7.5'
providedCompile group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.7.5'
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
providedCompile group: 'javax.servlet.jsp', name: 'jsp-api', version:'2.1'
providedCompile group: 'org.apache.axis', name: 'axis', version:'1.4'
}
war{
manifest {
attributes(
"Manifest-Version": "1.0",
"Class-Path": configurations.providedCompile.collect {" lib/" + it.getName() }.join(' ')
)
}
}
我正试图做一些类似的事情,所以我想使用这里发生的一些事情,但我在ear gradle文件中看到一个“带有路径的项目”:CommonJAR“在项目中找不到”错误。您使用的是哪个版本的gradle?CommanJar是jar模块,如果您有jar模块,请添加它。