You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Groovy 3.0.19中picocli requiredOptionMarker类型转换报错求助

Groovy 3.x中picocli @Command注解requiredOptionMarker属性赋值失败问题

问题现象

脚本在Groovy 3.0.19中运行失败,但在Groovy 4.0.15中可正常运行。

背景

尝试遵循picocli文档中Groovy脚本相关说明,其中@Command注解的requiredOptionMarker属性要求接收char类型值。

报错场景

当为requiredOptionMarker赋值'*'时,编译失败:

@Command(name = "sampleScript",
        mixinStandardHelpOptions = true,
        requiredOptionMarker = '*')

报错信息如下:

Attribute 'requiredOptionMarker' should have type 'java.lang.Character'; but found type 'java.lang.String' in @picocli.CommandLine$Command
 @ line 63, column 32.
           requiredOptionMarker = '*',
                                  ^

1 error

已尝试的解决方法

  • 尝试过(char) '*'、'*' as char等类型转换方式,均无效
  • 找到相关Groovy问题工单:GROOVY-3278
  • 使用((char)'*')赋值时,仍报错:
    代码示例:
    sortOptions = false,
        requiredOptionMarker = ((char)'*') //---->>>>>> This DOES"T WORK
    
    报错信息:
    >groovy sample-picocli.groovy
    
    org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
    C:\ws\sample-picocli.groovy: 35: Expected '(char) *' to be an inline constant of type char in @picocli.CommandLine$Command
     @ line 35, column 32.
               requiredOptionMarker = ((char)'*') //---->>>>>> This DOES"T WORK
                                      ^
    
    C:\ws\picocli\sample-picocli.groovy: 35: Attribute 'requiredOptionMarker' should have type 'java.lang.Character'; but found type 'java.lang.Object' in @picocli.CommandLine$Command
     @ line 35, column 32.
               requiredOptionMarker = ((char)'*') //---->>>>>> This DOES"T WORK
                                      ^
    
    C:\ws\picocli\sample-picocli.groovy: 35: Expected '(char) *' to be an inline constant of type char in @picocli.CommandLine$Command
     @ line 35, column 32.
               requiredOptionMarker = ((char)'*') //---->>>>>> This DOES"T WORK
                                      ^
    
    C:\ws\picocli\sample-picocli.groovy: 35: Attribute 'requiredOptionMarker' should have type 'java.lang.Character'; but found type 'java.lang.Object' in @picocli.CommandLine$Command
     @ line 35, column 32.
               requiredOptionMarker = ((char)'*') //---->>>>>> This DOES"T WORK
                                      ^
    
    4 errors
    

内容的提问来源于stack exchange,提问作者Asif Kamran Malick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 08:10:10