spring 用于在构建前转义单引号的gradle脚本

g9icjywg  于 2023-02-11  发布在  Spring
关注(0)|答案(1)|浏览(191)

我有带翻译的i18n消息文件。问题在于某些语言(例如意大利语)在某些单词中使用单引号。我想运行一些脚本(可能是gradle.build任务),将单引号替换为双引号。我将以下代码粘贴到build.gradle.kts文件中

task("replaceSingleQuotes") {
    doLast {
        ant.ReplaceRegExp(match:'\'', replace:'\'\'', flags:'g', byline:false) {
            fileset(dir: 'src/main/resources/i18n/', includes: '*')
        }
    }
}

第一个问题是,现在我的项目未能配置以下错误:

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

第二个问题,我想,是因为每次我的任务执行时,它会添加越来越多的双引号。因此,这里有两个问题:如何使用此任务配置我项目,以及如何更改regex以仅匹配单引号?

gzszwxb4

gzszwxb41#

使用与“([^\])'”匹配并替换“\1\\'”应该有效
如这里所建议的https://stackoverflow.com/a/60127123

相关问题