unknown
unknown

Reputation: 1893

Rename the filename in build.gradle with version

I am working on one gradle script where I need to rename the artifact name at the end but I am facing an issue my code is below.Version is coming from the version.properties file and I am able to read it properly in build.gradle script but while I change the name of the artifact at the end for e.g. libmain.so to NativeJNI-4.0.0_15 then it doesn't change and change it from libmain.so to filechange.Cansome one let me know what is the issue here

    def filechange = file("NativeJNI-${project.version}.so")
    //println filechange
    task fixartifactname (type: Copy) {
           //def filechange = "NativeJNI-${project.version}.so"
           //println filechange
           from 'build/binaries/mainSharedLibrary'
           into 'build/libs'
   // def filechange = file("NativeJNI-${project.version}.so")
    println filechange
    include('libmain.so')
    rename ('libmain.so', '${filechange}')
    }
    //println fixartifactname
    build.dependsOn fixartifactname

Upvotes: 0

Views: 3906

Answers (2)

unknown
unknown

Reputation: 1893

I am able to fix my issue in below way

def filechange = file("build/libs/NativeJNI-${project.version}.so")
task copyfile(type: Copy) {
     from 'build/binaries/mainSharedLibrary'
     into 'build/libs'
     include('libmain.so')
     rename ('libmain.so', filechange.name)
}

Upvotes: 1

Amnon Shochot
Amnon Shochot

Reputation: 9356

Per your question I understand that you're building a native binary. Did you try to set the baseName property for your component? This way you could create your shared library with your desired name from the first place.

Now, regarding your code above then it contains 2 problems:

  1. When calling rename you're wrapping ${filechange} with a single apostrophe (') rather than using inverted commas("), thus this variable is not being resolved to its value. Also, there is no need for a closure block here.
  2. By default using filechange inside the rename would map to its string value which is its full path rather than just the new file name. To overcome this simply use the name property of filechange.

To conclude, each of the following options should do the work for you:

// use inverted commas
rename ('libmain.so', "$filechange.name")

// remove apostrophe or commas
rename ('libmain.so', filechange.name) //

// groovy style function call with no paranthesis
rename 'libmain.so', filechange.name //

Upvotes: 0

Related Questions