Gradle set buildConfigField in task

Viewed 604

I have a java project and I use the de.fuerstenau.buildconfig gradle plugin to set a java constant from my build script. I have two tasks that create a war with a different value for the "HOME" constant:

buildscript {
repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.de.fuerstenau:BuildConfigPlugin:1.1.8"
  }
}
apply plugin: 'de.fuerstenau.buildconfig'

[... left out]

buildConfig { 
    buildConfigField 'String', 'HOME', 'TEST_HOME'
}

task createLiveOnly(type: War, dependsOn: classes, group: 'build') {

    buildConfig {
        buildConfigField 'String', 'HOME', 'LIVE_HOME'
    }

    archiveName = 'live.war'
    destinationDir = file("$buildDir/libs")
}

task createTestOnly(type: War, dependsOn: classes, group: 'build') {
    buildConfig {
        buildConfigField 'String', 'HOME_ENV_NAME', 'ISAMT_TEST_HOME'
    }
    archiveName = 'test.war'
    destinationDir = file("$buildDir/libs")
}

task createWars(dependsOn: [createLiveOnly, createTestOnly], group: 'build')

[... left out]

}

Intention: when running createLiveOnly, HOME = 'LIVE_HOME'. When running createTestOnly, HOME = 'TEST_HOME'. When running createWars, it creates both for both values for HOME. When running everything else (e.g. standard gradle war) it defaults to 'TEST_HOME'. Unfortunately, this does not work as the constant is always set to 'TEST_HOME' even when only running createLiveOnly. Why? And how do I fix it?

Thanks for your answers!

0 Answers
Related