如何为Gradle项目生成类路径? [英] How do I generate the class path for a Gradle project?

查看:144
本文介绍了如何为Gradle项目生成类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个包的gradle项目。构建完成后,每个包在build / libs中生成它的jar文件。外部jar依赖被拉入〜/ .gradle。我现在想通过适当的类路径从命令行本地运行服务。为此,我正在编写构建类路径的脚本。问题是脚本不理解所有的外部依赖关系,因此不能构造类路径。有没有一种方法可以帮助Gradle?理想情况下,我想在构建结束时将所有依赖关系转储到文件夹中。

首先,我会建议如果可以的话,请使用应用程序插件,因为它已经处理好了。

如果你想将类路径转储到一个文件中,最简单的方法是这样的:

 任务writeClasspath<< {
buildDir.mkdirs()
新建文件(buildDir,classpath.txt).text = configurations.runtime.asPath +\\\

}

如果您想实际上将类路径中的所有库复制到一个目录中,您可以这样做:

 任务copyDependencies(type:Copy){
from configurations.runtime
into new File(buildDir,dependencies)
}


I have a gradle project with multiple packages. After the build, each package generates its jar files in build/libs. The external jar dependencies are pulled into ~/.gradle. I would now like to run the service locally from the commandline with the appropriate classpath. For this purpose, I am writing a script that constructs the classpath. The problem is that the script does not understand all the external dependencies and hence cannot construct the classpath. Is there a way for gradle to help with this? Ideally, I would like to dump all the dependencies into a folder at the end of the build.

解决方案

Firstly, i would suggest using the application plugin if you can, since it takes care of this already.

If you want to dump the classpath to a file yourself, the simplest way is something like:

task writeClasspath << {
    buildDir.mkdirs()
    new File(buildDir, "classpath.txt").text = configurations.runtime.asPath + "\n"
}

If you want to actually copy all the libraries on the classpath into a directory, you can do:

task copyDependencies(type: Copy) {
    from configurations.runtime
    into new File(buildDir, "dependencies")
}

这篇关于如何为Gradle项目生成类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆