Я попытаюсь взять в свои руки эту сборку снимков, но вот как я со вчерашнего дня все взламывал, просто для полноты картины.Пожалуйста, не стесняйтесь улучшать мой Gradle / Groovy.Я уверен, что это не так элегантно, как могло бы быть.
//Make sure the war and jars get built first
task ('ear', type:Jar, dependsOn: ":myWarProject:assemble" ){
//This needs to be in the config block, or Gradle skips the task, assuming the file list for the jar/ear is empty...
from{ "ear/src/main/application" }
}
ear.doFirst{
//Set up the ear file name
baseName = "myapp-" + rootVersion
extension = "ear"
//Gather up the jars required by all of the subprojects
def allSubprojectDependencies = getAllProjectDependencies([
"subproject1",
"subproject2",
"subproject3",
"subproject4",
"subproject5"
])
from { allSubprojectDependencies }
//grab the assembled war file
from {
subprojects.find{ it.name=="myWarFile" }.war.archivePath
}
//Other stuff required for our ear, such as security or eventing EJBs
//Make sure you apply your "repositories" block to your root/ear project or "allProjects" if you do this...
from { configurations.earConfig.files }
//Create the classpath manifest
manifestClassPath = allSubprojectDependencies.collect { it.name }.sort().join(' ')
manifest { attributes( "Class-Path": manifestClassPath ) }
}
def getAllProjectDependencies (def projectNames){
def allDependencies = []as Set
projectNames.each{ projectName ->
def subProject = subprojects.find{ subProject ->
subProject.name.equals(projectName)
}
def subProjectDependencies = subProject.configurations.compile.files
allDependencies.addAll subProjectDependencies
}
return allDependencies.unique{ a,b->
if (a.equals(b)){
return 0
}
return -1
}
}
(Обратите внимание, что все банки специально находятся в корне уха. Не спрашивайте меня, почему, но некоторым людям явноэто так.)