Commend -P set value to property not working somehow at the early stage

(Yong Cheng) #1

myPlugin is creating an extension

project.extensions.create("myPlugin", MyPluginExtension)


project.ext {
     env = "development"
  // set value to the evn in extension
myPlugin {
     env = project.env
  task myTask<< {
      configurations.each { config ->
            println "env1 = " + project.env
  println "env2 = " + project.env

The command I’m running

gradle -Penv="testing"

The result is bellowing, but I’m expecting both should output “testing”

env2 = development
env1 = testing

(Peter Niederwieser) #2

‘-P’ doesn’t set a property declared in a build script, but defines a new (project) property. I think what happens is that the extra property shadows it. Giving them different names should solve the problem, e.g. ‘env’ vs. ‘environment’.