Conditional Compile Steps/Properties issues


(Allen Fisher) #1

Hi! I’m new to Gradle and so far liking what I’m seeing.

I’m attempting to port an ANT build over to Gradle. Right now I’m trying to get the flow of the build correct, then I’m going to tackle getting the build to actually do something (this is a pretty complex build that requires interaction with an IBM iSeries system and a lot of shared ANT code with other builds). The first problem I’m running into is switching some properties around for QA builds vs. Production (PDN) builds.

The way our ANT build handles this is when it’s time for a QA build, we call two targets

ant qua all

This sets some properties differently, swaps in a special property file and then continues to the “all” target which does the build.

What I’m trying to do is to figure out how to make this switch. I’ve tried defining a task for my QA build and running it (similar to the way we do it with ANT), I’ve tried passing in either a project property (-P) or a Java system property (-D).

Either way, I can only get Gradle to adopt one or the other, meaning I can’t switch from run-to-run which variation of the build I do.

Here’s my current (very simple) build.gradle:
def buildProfile = 'build-pdn.props’
def isQUABuild

task all {
  doLast {
    println 'Inside the all task'
  }
}

task qua {
  buildProfile = "build-qua.props"
  isQUABuild = true
}

task pdn {
  buildProfile = "build-pdn.props"
  isQUABuild = false
}

task init {
  doLast {
    println 'Inside the init task'
    println isQUABuild
    if(isQUABuild) {
      println "This is a QA build!"
    } else {
      println "This is a PDN build!"
    }
    println buildProfile
  }
}

task setProps {
  doLast {
    println 'Inside the setProps task!'
  }
}

task fetchRelMod {
  doLast {
    println 'Inside the fetchRelMod task!'
  }
}

Any help or guidance would be appreciated. Thanks in advance for the help.

Allen