Netflix Nebula Gradle Plugin and project.version

Posted by & filed under , .

nebula-verticalIf you use the Netflix OSS Nebula plugin in gradle and you use it for automatic versioning, incrementals etc then you will come across this at some point. (And in the case that some of you have already encountered this, I have to ask why did you not write the blog post I needed when I came across this?) It’s to do with project.version property in the build.gradle file — which seems to somehow report itself to your script as “unresolved” — even though the actual build works correctly and produces correctly versioned packages!

This can have annoying implications on your project scripts — especially if you are dealing with things like generating paths/links/etc based on the version number. (It’s a known thing that the application gradle plugin generates paths like /application-M.m.v/bin/.... for instance.)

It turns out that the reason for it is that nebula sets the project.version during the evaluate project phase — and before that it’s not set. To ensure any of your variables which use project.version are set to the right version, simply wrap it all up in an afterEvaluate closure :

afterEvaluate {
  def path = "/myapp-${project.version}/bin"
  def logPath = "/logs/myapp/${project.version}/"
  //...
}

You can even declare tasks in the afterEvaluate — such as:

afterEvaluate {
  def appDir = "/${project.applicationName}-${project.version}"
  def appDirLatest = "/${project.applicationName}-latest"
 
  task createDockerfile(type: Dockerfile) {
    destFile = project.file('./build/docker/Dockerfile')
    dependsOn distTar
    // ...
  }
 
  task buildImage(type: DockerBuildImage) {
    dependsOn createDockerfile
    //...
  }
  //...
}

Small detail but makes a huge difference.