'gradle script to escape single quote before build
I've got i18n messages files with translations. The problem is in that some languages (Italian for example) use single quotes in some words. I want to run some script (may be as a gradle.build task) to replace single quotes with double quotes. I paste following code into my build.gradle.kts file
task("replaceSingleQuotes") {
doLast {
ant.ReplaceRegExp(match:'\'', replace:'\'\'', flags:'g', byline:false) {
fileset(dir: 'src/main/resources/i18n/', includes: '*')
}
}
}
The first problem is in that now my project failed to configure with following errors:
e: build.gradle.kts:139:32: Expecting ')'e: D:\Sources\delivery-backend\build.gradle.kts:139:33: Unexpected tokens (use ';' to separate expressions on the same line)
e: build.gradle.kts:140:15: Expecting ')'
e: build.gradle.kts:140:17: Unexpected tokens (use ';' to separate expressions on the same line)
e: build.gradle.kts:154:13: Expecting an element
e: build.gradle.kts:155:28: Expecting ')'
e: build.gradle.kts:155:29: Unexpected tokens (use ';' to separate expressions on the same line)
e: build.gradle.kts:156:20: Expecting ')'
e: build.gradle.kts:156:22: Unexpected tokens (use ';' to separate expressions on the same line)
e: build.gradle.kts:139:13: Unresolved reference: ReplaceRegExp
e: build.gradle.kts:139:27: Unresolved reference: match
e: build.gradle.kts:140:4: Unresolved reference: fileset
e: build.gradle.kts:140:12: Function invocation 'dir(...)' expected
e: build.gradle.kts:140:12: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline fun SourceSetOutput.dir(dir: Any, vararg options: Pair<String, Any?>): Unit defined in org.gradle.kotlin.dsl
e: build.gradle.kts:154:1: Function invocation 'task(...)' expected
e: build.gradle.kts:154:1: None of the following functions can be called with the arguments supplied:
public abstract fun task(p0: String!): Task! defined in org.gradle.api.Project
public abstract fun task(p0: String!, p1: Closure<(raw) Any!>!): Task! defined in org.gradle.api.Project
public abstract fun task(p0: String!, p1: Action<in Task!>!): Task! defined in org.gradle.api.Project
public abstract fun task(p0: (Mutable)Map<String!, *>!, p1: String!): Task! defined in org.gradle.api.Project
public abstract fun task(p0: (Mutable)Map<String!, *>!, p1: String!, p2: Closure<(raw) Any!>!): Task! defined in org.gradle.api.Project
e: build.gradle.kts:155:9: Unresolved reference: replaceregexp
e: build.gradle.kts:155:23: Unresolved reference: match
e: build.gradle.kts:156:9: Unresolved reference: fileset
e: build.gradle.kts:156:17: Function invocation 'dir(...)' expected
e: build.gradle.kts:156:17: Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline fun SourceSetOutput.dir(dir: Any, vararg options: Pair<String, Any?>): Unit defined in org.gradle.kotlin.dsl
The second problem, I guess, is in that every time my task executed it'll add more and more double quotes. Thus, two questions here: how to make my project configure with this task and how to change regex to match only single quote?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
