Gradle - add directory to classpath

和自甴很熟 提交于 2019-12-10 12:35:28

问题


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')
}

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

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

How can I make gradle add another directory to the build and specify it as part of the classpath for the generated startup scripts?


回答1:


The application plugin documentation says:

Static files to be added to the distribution can be simply added to src/dist

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')

Note: working around this defect means that config has to go into /lib under src/dist




回答2:


You may try this:

project('project-name') {
   apply plugin: 'application'
   mainClassName = "your.main.Class"

   startScripts {
       classpath += files('src/dist/lib/conf')
   }

More information can be found here.



来源:https://stackoverflow.com/questions/35545405/gradle-add-directory-to-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!