I have a tree of files that I'd like to copy with Gradle, and for some of the files (e.g. ending in .txt), I'd like to do some property substitions. For example, I have:
task "copyAndroidAssets$flavor" (type: Copy,
dependsOn: ["cleanAndroidAssets", "copyAndroidRes$flavor"] ) {
from "build/assets/${flavorLc}/release/"
into '../android/assets'
expand ( versionName: myVersionName, versionCode: myVersionCode )
}
The problem is that some of the files in the tree being copied have dollar signs ($) in them that have nothing to do with property expansion, and this creates the error SimpleTemplateScript6.groovy: 1: illegal string body character after dollar sign;
.
In my specific scenario, all the files except one can simply be copied as is. Only a single file, about.txt
, needs to have values substituted. Any suggestions on a simple way to do this?
You can run gradle distZip to package the main distribution as a ZIP, or gradle distTar to create a TAR file. To build both types of archives just run gradle assembleDist . The files will be created at $buildDir/distributions/${project.name}-${project. version}.
The Gradle user home directory ( $USER_HOME/.gradle by default) is used to store global configuration properties and initialization scripts as well as caches and log files.
Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.
“build. gradle” are scripts where one can automate the tasks. For example, the simple task to copy some files from one directory to another can be performed by the Gradle build script before the actual build process happens.
Now (Gradle 2.3.1) there is a better solution: https://issues.gradle.org/browse/GRADLE-1566
processResources {
inputs.property('version', version)
filesMatching("**/version.properties") {
expand version: version
} }
In my case I want project properties expansion only in yaml files:
processResources {
filesMatching("**/*.yaml") {
expand project.properties
}
}
Thanks to the link from Opal in the comments, I found a solution. The link shows that it is possible to have multiple from
sources and each of these can have a separate expand
treatment. Thus, in my case, I only wanted to expand .txt
files, so I split the from
into two parts using include
& exclude
as follows:
task "copyAndroidAssets$flavor" (type: Copy,
dependsOn: ["cleanAndroidAssets", "copyAndroidRes$flavor"] ) {
from ("build/assets/${flavorLc}/release/") {
include '**/*.txt'
expand ( versionName: versionName, versionCode: versionCode )
}
from ("build/assets/${flavorLc}/release/") {
exclude '**/*.txt'
}
into '../android/assets'
expand ( versionName: myVersionName, versionCode: myVersionCode )
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With