android - Rename file in gradle with passed parameter -
i'm packaging build artefacts gradle build. it's android studio project.
i have tasks create zip file containing 2 jars. let's zip file called 'my.zip
'.
i have following gradle task:
task renameartifacts (type: copy) { ('build/') include 'my.zip' destinationdir file('build/') dolast { println "my-${versionstring}.zip" rename('build/my.zip', "build/my-${versionstring}.zip") } }
and i'm calling gradle -pversionstring="123" :sdk:renameartifacts
i have println
in dolast
closure , can see string interpolation working correctly outputs my-123.zip
.
however, 'my.zip'
not renamed 'my-123.zip'
. remains 'my.zip'
, in fact results in file size of 0 bytes , no longer openable zip file.
i'm going wrong somewhere, where?
full gradle file:
apply plugin: 'com.android.library' android { compilesdkversion 22 buildtoolsversion "23.0.3" defaultconfig { minsdkversion 14 targetsdkversion 14 versioncode 1 versionname "1.0" } buildtypes { release { minifyenabled false proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile filetree(include: ['*.jar'], dir: 'libs') testcompile 'junit:junit:4.12' compile 'com.android.support:support-v4:22.2.0' compile files('libs/urbanairship-lib-3.1.0.jar') compile files('libs/jackson-annotations-2.2.2.jar') compile files('libs/jackson-core-2.2.2.jar') compile files('libs/jackson-databind-2.2.2.jar') } task updateversionnumber() << { ant.replace(file: 'src/main/java/com/my/version.java', token: '{{version}}', value: versionstring) } task javadoc(type: javadoc) { source = android.sourcesets.main.java.srcdirs classpath += project.files(android.getbootclasspath().join(file.pathseparator)) destinationdir = file("build/javadoc") failonerror false } task createjavadocjar(type: jar) { ('build/javadoc') destinationdir file('build') basename = 'my_doc' } createjavadocjar.dependson(javadoc) task packagemyjaranddependencies(type: jar) { (ziptree('libs/jackson-annotations-2.2.2.jar')) { exclude 'meta-inf/maven/' exclude 'meta-inf/services/' } (ziptree('libs/jackson-core-2.2.2.jar')) { exclude 'meta-inf/maven/' exclude 'meta-inf/services/' } (ziptree('libs/jackson-databind-2.2.2.jar')) { exclude 'meta-inf/maven/' exclude 'meta-inf/services/' } (ziptree('libs/urbanairship-lib-3.1.0.jar')) (ziptree('build/intermediates/bundles/release/classes.jar')) } task createfinaljar(type: copy) { from('build/libs/') into('build') include('sdk.jar') rename('sdk.jar', 'my.jar') } createfinaljar.dependson(clean, build, packagemyjaranddependencies) packagemyjaranddependencies.mustrunafter build build.mustrunafter clean task zipartifacts(type: zip) { ('build/') ('build/libs') include 'my_doc.jar' include 'my.jar' basename = 'my_lib' destinationdir file('build') } zipartifacts.dependson(createfinaljar, createjavadocjar) task renameartifacts (type: copy) { ('build/') into('build') include 'my_lib.zip' dolast { println "my_lib-${versionstring}.zip" rename "my_lib.zip", "my_lib-${versionstring}.zip" } } renameartifacts.dependson(zipartifacts)
rename
method on copyprocessingspec
, configures task perform renamings while operating. if wrap in dolast
, copying has happened, , no rename performed. furthermore, rename takes file names, not relative or absolute file paths. should work:
project.ext.versionstring = versionstring task renameartifacts (type: copy) { ('build/') include 'my.zip' destinationdir file('build/') rename 'my.zip', "my-${project.versionstring}.zip" }
edit: $versionstring not accessible in tasks. using project property suggested way how pass these in tasks (see here).
Comments
Post a Comment