有没有“正确的方法”?在 Gradle 中创建瘦战争和耳朵文件
使用 Gradle(显然还有 Java),我想生成一个瘦战争(战争中没有依赖项 jar),并将所有依赖项包含在 Ear 文件中。我做了一些挖掘,但我找不到任何明显的 Gradle“瘦战争”教程。
在 Maven 2.2.1 中(是的,我们陷入了 2.2.1,不要问我为什么),这是由 创建一个单独的ear项目并重复ear中子项目的所有依赖项。
我可以想象如何在 Gradle 中复制同样的 hack,但我希望有一种更聪明的方法来做到这一点。有人有任何想法/例子/建议吗?
Using Gradle (and Java, obviously), I'd like to generate a skinny war (with no dependency jars in the war), and include all of the dependencies in the ear file. I've done some digging, but I can't find any obvious "skinny war" tutorials for Gradle.
In Maven 2.2.1 (yeah, we're stuck in 2.2.1, don't ask me why), this was accomplished by creating a separate ear project and repeating all of my dependencies from my sub-projects in the ear.
I can imagine how I would duplicate this same hack in Gradle, but I'm hoping there's a smarter way to do this. Does anyone have any ideas/examples/suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最新的 1.0-M4 gradle 快照包含新的 Ear 插件。您可以更新包装器配置或直接从
。拉链” rel="nofollow">http://repo.gradle.org/gradle/distributions/gradle-snapshots/gradle-1.0-milestone-4-20110610162713+0200-bin.zip
此快照的完整发行版可下载在 http://repo.gradle.org/gradle/distributions/gradle-snapshots/gradle-1.0-milestone-4-20110610162713+0200-all.zip 包含一个示例文件夹,其中包含两个示例新引入的ear插件的用法。
看看samples/ear/earWithWar 中的例子这个例子定义了一个带有战争的耳朵。
要获得瘦战争,你必须修改战争项目的build.gradle。要获得没有第三方库的战争,您必须将以下代码段添加到样本/ear/earWithWar/war/build.gradle:
要在您的ear的lib/子文件夹中获取第三方库,您必须添加由war 插件也添加到根项目中的earlib 配置中。该示例针对 log4j 库执行此操作。
现在在示例项目上运行“gradle Ear”会创建一个带有skinny war的ear,并且第三方库存储在ear的lib/子文件夹中。
完整的快照包含 docs/ 子文件夹中有关 Ear 插件的更多文档
the latest 1.0-M4 snapshot of gradle contains the new ear plugin. You can either update your wrapper configuration or download the snapshot directly from
http://repo.gradle.org/gradle/distributions/gradle-snapshots/gradle-1.0-milestone-4-20110610162713+0200-bin.zip
The complete distribution of this snapshot downloadable at http://repo.gradle.org/gradle/distributions/gradle-snapshots/gradle-1.0-milestone-4-20110610162713+0200-all.zip contains a samples folder with two example usages of the newly introduced ear plugin.
Have a look at the example in samples/ear/earWithWar This example defines a ear with a war.
To get a skinny war, you have to modify the build.gradle of the war project. To get a war without thirdparty libs, you have to add the following snippet to samples/ear/earWithWar/war/build.gradle:
To get the thirdparty libs in the lib/ subfolder of your ear you have to add the lib used by the war plugin to the earlib configuration in the root project too. The example does this for the log4j library.
Now running "gradle ear" on the example project creates a ear with a skinny war and the thirdparty libs stored in the lib/ subfolder of the ear.
The complete snapshot contains further documentation in the docs/ subfolder about the ear plugin
按照 Rene 的建议设置
war { classpath = [] }
会阻止包含所有内容 - 最终存档甚至不包含WEB-INF/classes
。我知道从 war 文件的WEB-INF/lib
目录中排除依赖项但仍包含WEB-INF/classes
的唯一方法是使用 providedCompile em> 和/或 providedRuntime 配置。例如<代码>
依赖项{
提供的Compile fileTree(dir: 'lib', include: '**/*.jar')
}
Setting
war { classpath = [] }
as suggested by Rene prevents everything from being included - the final archive doesn't even containWEB-INF/classes
. The only way I know of to exclude dependencies from a war file'sWEB-INF/lib
dir but stil includeWEB-INF/classes
is to use providedCompile and/or providedRuntime configurations. For exampledependencies {
providedCompile fileTree(dir: 'lib', include: '**/*.jar')
}
我将尝试获得快照版本,但为了完整起见,以下是我从昨天开始将所有内容组合在一起的方式。请随时改进我的 Gradle/Groovy。我确信它没有想象中那么优雅。
(请注意,所有罐子都是故意放在耳根的。不要问我为什么,但有些人显然喜欢这样。)
I'm going to try to get my hands on that snapshot build, but here's how I hacked things together since yesterday, just for the sake of completeness. Please feel free to improve my Gradle/Groovy. I'm sure it's not as elegant as it could be.
(Please note, all jars are in the root of the ear on purpose. Don't ask me why, but some people apparently like it that way.)