gradle - 如何构建一个带有 lib 目录和其他 jar 的 jar?
在 gradle 中 - 如何将 jar 嵌入到 lib 中的构建输出 jar 中 目录(特别是 lib/enttoolkit.jar 和 lib/mail.jar)?
In gradle - how can I embed jars inside my build output jar in the lib
directory (specifially the lib/enttoolkit.jar and lib/mail.jar)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
如果您的项目中的一个目录(让我们称之为
libs
)内有所有的jar,您只需要这个:我想这些jar更有可能是某种依赖项。然后你可以这样做:
If you have all the jars inside a directory (lets call it
libs
) in your project, you only need this:I guess it is more likely that these jars are dependencies of some sort. Then you could do it like this:
逐字摘自:http://docs.codehaus.org/display/GRADLE/Cookbook #Cookbook-Creatingafatjar
Gradle 0.9:
Gradle 0.8:
上面的代码片段将仅包含该项目的编译依赖项,而不包含任何可传递的运行时依赖项。如果您还想合并它们,请将configurations.compile 替换为configurations.runtime。
编辑:仅选择您需要的 jar
进行新配置,releaseJars 可能
将您想要的 jar 添加到该配置中,
然后在上面概述的 jar 任务中使用该配置。
Lifted verbatim from: http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar
Gradle 0.9:
Gradle 0.8:
The above snippets will only include the compile dependencies for that project, not any transitive runtime dependencies. If you also want to merge those, replace configurations.compile with configurations.runtime.
EDIT: only choosing jars you need
Make a new configuration, releaseJars maybe
Add the jars you want to that configuration
then use that configuration in the jar task outlined above.
简单:
运行它:
simple:
run it:
我还需要做类似的事情,但不太能够得到 Guus 和 stigkj 建议的工作,但在他们的帮助下足够接近以使其工作(Guus 的示例在
dependency {compile {extendsFrom myLibs 上爆炸了) 然后运行 gradle jar 并检查创建的 jar 给出了这个
输出,表明我得到的 jar 文件具有 groovy 以及它所依赖的所有 jar。在“胖罐子”里面:
I also needed to do something similar and wasn't quite able to get what Guus and stigkj suggested working, but got close enough with their help to get this working (Guus' example blew up on the
dependencies { compile { extendsFrom myLibs }}
closure for me.Then running
gradle jar
and examining the created jar gives me this output, showing that I get the jar file to have groovy as well as all jars that it's dependent on inside the "fat jar":下面的代码可以尝试一下。它取决于jar任务并且是Jar类型
上面的代码将不同的内容打包到不同的目录中。
在 gradle 2.2 上测试
Below code could be tried. It depends on the jar task and is of Type Jar
The above code would pack different content inside different directories.
Tested on gradle 2.2
我需要你问的同样的事情,并使用了这种方法。您可能不需要自定义配置声明,但我需要将本地使用的 jar 文件与超级构建文件中声明的文件分开。
I needed to the same thing you asked, and used this method. you may not need a custom configuration declaration, but i needed to separate the locally used jar files from those declared in a super-build file.
我也有同样的问题。我这样解决了:
使用 copyToLib 将文件复制到 lib 文件夹中,并使用类路径引用依赖项
I had the same problem. I solved it like this:
Copy the files into the lib folder with copyToLib and reference the dependency with the Class-Path
就我而言,我需要将根项目 Jar 的内容包含到子项目 Jar 中。因此,为了使其工作,可以使用此模板:
我的示例:
In my case I needed to include a contents of the root project Jar into subproject Jar. So, to make it work, one can use this template:
My example:
以下是我如何使用 Gradle 实现此构建设置。这会将您的应用程序构建到 Jar 中,将生成的库 jar 复制到 build/libs 下的 libs 目录中,并配置类路径以将 jar 包含在创建的 build/libs/libs 目录中。
Here's how I managed to achieve this build setting using Gradle. This will build your app into a Jar, copy the library jars generated into the libs directory under build/libs and also configure classpath to include the jars in the created build/libs/libs directory.