如何在Gradle构建项目中创建多个ejb罐子? [英] How do I create several ejb jars in a Gradle build project?
问题描述
我有一个多项目构建,并且在每个项目中,我在主src树中有几个包,需要与src的其余部分分开打包,作为单独的EJB构件:
com / foo / ejb / ejb1
com / foo / ejb / ejb2
...
每个项目中可以有任意数量的这些EJB(0或几个)。 任务应该是我可以分享给每个项目的东西(可能在根项目中定义),并且会自动查找EJB src并为每个EJB生成一个jar,而无需在子项目中明确定义EJB(但可能是一个属性集合containsEjbs来缩小具有EJB的子项目)。 感谢任何帮助,克里斯。 我最终做了以下事情。在[root] /build.gradle中: 因此,如果任何项目具有'containsEjbs = true'属性,那么将为每个各自的(子)项目中的'/ com / foo / ejb'下的每个ejb包添加一个任务。我们将META-INF与描述符一起存储在与类相同的源代码树中,因此可能需要对设置进行调整。 I have a multi-project build and in each of the projects I have several packages in the main src tree which need to be packaged up separately from the rest of the src as individual EJB artifacts: There can be an arbitrary number of these EJBs in each project (0 or several).
My question is, how do I create a task that can, per project, Jar each of these as separate artifacts after the regular compile/jar? I.e. So I end up with following artifacts for each project: The task(s) should be something I can share to each project (so probably defined in root project) and that will automatically find EJB src and generate a jar for each, without having to explicitly define the EJBs in the subprojects (but perhaps a property set "containsEjbs" to narrow down subprojects that have EJBs). I'm thinking along the lines of using a filetree to grab the src package (com.foo.ejb.*) and then iterating and Jar-ing - but its how to do this Jar-ing in the context of Tasks which is what I'm having trouble with. Thanks for any help, Chris. I ended up doing the following. In [root]/build.gradle: So if any projects have a property 'containsEjbs=true', then a tasks is added for each ejb package found under '/com/foo/ejb' in each respective (sub)project. We store META-INF with descriptors in same source tree as classes, so there may be tweaks needed for your set up. 这篇关于如何在Gradle构建项目中创建多个ejb罐子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
我的问题是,如何创建一个任务,可以为每个项目在正常编译/ jar之后将每个这些jar分别作为单独的工件?即所以我最终为每个项目提供了以下工件:
$ p $ project.jar(通常的Java类)
ejb1.jar (MyEjb2Home / Remote / Bean.class,META_INF / [描述符])
...
(MyEjb1Home / Remote / Bean.class,META_INF / [描述符])
ejb2.jar code>
<我正在考虑使用filetree来抓取src包(com.foo.ejb。*),然后迭代和Jaring - 但它如何在任务的上下文中执行此Jar-ing操作是我遇到的麻烦。
afterEvaluate {project - >
if(project.hasProperty('containsEjbs'))
{
def basePath ='/ com / foo / ejb'
def classesDir = project.sourceSets.main.classesDir
def ejbRootClassesDir = file(classesDir.getPath()+ basePath)
def srcFileDirs = project.sourceSets.main.java.srcDirs.collect {file(it.getPath()+ basePath)} .findAll {it .exists()&& it.isDirectory()}
def ejbDirs = srcFileDirs.collect {it.listFiles()} .flatten()
def ejbs = ejbDirs.findAll {it.listFiles()。findAll {f - > f.name =='META-INF'}}
ejbs.each {file - >
任务jarEjbFor_ $ file.name(类型:Jar,dependsOn:classes){
aseName =$ file.name
classifier ='ejb'
from fileTree(文件).include('META-INF / **')
转换为($ basePath / $ file.name)
{
from fileTree(ejbRootClassesDir.getPath()+/ $ file $ name
code $ $ $ $ $ $ $ b com/foo/ejb/ejb1
com/foo/ejb/ejb2
...
project.jar (usual Java classes)
ejb1.jar (MyEjb1Home/Remote/Bean.class, META_INF/[descriptors])
ejb2.jar (MyEjb2Home/Remote/Bean.class, META_INF/[descriptors])
...
afterEvaluate { project ->
if (project.hasProperty('containsEjbs'))
{
def basePath = '/com/foo/ejb'
def classesDir = project.sourceSets.main.classesDir
def ejbRootClassesDir = file(classesDir.getPath() + basePath)
def srcFileDirs = project.sourceSets.main.java.srcDirs.collect { file(it.getPath() + basePath) }.findAll { it.exists() && it.isDirectory() }
def ejbDirs = srcFileDirs.collect { it.listFiles() }.flatten()
def ejbs = ejbDirs.findAll { it.listFiles().findAll { f -> f.name == 'META-INF'} }
ejbs.each { file ->
task "jarEjbFor_$file.name" (type: Jar, dependsOn:classes) {
baseName = "$file.name"
classifier = 'ejb'
from fileTree(file).include('META-INF/**')
into ("$basePath/$file.name")
{
from fileTree( ejbRootClassesDir.getPath() + "/$file.name" )
}
}
}
}