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.

有帮助吗?

解决方案

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).
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top