title: How to pass gradle property of parent project to logback.xml in Spring Boot?
body: <p>I have this projects structure:</p>
  <pre><code>- parent-project
    - build.gradle
    - gradle.properties
    - child-project
      - build.gradle
      - src
        - main
          - java
          - resources
            - application.properties
            - logback.xml
  </code></pre>
  <p>This is the parent build.gradle:</p>
  <pre><code>allprojects {
      apply plugin: 'java'
      apply plugin: 'groovy'
      apply plugin: 'maven'
  
      group = 'com.test'
  
      sourceCompatibility = JavaVersion.VERSION_11
      targetCompatibility = JavaVersion.VERSION_11
  
      repositories {
          mavenLocal()
          maven {
              url nexusRepo
              credentials {
                  username = nexusUsername
                  password = nexusPassword
              }
          }
          mavenCentral()
          jcenter()
      }
      
      uploadArchives {
          repositories {
              mavenDeployer {
                  repository(url: nexusRepo) {
                      authentication(userName: nexusUsername, password: nexusPassword)
                  }
              }
          }
      }
  }
  
  uploadArchives.enabled = false
  </code></pre>
  <p>my gradle.properties of the parent project contains among others this:</p>
  <pre><code>version=0.1.0-SNAPSHOT
  </code></pre>
  <p>This is the child-project build.gradle:</p>
  <pre><code>plugins {
      id 'org.springframework.boot' version '2.3.0.RELEASE'
      id 'io.spring.dependency-management' version '1.0.9.RELEASE'
      id 'java'
      id 'groovy'
      id 'war'
  }
  
  configurations {
      compileOnly {
          extendsFrom annotationProcessor
      }
  }
  
  dependencies {
      //spring boot related dependencies
      ...
      implementation &quot;com.xm.logback:jLogbackGelfAppender:1.1.0&quot;
      implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
      implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
      implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
      implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '6.3'
      ...
      //testing related dependencies
  }
  </code></pre>
  <p>This is the child-project application.properties:</p>
  <pre><code>prop.testserver.computer-name=${COMPUTERNAME}
  ...
  
  # graylog properties
  graylogHost=host.com
  graylogPort=555
  graylogSourceId=app_id_dev
  </code></pre>
  <p>The reason I am posting the prop.testserver.computer-name property is because I tried using gradle resourceProcess and got an error concerning this property.</p>
  <p>This is my logback.xml:</p>
  <pre><code>&lt;!DOCTYPE configuration&gt;
  
  &lt;configuration&gt;
    &lt;contextName&gt;${graylogSourceId}&lt;/contextName&gt;
    &lt;jmxConfigurator/&gt;
  
    &lt;springProperty scope=&quot;context&quot; name=&quot;graylogHost&quot; source=&quot;graylogHost&quot;/&gt;
    &lt;springProperty scope=&quot;context&quot; name=&quot;graylogPort&quot; source=&quot;graylogPort&quot;/&gt;
    &lt;springProperty scope=&quot;context&quot; name=&quot;graylogSourceId&quot; source=&quot;graylogSourceId&quot;/&gt;
  
    &lt;appender name=&quot;CONSOLE&quot; class=&quot;ch.qos.logback.core.ConsoleAppender&quot;&gt;
      &lt;encoder class=&quot;net.logstash.logback.encoder.LogstashEncoder&quot;/&gt;
    &lt;/appender&gt;
  
    &lt;appender name=&quot;GELF&quot; class=&quot;com.xm.logback.GelfAppender&quot;&gt;
      &lt;server&gt;${graylogHost}&lt;/server&gt;
      &lt;port&gt;${graylogPort}&lt;/port&gt;
      &lt;protocol&gt;TCP&lt;/protocol&gt;
      &lt;includeSource&gt;true&lt;/includeSource&gt;
      &lt;includeMDC&gt;true&lt;/includeMDC&gt;
      &lt;additionalFields&gt;
        application=${graylogSourceId}
      &lt;/additionalFields&gt;
      &lt;layout class=&quot;ch.qos.logback.classic.PatternLayout&quot;&gt;
        &lt;pattern&gt;%m&lt;/pattern&gt;
      &lt;/layout&gt;
    &lt;/appender&gt;
  
    &lt;logger name=&quot;com.test&quot; level=&quot;INFO&quot;&gt;
      &lt;appender-ref ref=&quot;GELF&quot;/&gt;
    &lt;/logger&gt;
  
    &lt;root level=&quot;INFO&quot;&gt;
      &lt;appender-ref ref=&quot;CONSOLE&quot;/&gt;
    &lt;/root&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  <p>I need to add an application_version in the  in logback but I cannot get the version trying different things through the process.</p>
  <p>First I tried using this options</p>
  <ul>
  <li>application_version=${version}, the application runs but the logger prints version_IS_UNDEFINED</li>
  <li>application_version=${project.version}, the application runs but the logger prints project.version_IS_UNDEFINED</li>
  <li>application_version=@version@, the application runs but the logger prints @version@</li>
  <li>application_version=@project.version@, the application runs but the logger prints @project.version@</li>
  </ul>
  <p>Then I added:</p>
  <pre><code>processResources {
      filesMatching('application.properties') {
          expand(project.properties)
      }
  }
  </code></pre>
  <p>to the child-project build.gradle and I got this error:</p>
  <blockquote>
  <p>Missing property (COMPUTERNAME) for Groovy template expansion. Defined
  keys [parent, classLoaderScope, configurations, plugins, objects,
  logger, rootDir, projectRegistry, path, testResultsDirName,
  targetCompatibility, java, normalization, bootJar, childProjects, jar,
  state, processResources, serviceRegistryFactory, tasks, ext,
  projectDir, dependencyLocking, projectEvaluationBroadcaster,
  dependencyManagement, projectPath, module, inheritedScope,
  nexusBuilderUsername, version, script, dependencies,
  processTestResources, webAppDir, extensions, modelRegistry, install,
  projectEvaluator, nexusBuilderUserPassword, projectConfigurator,
  archivesBaseName, logging, configurationActions, sourceCompatibility,
  status, subprojects, components, displayName, bootWar,
  nexusDeployerUsername, parentIdentifier, testClasses,
  antBuilderFactory, out, standardOutputCapture, docsDir,
  compileTestGroovy, defaultTasks, nexusRepo, buildScriptSource,
  autoTargetJvmDisabled, reportsDir, sonarqube, baseClassLoaderScope,
  services, assemble, gradle, distsDirName, buildFile, depth,
  mutationState, docsDirName, testResultsDir, buildDir,
  scriptHandlerFactory, deferredProjectConfiguration, project,
  conf2ScopeMappings, groovyRuntime, repositories,
  nexusDeployerUserPassword, scriptPluginFactory, resourceLoader,
  testReportDir, compileGroovy, mavenPomDir, group, artifacts, test,
  configurationTargetIdentifier, compileJava, check, webAppDirName,
  fileResolver, name, testReportDirName, buildscript, springBoot,
  processOperations, asDynamicObject, publicType, classes, identityPath,
  description, sourceSets, buildPath, fileOperations, pluginManager,
  defaultArtifacts, class, modelSchemaStore, reporting, convention,
  allprojects, ant, war, resources, clean, compileTestJava, layout,
  build, listenerBuildOperationDecorator, libsDir, distsDir,
  uploadArchives, rootProject, libsDirName, properties, providers]</p>
  </blockquote>
  <p>I need help passing the application version from parent gradle.properties to child project logback.xml parametrically. Please help, thanks in advance.</p>