title: Grails: why is the Config.groovy file executed during compilation?
body: <p>From <a href="http://docs.grails.org/2.3.7/guide/conf.html" rel="nofollow noreferrer">the Grails documentation</a> and <a href="https://stackoverflow.com/questions/17600252/what-is-the-difference-between-buildconfig-groovy-and-config-groovy">this</a> question:</p>
  
  <blockquote>
    <p>For general configuration Grails provides two files:</p>
    
    <ol>
    <li>grails-app/conf/BuildConfig.groovy</li>
    <li>grails-app/conf/Config.groovy</li>
    </ol>
    
    <p>Both of them use Groovy's ConfigSlurper syntax. The first, BuildConfig.groovy, is for settings that are used when running Grails commands, such as compile, doc, etc. The second file, Config.groovy, is for settings that are used when your application is running. This means that Config.groovy is packaged with your application, but BuildConfig.groovy is not. </p>
  </blockquote>
  
  <p>And here is an extract about the <code>log4j</code> framework:</p>
  
  <blockquote>
    <p>Grails uses its common configuration mechanism to provide the settings for the underlying Log4j log system, so all you have to do is add a log4j setting to the file grails-app/conf/<strong>Config.groovy</strong>.</p>
  </blockquote>
  
  <p>I have a project with these two files: <code>grails-app/conf/BuildConfig.groovy</code> and <code>grails-app/conf/Config.groovy</code>. The project uses the <code>log4j</code> utility, so some settings (including a function) are placed in the <strong>Config.groovy</strong> file. Now, according to the documentation I quoted, it is the right file, since I want to use the logging utilities for running the application, not compiling it. </p>
  
  <p>What's interesting, these settings are used when I run <code>mvn package</code> on my project - the function inside the <code>log4j</code> settings is executed.  </p>
  
  <p>According to both <a href="http://docs.grails.org/2.3.7/guide/conf.html" rel="nofollow noreferrer">the documentation</a> and <a href="https://stackoverflow.com/questions/17600252/what-is-the-difference-between-buildconfig-groovy-and-config-groovy">the question</a> this should not be the case. </p>
  
  <p>I know that it is possible to use the <code>grailsApplication</code> to access these settings:</p>
  
  <pre><code>def recipient = grailsApplication.config.foo.bar.hello
  </code></pre>
  
  <p>So I searched my project and found some usages of the <code>grailsApplication</code>, but none related to the log4j settings.</p>
  
  <p>What are other possible reasons of having the log4j settings that are placed in the <strong>Config.groovy</strong> file used during <code>mvn package</code>? What am I missing?</p>
  
  <p><strong>Update:</strong> the mentioned configuration seems to work when I use <code>mvn package</code> to build my project for the first time. Next time I run <code>mvn package</code>, the <code>log4j</code> configuration from the <code>Config.groovy</code> file is used. And if I delete the job workspace, it works well again.</p>