title: Log4j2.properties file not picked up in Gradle Java application?
body: <p>I'm using the <a href="https://docs.gradle.org/current/userguide/application_plugin.html" rel="nofollow noreferrer">Gradle application plugin</a> and trying to configure logging through SLF4J with a Log4J 2 implementation. I've put a <code>log4j2.properties</code> file in <code>src/main/resources</code>:</p>
  <pre><code>.
  ├── app
  │   ├── build
  │   │   ├── classes
  │   │   │   └── java
  │   │   │       └── main
  │   │   │           └── log4j
  │   │   │               └── App.class
  │   │   ├── generated
  │   │   │   └── sources
  │   │   │       ├── annotationProcessor
  │   │   │       │   └── java
  │   │   │       │       └── main
  │   │   │       └── headers
  │   │   │           └── java
  │   │   │               └── main
  │   │   ├── resources
  │   │   │   └── main
  │   │   │       └── log4j2.properties
  │   │   └── tmp
  │   │       └── compileJava
  │   │           └── source-classes-mapping.txt
  │   ├── build.gradle
  │   └── src
  │       ├── main
  │       │   ├── java
  │       │   │   └── log4j
  │       │   │       └── App.java
  │       │   └── resources
  │       │       └── log4j2.properties
  │       └── test
  │           ├── java
  │           │   └── log4j
  │           │       └── AppTest.java
  │           └── resources
  ├── gradle
  │   └── wrapper
  │       ├── gradle-wrapper.jar
  │       └── gradle-wrapper.properties
  ├── gradlew
  ├── gradlew.bat
  └── settings.gradle
  </code></pre>
  <p>My <code>build.gradle</code> contains the Log4j 2 SLF4J binding (<a href="https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/" rel="nofollow noreferrer">https://logging.apache.org/log4j/2.x/log4j-slf4j-impl/</a>):</p>
  <pre><code>/*
   * This file was generated by the Gradle 'init' task.
   *
   * This generated file contains a sample Java application project to get you started.
   * For more details take a look at the 'Building Java &amp; JVM projects' chapter in the Gradle
   * User Manual available at https://docs.gradle.org/6.8.1/userguide/building_java_projects.html
   */
  
  plugins {
      // Apply the application plugin to add support for building a CLI application in Java.
      id 'application'
  }
  
  repositories {
      // Use JCenter for resolving dependencies.
      jcenter()
  }
  
  dependencies {
      // Use JUnit test framework.
      testImplementation 'junit:junit:4.13'
  
      // This dependency is used by the application.
      implementation 'com.google.guava:guava:29.0-jre'
  
      implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.0-alpha1'
      implementation 'org.apache.logging.log4j:log4j-slf4j18-impl:2.14.0'
  
      compileOnly 'org.projectlombok:lombok:1.18.16'
      annotationProcessor 'org.projectlombok:lombok:1.18.16'
  
      testCompileOnly 'org.projectlombok:lombok:1.18.16'
      testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
  }
  
  application {
      // Define the main class for the application.
      mainClass = 'log4j.App'
  }
  </code></pre>
  <p>and the <code>App.java</code> reads</p>
  <pre class="lang-java prettyprint-override"><code>package log4j;
  
  import lombok.extern.slf4j.Slf4j;
  
  @Slf4j
  public class App {
      public String getGreeting() {
          return &quot;Hello World!&quot;;
      }
  
      public static void main(String[] args) {
          log.debug(&quot;Printing a greeting...&quot;);
          System.out.println(new App().getGreeting());
      }
  }
  </code></pre>
  <p>and <code>app/src/main/resources</code> contains the following:</p>
  <pre class="lang-java prettyprint-override"><code># Define the root logger with appender file
  log4j.rootLogger = DEBUG, stdout
  
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%p\t%d{ISO8601}\t%r\t%c\t[%t]\t%m%n
  </code></pre>
  <p>Thus, I would expect the log level to get set to <code>DEBUG</code> and something to get printed to the console if I <code>log.debug()</code> in the application. However, if I <code>./gradlew run</code> the application I don't see a log line:</p>
  <pre><code>&gt; ./gradlew run
  
  &gt; Task :app:run
  Hello World!
  
  BUILD SUCCESSFUL in 953ms
  3 actionable tasks: 1 executed, 2 up-to-date
  </code></pre>
  <p>However, I see no such log line, suggesting that the configuration file wasn't 'picked up'. How can I get this Java application to pick up the <code>log4j2.properties</code> file?</p>