7

How do you configure Grape to look for a custom configuration file at a location other than the default of ~/.groovy/grapeConfig.xml? Unfortunately the official documentation at http://groovy.codehaus.org/Grape appears to be incomplete and doesn't cover this particular case.

For example, I'd like to specify a path such as $PROJECT_DIR/src/main/resources/groovyConfig.xml so that other members in my team don't have to create and maintain their own groovyConfig.xml files in their user/home directories.

M. Justin
  • 14,487
  • 7
  • 91
  • 130
sversch
  • 856
  • 8
  • 22

1 Answers1

10

To set a custom path to the Grape configuration file, set the grape.config system property, e.g. if grape.config is set to /home/user/customGrapeConfig.xml then Grape will use that as the configuration file.

The full list of options related to Grape configuration files, according to a Groovy Developers' mailing list thread, is as follows:

  1. Grape will use the value of the system property grape.config (if it is set) as the path to the configuration file.
  2. If grape.config is not set, then:
    • If the groovy.root system property is set, Grape will look for the configuration file in the directory specified; otherwise
    • If groovy.root is not set, it uses ${user.home}/.groovy/ as the Groovy root directory and looks for a configuration file there.
  3. If no configuration file is found to exist as per the previous steps, the defaultGrapeConfig.xml is retrieved from GrapeIvy's classloader (i.e. from the Groovy JAR).
sversch
  • 856
  • 8
  • 22
  • This algorithm resides in https://git-wip-us.apache.org/repos/asf?p=groovy.git;a=blob;f=src/main/groovy/grape/GrapeIvy.groovy – eel ghEEz Jun 18 '16 at 00:38
  • I wanted to integrate Groovy Grape/Ivy with a local Maven cache. GrapeIvy only reads Maven artifacts. A reimplementation that uses Maven for both reading and writing cached artifacts appears here: https://github.com/yihtserns/grape-maven – eel ghEEz Jun 18 '16 at 00:38
  • the new link for the algorithm is now https://git-wip-us.apache.org/repos/asf?p=groovy.git;a=blob;f=src/main/groovy/groovy/grape/GrapeIvy.groovy (as per @eelghEEz comment) – Donatello Jun 07 '21 at 14:48