我怎么能在gradle.properties指定正则表达式? - How can I specify a regular expression in gradle.properties?

- 此内容更新于:2015-12-20
主题:

我的文件有以下定义:它是用于方法如下:这种方法可以很好地工作,但是当我去试着允许更一般的正则表达式,分解的东西:我认为这与指定正则表达式不正确,但我使用正则表达式代似乎表明,正则表达式是正确的,并会给我我要找什么。我认为这可能与gradle括号。属性,指定以来还生成相同的例外。

原文:

I have the following definition in my gradle.properties file:

# A regular expression for extracting ticket numbers from commit messages       
ticketRegEx=AND-[0-9]+

It's used in a method like the following:

ext.getIssueNumbersFromLatestAlpha = { 
  def issueNumbers = [] 
  def commits = getCommitMessagesInRange('latest-alpha', 'HEAD')
  commits.each() { message ->
    def issueNumMatcher = message =~ /${project.ticketRegEx}/
    if (issueNumMatcher.size() > 0) {
      issueNumbers << issueNumMatcher[0].replace("(", "").replace(")", "")        }                                                                        }      
  return issueNumbers.toSet()
}

This works pretty well, but when I go to try and allow for a more general regex, things break down:

ticketRegEx=(\#[0-9]+)|(AND-[0-9]+)

./gradlew releaseNotes

* Where:
Build file '/Users/scottjohnson/Source/wheniwork-android/WhenIWork/build.gradle' line: 103

* What went wrong:
A problem occurred evaluating project ':WhenIWork'.
> Could not find method getReleaseNotes() for arguments [alpha] on BuildType_Decorated{name=debug, debuggable=true, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, applicationIdSuffix=null, versionNameSuffix=-e506db5, minifyEnabled=false, zipAlignEnabled=false, signingConfig=SigningConfig_Decorated{name=debug, storeFile=/Users/scottjohnson/Source/wheniwork-android/debug.keystore, storePassword=android, keyAlias=wheniwork, keyPassword=android, storeType=/Users/scottjohnson/Source/wheniwork-android/debug.keystore}, embedMicroApp=false, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}}.

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':WhenIWork'.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:76)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$1.run(DefaultScriptPluginFactory.java:148)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:156)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:39)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:487)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:85)
    at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:47)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:90)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:49)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:37)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.health.DaemonHealthTracker.execute(DaemonHealthTracker.java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:66)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:71)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.health.HintGCAfterBuild.execute(HintGCAfterBuild.java:41)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method getReleaseNotes() for arguments [alpha] on BuildType_Decorated{name=debug, debuggable=true, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, applicationIdSuffix=null, versionNameSuffix=-e506db5, minifyEnabled=false, zipAlignEnabled=false, signingConfig=SigningConfig_Decorated{name=debug, storeFile=/Users/scottjohnson/Source/wheniwork-android/debug.keystore, storePassword=android, keyAlias=wheniwork, keyPassword=android, storeType=/Users/scottjohnson/Source/wheniwork-android/debug.keystore}, embedMicroApp=false, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}}.
    at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:68)
    at org.gradle.api.internal.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:56)
    at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:175)
    at com.android.build.gradle.internal.dsl.BuildType_Decorated.invokeMethod(Unknown Source)
    at build_bkmx47wa6tcrmf0go4x11gcnv$_run_closure5_closure16_closure27.doCall(/Users/scottjohnson/Source/wheniwork-android/WhenIWork/build.gradle:103)
    at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:67)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:130)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:91)
    at org.gradle.api.internal.DefaultNamedDomainObjectCollection$ContainerElementsDynamicObject.invokeMethod(DefaultNamedDomainObjectCollection.java:341)
    at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:150)
    at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:150)
    at org.gradle.api.internal.ConfigureDelegate.invokeMethod(ConfigureDelegate.java:62)
    at build_bkmx47wa6tcrmf0go4x11gcnv$_run_closure5_closure16.doCall(/Users/scottjohnson/Source/wheniwork-android/WhenIWork/build.gradle:97)
    at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:67)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:130)
    at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:91)
    at org.gradle.api.internal.AbstractNamedDomainObjectContainer.configure(AbstractNamedDomainObjectContainer.java:68)
    at org.gradle.api.internal.AbstractNamedDomainObjectContainer.configure(AbstractNamedDomainObjectContainer.java:24)
    at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:59)
    at org.gradle.api.Action$execute.call(Unknown Source)
    at com.android.build.gradle.BaseExtension.buildTypes(BaseExtension.groovy:327)
    at com.android.build.gradle.AppExtension_Decorated.buildTypes(Unknown Source)
    at build_bkmx47wa6tcrmf0go4x11gcnv$_run_closure5.doCall(/Users/scottjohnson/Source/wheniwork-android/WhenIWork/build.gradle:96)
    at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:67)
    at org.gradle.api.internal.plugins.ExtensionsStorage$ExtensionHolder.configure(ExtensionsStorage.java:145)
    at org.gradle.api.internal.plugins.ExtensionsStorage.configureExtension(ExtensionsStorage.java:69)
    at org.gradle.api.internal.plugins.DefaultConvention$ExtensionsDynamicObject.invokeMethod(DefaultConvention.java:207)
    at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:150)
    at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:79)
    at build_bkmx47wa6tcrmf0go4x11gcnv.run(/Users/scottjohnson/Source/wheniwork-android/WhenIWork/build.gradle:59)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:74)
    ... 46 more


BUILD FAILED

I think this has something to do with specifying my regular expression incorrectly, but the regex generation I'm using seems to indicate that the regular expression is correct, and will give me what I'm looking for. I think it might have something to do with the parentheses in gradle.properties, since specifying (AND-[0-9]+) as the ticketRegEx also generates the same exception.

楼主:另外,以下:如果我把它直接在代码代替,但如果我把它在正则表达式的地方。

(原文:Also, the following: \(\#[0-9]+\)|\(AND-[0-9]+\) works if I place it directly in the code in place of ${project.ticketRegEx}, but not if I put it in gradle.properties in place of the regular expression.)

网友:吗?

(原文:def issueNumMatcher = java.util.regex.Pattern.compile(project.ticketRegEx).matcher(message) ?)