Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - add directory to classpath

Tags:

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?

like image 586
Omar Darwish Avatar asked Feb 22 '16 03:02

Omar Darwish


People also ask

Where do I add classpath in New Gradle?

1- open your build. Gradle (app module) scroll to the top until you see that comment // Top-level build file where you can add configuration options common to all sub-projects/modules. builtin comment // Top-level build file where you can add configuration options common to all sub-projects/modules.

How do I create a directory in Gradle?

Creating directories All core Gradle tasks ensure that any output directories they need are created if necessary using this mechanism. As described in the Apache Ant manual, the mkdir task will automatically create all necessary directories in the given path and will do nothing if the directory already exists.

What is classpath in Gradle?

Gradle dependencies are grouped into sets called configurations. Different configurations are used for building classpath for the major two tasks — compile classpath is used for compilation and runtime classpath is used for running the application.

What is FileTree in Gradle?

A FileTree represents a hierarchy of files. It extends FileCollection to add hierarchy query and manipulation methods. You typically use a FileTree to represent files to copy or the contents of an archive. You can obtain a FileTree instance using Project.


2 Answers

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

like image 177
RaGe Avatar answered Mar 01 '23 04:03

RaGe


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.

like image 40
Andy Malakov Avatar answered Mar 01 '23 04:03

Andy Malakov