How to determine if project.version is set?


(Chris Doré) #1

I’d like to know if there is a better way to determine if a project has a version specified. I’m currently using the following, but it seems kind of gross:

allprojects { proj ->
    if("$proj.version" != "unspecified") {
        ...
    }
}

Thanks, Chris


(Peter Niederwieser) #2

You can simplify the syntax a bit:

allprojects {
  if (version != "unspecified") { ... }
}

Note that, depending on where you put this check, it may come too early.


(Chris Doré) #3

Ok, I was hoping there was a better way then comparing to the fixed string “unspecified”, just because it feels fragile.

In this case I am accessing the version in a closure I’ve added to Gradle.projectsEvaluated(), so I hope it won’t happen too early. So far things are working.

Thanks Peter.