0

In my build file I have the following line:

version = '1.1.2'

I want to make an executable "fat jar" using Shadow Jar (see my answer here) and then copy this to another directory (see answer here). But I want to incorporate the project's version number into the name of the jar file so as not to overwrite the existing version.

The Shadow Plugin User Guide explains how to set the name:

shadowJar {
    baseName = 'shadow'
    classifier = null
    version = "7.7.7"
}

... but how might I set the variable version here to use the outer (file-wide/global...) variable version?

Community
  • 1
  • 1
mike rodent
  • 14,126
  • 11
  • 103
  • 157
  • 1
    version = project.version – lance-java Jan 18 '17 at 21:04
  • Ha... thanks very much. Add an answer if you want some points. To clarify also, if anyone's interested, the line setting the project.version variable must come physically ***before*** the reference to it in this task. Somehow a Gradle newb like myself assumes that the variables will all be set in the "first life cycle" ... – mike rodent Jan 18 '17 at 21:29

1 Answers1

1

In a gradle script, there's a Project instance in scope which everything delegates to. When you say version = '1.1.2' it's actually invoking

getProject().setVersion('1.1.2')

In your shadowJar closure there's a version higher up in the scope which is hiding the project version. So you can do

shadowJar {
    version = project.version
    ...
}
lance-java
  • 25,497
  • 4
  • 59
  • 101