Gradle - 将目录添加到类路径 [英] Gradle - add directory to classpath
问题描述
我的应用程序需要在类路径中找到<目录下的配置文件时使用 \config
目录。我目前有这样配置的依赖关系,尽管这可能不是使我的应用程序可用的目录的正确方式:
My application requires that a \config
directory be available on the classpath when it looks for configurations files under the directory. I currently have dependencies configured like so, though this is probably not the correct way to make a directory available to my application:
dependencies {
... //runtime, compile dependencies pulled from repositories
runtime files('config')
}
我使用应用程序
插件为我的项目创建独立的zip。如果我的 \config
目录有 \config\subdir
, file1
, file2
,那么插件会生成一个 build \\ install \\ / c $ c>目录,其结构如下:
I am using the application
plugin to create a standalone zip for my project. If my \config
directory has \config\subdir
, file1
, file2
, then the plugin produces a build\install
directory with the following structure:
| build
| --|install
| ----|bin
| ------ projectName
| ------ projectName.bat
| ----|lib
| ------ dependency1.jar
| ------ dependency2.jar
| ------|subdir
| ------ file1
| ------ file2
这对我的应用程序不起作用,因为它显式地期望 \config
目录
This does not work for my application because it explicitly expects a \config
directory
然而,这是我需要的目录结构:
However, this is the directory structure that I need:
| build
| --|install
| ----|bin
| ------ projectName
| ------ projectName.bat
| ----|lib
| ------ dependency1.jar
| ------ dependency2.jar
| ----|config
| ------|subdir
| ------ file1
| ------ file2
如何让gradle将另一个目录添加到构建中并指定它作为生成的启动脚本的类路径的一部分?
How can I make gradle add another directory to the build and specify it as part of the classpath for the generated startup scripts?
推荐答案
应用程序插件 documentation 说:
The application plugin documentation says:
静态文件添加到发行版中可以简单地添加到src / dist中
Static files to be added to the distribution can be simply added to src/dist
我会尝试将您的配置目录放入 src / dist / lib
,并继续使用运行时文件('src / dist / lib / config')
I would try putting your config directory into src/dist/lib
and continue adding it to your classpath with runtime files('src/dist/lib/config')
注意:解决此缺陷意味着config必须在 src / dist
Note: working around this defect means that config has to go into /lib
under src/dist
这篇关于Gradle - 将目录添加到类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!