picocli

remkopApache-2.0活跃维护

用注解快速构建 Java 命令行应用,支持子命令、彩色输出、自动补全和 GraalVM 原生镜像,还能单文件引入免依赖。

Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line apps with ease. It supports colors, autocompletion, subcommands, and more. In 1 source file so apps can include as source & avoid adding a dependency. Written in Java, usable from Groovy, Kotlin, Scala, etc.

v4.7.7发布于 2025-04-19 01:21 UTC5,454star +1 / 7 天498fork同步于 2026-11-10 17:37 UTC

怎么上手

由 README 提炼,执行前请确认
implementation 'info.picocli:picocli:4.7.7'
硬件要求按 README 说明

README 未说明;仅要求 Java 5 及以上运行环境,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用注解把 Java 类变成带子命令、彩色帮助和补全的 CLI,还能编成 GraalVM 原生镜像

用注解快速构建 Java 命令行应用,支持子命令、彩色输出、自动补全和 GraalVM 原生镜像,还能单文件引入免依赖。

核心能力

  • 注解式声明选项与位置参数并强类型转换
  • 支持 git 式子命令与嵌套子子命令
  • 生成带 ANSI 颜色和样式的用法与版本帮助
  • 为 bash/zsh 生成 TAB 补全脚本
  • 单文件源码可内嵌,免加外部依赖

容易踩的坑

想免依赖需手动复制 CommandLine.java 单文件进项目;交互式 shell 补全要额外引入 picocli-shell-jline2 或 jline3 模块;GraalVM 原生镜像需配合注解处理器在编译期完成配置

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v4.7.7
  1. v4.7.7Picocli 4.7.7最新正式版2025-04-19 · 2025-04-19 01:21 UTC

    Picocli 4.7.7

    The picocli community is pleased to announce picocli 4.7.7.

    This release includes bugfixes and enhancements.

    Many thanks to the picocli community for raising these issues and providing the pull requests to address them!

    This is the eighty-sixth public release. Picocli follows semantic versioning. Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96).

    Table of Contents

    New and Noteworthy

    This release fixes a problem that was introduced in the previous release (4.7.6), where using an ArgGroup in a Mixin would result in options being added twice, or DuplicateOptionAnnotationsException.

    The built-in picocli.CommandLine.HelpCommand subcommand now implements Callable<Integer> and returns the exit code of the subcommand's exitCodeOnUsageHelp value for the subcommand whose help was requested.

    From this release, if a command implements both Callable and Runnable, then the default execution strategy will invoke the call method instead of the run method.

    Fixed issues

    • [#2353] Enhancement: picocli.shell.jline3.PicocliCommands::invoke now returns ParseResult instead of null. Thanks to Paul for raising this.
    • [#2336] Enhancement: Avoid syntax error in auto-completion script for invalid option names and paramLabel values starting with a digit. Thanks to Ruud Senden and Tobias Knerr for raising this.
    • [#2281] Enhancement: Variable interpolation should work for ArgGroup.heading attribute. Thanks to Marc Philipp for raising this.
    • [#2355] Bugfix: The built-in help subcommand should return the exit code of the subcommand's exitCodeOnUsageHelp value for the subcommand whose help was requested. Thanks to marco-brandizi for raising this.
    • [#2335] Bugfix: Module info missing in all jars except the main picocli jar file. Thanks to Oliver B. Fischer for raising this.
    • [#2331] Bugfix: AutoComplete with jline3 was showing hidden commands. Thanks to clebertsuconic for raising this.
    • [#2291] Bugfix: NullPointerException when using PropertiesDefaultProvider. Thanks to JessHolle for raising this.
    • [#2344] Bugfix: negatable=true option in an ArgGroup should not add negated option twice. Thanks to Robin Fritz for raising this.
    • [#2309] Bugfix: Duplicate help output for ArgGroup from a Mixin. Thanks to s-falke for raising this. Thanks to Simon Gamma for providing a pull request for this.
    • [#2341] Bugfix: Options get doubled in non validating ArgGroup when used in Mixin. Thanks to Selene Feigl for raising this.
    • [#2349] Bugfix: Incorrect results when using ArgGroup + defaultValue + split + List/Set. Thanks to Mithun Josalyn Gonsalvez for raising this.
    • [#2292] Bugfix: DuplicateOptionAnnotationsException on using negatable option in ArgGroup. Thanks to Bhavik Patel for raising this.
    • [#2380] Bugfix: boolean with arity=0 and defaultValue=false behaved unexpectedly. Thanks to Leonard Brünings for raising this.
    • [#2290] DOC: User guide, CDI 2.0 (JSR 365) section: fix example and add warning about dynamic proxies. Thanks to Mert Zeybekler for the pull request.
    • [#2347] DOC: Fix line-endings in generated asciidoc HTML. Tha
  2. v4.7.6Picocli 4.7.62024-05-08 · 2024-05-08 00:30 UTC
    查看更新说明

    Picocli 4.7.6

    The picocli community is pleased to announce picocli 4.7.6.

    This release includes bugfixes and enhancements.

    Many thanks to the picocli community for raising these issues and providing the pull requests to address them!

    This is the eighty-fifth public release. Picocli follows semantic versioning. Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96).

    Table of Contents

    New and Noteworthy

    PropertiesDefaultProvider now tries to load properties from the classpath if the file cannot be found in the user.home directory.

    Fixed issues

    • [#2102][#2107] Enhancement: PropertiesDefaultProvider should try to load properties from classpath (last). Thanks to Lumír Návrat for the pull request.
    • [#2202] Enhancement: Change log level from WARN to INFO when bean not found in ApplicationContext. Thanks to Desmond Kirrane for raising this.
    • [#2248] Enhancement: Don't show hidden commands in JLine3 command description. Thanks to Reinhard Handler for the pull request.
    • [#2170] Enhancement: Use ... vararg instead of array parameter to match overridden method signature. Thanks to Michael Vorburger for the pull request.
    • [#2058] Bugfix: defaultValue should not be applied in addition to user-specified value for options with a custom IParameterConsumer. Thanks to Staffan Arvidsson McShane for raising this.
    • [#2148] Bugfix: Fix NPE in jline3 Example.jar as ConfigurationPath cannot be null anymore. Thanks to llzen44 for the pull request.
    • [#2232] Bugfix: fix bug for Optional<T> arguments with initial value. Thanks to hq6 for raising this.
    • [#2149] Bugfix: @Option-annotated setter method not invoked with default value when used in mixin for both command and subcommand. Thanks to Zhonghao Wang for raising this.
    • [#2270] Bugfix: Custom type converter for primitive boolean options should not be ignored. Thanks to Sven Kammerer for raising this.
    • [#2234] BUILD: fix errorprone TruthSelfEquals warnings
    • [#2172] BUILD: Fix broken build. Thanks to Michael Vorburger for the pull request.
    • [#2174] BUILD: Fix .gitattributes related CR/LF problems. Thanks to Michael Vorburger for the pull request.
    • [#2054][#2176] BUILD: Add Error Prone. Thanks to Michael Vorburger for the pull request.
    • [#2053] [#2175] CLEAN: Remove unused extra format arguments. Thanks to Michael Vorburger for the pull request.
    • [#2171] DOC: Fix a few typos in CommandLine's JavaDoc. Thanks to Michael Vorburger for the pull request.
    • [#2217] DOC: Clarify documentation for negatable options. Thanks to dbear496 for raising this.
    • [#2228] DOC: Clarify that ParseResult passed to IExecutionExceptionHandler is the top-level parse result, not the parse result of the subcommand that failed. Thanks to Abel Salgado Romero for raising this.
    • [#2047] DEP: Bump andymckay/append-gist-action from 1fbfbbce708a39bd45846f0955ed5521f2099c6d to 6e8d64427fe47cbacf4ab6b890411f1d67c07f3e
    • [#2091] DEP: Bump actions/checkout from 3.5.2 to 3.6.0
    • [#2108] DEP: Bump actions/checkout from 3.6.0 to 4.0.0
    • [#2120] DEP: Bump actions/checkout from 4.0.0 to 4.1.0
    • [#2225] DEP: Bump actions/checkout from 4.1.0 to 4.1.2
    • [#
  3. v4.7.5Picocli 4.7.52023-08-26 · 2023-08-26 23:07 UTC
    查看更新说明

    Picocli 4.7.5

    The picocli community is pleased to announce picocli 4.7.5.

    This release includes bugfixes and enhancements.

    Many thanks to the picocli community for raising these issues and providing the pull requests to address them!

    This is the eighty-forth public release. Picocli follows semantic versioning. Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96).

    Table of Contents

    New and Noteworthy

    Fixed issues

    • [#2083][#2084] Enhancement: Java 22 update: improve logic for detecting if the output stream is connected to a terminal. Thanks to Liam Miller-Cushon for the pull request.
    • [#2087] Enhancement: Mask parameters in trace log when echo=false for interactive options and positional parameters. Thanks to szzsolt for raising this.
    • [#2060] Bugfix: Fix positional parameters bug with late-resolved arity variable. Thanks to daisukeoto for raising this.
    • [#2074][#2075] Bugfix: Don't generate auto-complete for hidden attributes in picocli.shell.jline3.PicoCommand. Thanks to clebertsuconic for the pull request.
    • [#2059] Bugfix: ArgGroup with exclusive=false and multiplicity=1 should require at least one option; fix regression and refine solution introduced in [#1848][#2030]. Thanks to Utkarsh Mittal for raising this.
    • [#2080] DOC: Improve GraalVM documentation: add graalvm-native-image-plugin. Thanks to Bhavik Patel for the pull request.
    • [#2045] DOC: Commit html files with LF line-endings. Thanks to Fridrich Strba for the pull request.

    Deprecations

    No features were deprecated in this release.

    Potential breaking changes

    This release has no breaking changes.

  4. v4.7.4Picocli 4.7.42023-06-03 · 2023-06-03 01:14 UTC
    查看更新说明

    Picocli 4.7.4

    The picocli community is pleased to announce picocli 4.7.4.

    This release includes bugfixes and enhancements.

    Many thanks to the picocli community for raising these issues and providing the pull requests to address them!

    This is the eighty-third public release. Picocli follows semantic versioning. Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96).

    Table of Contents

    New and Noteworthy

    See fixed items below.

    I cheated on the semantic versioning in this release: a public setter method was added in a class in the picocli.shell.jline3 module. In spite of that, the version number went from 4.7.3 to 4.7.4 (not 4.8.0). My apologies.

    Fixed issues

    • [#2028][#2031] API: Add setter for name in picocli.shell.jline3.PicocliCommands. Thanks to Irina Leontyuk for raising this.
    • [#2026][#2027] Enhancement: Improved feedback on mistyped subcommands. Thanks to David Pond for the pull request.
    • [#2029][#2034] Enhancement: prevent java.nio.charset.UnsupportedCharsetException: cp0 on windows, and fall back to the default charset if the charset provided by System property sun.stdout.encoding is invalid. Thanks to Bartosz Spyrko-Smietanko for the pull request.
    • [#2035][#2036] Bugfix: Option "mapFallbackValue" ignored when inherited to subcommand. Thanks to Dan Ziemba for the pull request.
    • [#1848][#2030] Bugfix: fix issue with required options in ArgGroup becoming optional when combined with DefaultValueProvider. Thanks to Ruud Senden and Mike Snowden for the pull request.
    • [#2020] DEP: Bump step-security/harden-runner from 2.3.0 to 2.4.0
    • [#2033] DEP: Bump github/codeql-action from 2.2.12 to 2.3.5
    • [#2015] DEP: Bump junit5Version from 5.9.2 to 5.9.3
    • [#2014] DEP: Bump org.jetbrains.kotlin:kotlin-gradle-plugin from 1.8.20 to 1.8.21
    • [#2013] DEP: Bump org.jetbrains.kotlin:kotlin-script-runtime from 1.8.20 to 1.8.21
    • [#2008] DEP: Bump springBootVersion from 2.7.10 to 2.7.11
    • [#2007] DEP: Bump org.asciidoctor:asciidoctorj-pdf from 2.3.6 to 2.3.7

    Deprecations

    No features were deprecated in this release.

    Potential breaking changes

    This release has no breaking changes.

  5. v4.7.3Picocli 4.7.32023-04-16 · 2023-04-16 07:27 UTC
    查看更新说明

    Picocli 4.7.3

    The picocli community is pleased to announce picocli 4.7.3.

    This release includes bugfixes and enhancements.

    This is the eighty-second public release. Picocli follows semantic versioning. Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96).

    Table of Contents

    New and Noteworthy

    Fixed a regression introduced in picocli 4.7.2. Multi-value options whose fallbackValue is set to CommandLine.Option.NULL_VALUE, may see a NullPointerException if the option is specified on the command line without a parameter but with a = attached, like --option=.

    Also, this release fixes broken links in the Javadoc.

    Known issues

    NOTE: A minor issue with this release is that the version string in the info.picocli.CommandLine.VERSION field is incorrectly set to 4.7.3-SNAPSHOT (should have been 4.7.3).

    Fixed issues

    • [#1998] Bugfix: ParameterException: NullPointerException: null while processing argument at or before arg[0]. Thanks to Jiri Daněk for raising this.
    • [#1957] DOC: Fixed broken links in the javadoc. Thanks to Andreas Deininger for raising this.
    • [#2002] DEP: Bump actions/checkout from 3.5.0 to 3.5.2
    • [#2005] DEP: Bump gradle/gradle-build-action from 2.4.0 to 2.4.2
    • [#2003] DEP: Bump github/codeql-action from 2.2.11 to 2.2.12
    • [#1997] DEP: Bump org.asciidoctor:asciidoctorj-pdf from 2.3.4 to 2.3.6

    Deprecations

    No features were deprecated in this release.

    Potential breaking changes

    This release has no breaking changes.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    GitHub Release Maven Central GitHub Actions Build Status Tests codecov Follow @remkopopma Follow @picocli Follow picocli on StackShare

    picocli - a mighty tiny command line interface

    Picocli aims to be the easiest-to-use way to create rich command line applications that can run on and off the JVM. Considering picocli? Check what happy users say about picocli.

    Picocli is a modern library and framework, written in Java, that contains both an annotations API and a programmatic API. It features usage help with ANSI colors and styles, TAB autocompletion and nested subcommands. In a single file, so you can include it in source form. This lets users run picocli-based applications without requiring picocli as an external dependency.

    Picocli-based applications can be ahead-of-time compiled to a native image, with extremely fast startup time and lower memory requirements, which can be distributed as a single executable file. Picocli comes with an annotation processor that automatically Graal-enables your jar during compilation.

    Picocli applications can be very compact with no boilerplate code: your command (or subcommand) can be executed with a single line of code. Simply implement Runnable or Callable, or put the business logic of your command in a @Command-annotated method.

    Picocli Demo help message with ANSI colors

    Picocli makes it easy to follow Command Line Interface Guidelines.

    How it works: annotate your class and picocli initializes it from the command line arguments, converting the input to strongly typed data. Supports git-like subcommands (and nested sub-subcommands), any option prefix style, POSIX-style grouped short options, custom type converters, password options and more.

    Picocli distinguishes between named options and positional parameters and allows both to be strongly typed. Multi-valued fields can specify an exact number of parameters or a range (e.g., 0..*, 1..2). Supports Map options like -Dkey1=val1 -Dkey2=val2, where both key and value can be strongly typed. Parser tracing facilitates troubleshooting. Command-line argument files (@-files) allow applications to handle very long command lines.

    Generates polished and easily tailored usage help and version help, using ANSI colors where possible. Requires at minimum Java 5, but is designed to facilitate the use of Java 8 lambdas. Tested on all Java versions between 5 and 18-ea (inclusive).

    Picocli-based command line applications can have TAB autocompletion, interactively showing users what options and subcommands are available. When an option has completionCandidates or has an enum type, autocompletion can also suggest option values. Picocli can generate completion scripts for bash and zsh, and offers picocli-shell-jline2 and picocli-shell-jline3 modules with JLine Completer implementations for building interactive shell applications.

    Unique features in picocli include support for negatable options, advanced quoted values, and argument groups. Argument groups can be used to create mutually exclusive options, mutually dependent options, option sections in the usage help message and repeating composite arguments like ([-a=<a> -b=<b> -c=<c>] (-x | -y | -z)).... For advanced use cases, applications can access the picocli command object model with the @Spec annotation, and implement custom parameter processing for option parameters if the built-in logic is insufficient.

    Picocli-based applications can easily integrate with Dependency Injection containers. The Micronaut microservices framework has built-in support for picocli. Quarkus has a Command Mode with Picocli extension for facilitating the creation of picocli-based CLI applications with Quarkus. Picocli ships with a picocli-spring-boot-starter module that includes a PicocliSpringFactory and Spring Boot auto-configuration to use Spring dependency injection in your picocli command line application. The user manual has examples of integrating with Guice, Spring Boot, Micronaut, Quarkus and with containers that comply to CDI 2.0 specification (JSR 365).

    Releases

    Documentation

    Older

    Articles & Presentations

    English
    русский
    Español
    Français
    Português
    日本語
    中文

    Mailing List

    Join the picocli Google group if you are interested in discussing anything picocli-related and receiving announcements on new releases.

    Credit

    Reallinfo designed the picocli logo! Many thanks!

    Commitments

    This project follows semantic versioning and adheres to the Zero Bugs Commitment.

    Adoption

    • Picocli is now part of Groovy. From Groovy 2.5, all Groovy command line tools are picocli-based, and picocli is the underlying parser for Groovy's CliBuilder DSL.
    • Picocli is now part of Micronaut. The Micronaut CLI has been rewritten with picocli, and Micronaut has dedicated support for running microservices standalone with picocli. See also Micronaut Picocli Guide.
    • Quarkus now offers Command mode with picocli.
    • Picocli is now part of JUnit 5. JUnit 5.3 migrated its ConsoleLauncher from jopt-simple to picocli to support @-files (argument files); this helps users who need to specify many tests on the command line and run into system limitations.
    • Debian now offers a libpicocli-java package. Thanks to Miroslav Kravec.
    • Picocli is used in the Intuit Karate standalone JAR / executable.
    • Picocli is part of Ballerina. Ballerina uses picocli for all its command line utilities.
    • Picocli is used in the CheckStyle standalone JAR / executable from Checkstyle 8.15.
    • Picocli is included in the OpenJDK Quality Outreach list of Free Open Source Software (FOSS) projects that actively test against OpenJDK builds.
    • Picocli is used in the Apache Hadoop Ozone/HDDS command line tools, the Apache Hive benchmark CLI, Apache Ignite TensorFlow, and Apache Sling Feature Model Converter.
    • Picocli is listed on StackShare. Please add it to your stack and add/upvote reasons why you like picocli!
    • Picocli is used in Pinterest ktlint.
    • Picocli is used in Spring IO nohttp-cli.
    • The MinecraftPicocli library facilitates the use of picocli in Minecraft Forge.
    • Simple Java Mail now offers a picocli-based CLI.
    • jbang not only uses picocli internally, but also has a CLI template to generate an initial script: use jbang --init=cli helloworld.java to generate a sample picocli-enabled jbang script. See asciinema.
    • Picocli is the main library used in the CookieTemple cli-java template for building GraalVM native CLI executables in Java. See this preview.
    • Picocli is mentioned in Command Line Interface Guidelines.

    Glad to see more people are using picocli. We must be doing something right. :-)

    Contribute by helping to promote picocli

    If you like picocli, help others discover picocli:

    Easy and impactful :sweat_smile:
    • Give picocli a star on GitHub!
    • Upvote my StackOverflow answer to "How do I parse command line arguments in Java?"
    • Upvote my Quora answer to "What is the best way to parse command-line arguments with Java?"
    Spread the joy! :tada:
    • Tweet about picocli! What do you like about it? How has it helped you? How is it different from the alternatives?
    • Mention that your project uses picocli in the documentation of your project.
    • Show that your GitHub project uses picocli, with this badge in your README.md: picocli
    [![picocli](https://img.shields.io/badge/picocli-4.7.7-green.svg)](https://github.com/remkop/picocli)
    
    Preach it! :muscle:
    • Perhaps the most impactful way to show people how picocli can make their life easier is to write a blog post or article, or even do a video!

    Example

    Annotate fields with the command line parameter names and description. Optionally implement Runnable or Callable to delegate error handling and requests for usage help or version help to picocli. For example:

    import picocli.CommandLine;
    import picocli.CommandLine.Command;
    import picocli.CommandLine.Option;
    import picocli.CommandLine.Parameters;
    import java.io.File;
    
    @Command(name = "example", mixinStandardHelpOptions = true, version = "Picocli example 4.0")
    public class Example implements Runnable {
    
        @Option(names = { "-v", "--verbose" },
          description = "Verbose mode. Helpful for troubleshooting. Multiple -v options increase the verbosity.")
        private boolean[] verbose = new boolean[0];
    
        @Parameters(arity = "1..*", paramLabel = "FILE", description = "File(s) to process.")
        private File[] inputFiles;
    
        public void run() {
            if (verbose.length > 0) {
                System.out.println(inputFiles.length + " files to process...");
            }
            if (verbose.length > 1) {
                for (File f : inputFiles) {
                    System.out.println(f.getAbsolutePath());
                }
            }
        }
    
        public static void main(String[] args) {
            // By implementing Runnable or Callable, parsing, error handling and handling user
            // requests for usage help or version help can be done with one line of code.
    
            int exitCode = new CommandLine(new Example()).execute(args);
            System.exit(exitCode);
        }
    }
    

    Implement Runnable or Callable, and your command can be executed in one line of code. The example above uses the CommandLine.execute method to parse the command line, handle errors, handle requests for usage and version help, and invoke the business logic. Applications can call System.exit with the returned exit code to signal success or failure to their caller.

    $ java Example -v inputFile1 inputFile2
    
    2 files to process...
    

    The CommandLine.execute method automatically prints the usage help message if the user requested help or when the input was invalid.

    Usage help message with ANSI colors

    This can be customized in many ways. See the user manual section on Executing Commands for details.

    Usage Help with ANSI Colors and Styles

    Colors, styles, headers, footers and section headings are easily customized with annotations. For example:

    Longer help message with ANSI colors

    See the source code.

    Usage Help API

    Picocli annotations offer many ways to customize the usage help message.

    If annotations are not sufficient, you can use picocli's Help API to customize even further. For example, your application can generate help like this with a custom layout:

    Usage help message with two options per row

    See the source code.

    Download

    You can add picocli as an external dependency to your project, or you can include it as source. See the source code. Copy and paste it into a file called CommandLine.java, add it to your project, and enjoy!

    Gradle

    implementation 'info.picocli:picocli:4.7.7'
    

    Maven

    <dependency>
      <groupId>info.picocli</groupId>
      <artifactId>picocli</artifactId>
      <version>4.7.7</version>
    </dependency>
    

    Scala SBT

    libraryDependencies += "info.picocli" % "picocli" % "4.7.7"
    

    Ivy

    <dependency org="info.picocli" name="picocli" rev="4.7.7" />
    

    Grape

    @Grapes(
        @Grab(group='info.picocli', module='picocli', version='4.7.7')
    )
    

    Leiningen

    [info.picocli/picocli "4.7.7"]
    

    Buildr

    'info.picocli:picocli:jar:4.7.7'
    

    JBang

    //DEPS info.picocli:picocli:4.7.7