【问题标题】:Determine in a Maven Plugin whether Batch mode is active在 Maven 插件中确定批处理模式是否处于活动状态
【发布时间】:2022-11-18 19:04:40
【问题描述】:

当我编写 Mojo 时,如何确定我当前是否处于批处理模式(即在命令行上给出了 -B 参数)?

【问题讨论】:

    标签: java maven maven-plugin


    【解决方案1】:

    我查看了 Maven 原型插件的源代码(准确地说是 generatemojo):

    他们只是将布尔值注入 mojo:

      /**
         * User settings used to check the interactiveMode.
         */
        @Parameter( property = "interactiveMode", defaultValue = "${settings.interactiveMode}", required = true )
        private Boolean interactiveMode;
    

    看看here,注意源码里他们是怎么用的:

      if ( interactiveMode.booleanValue() )
      {
            getLog().info( "Generating project in Interactive mode" );
      }
      else
      {
            getLog().info( "Generating project in Batch mode" );
      }
    

    【讨论】:

    • 如果 OP 想避免实际为他的插件引入配置参数,他可能也希望在注释上使用 readonly = true。认为它应该工作,但现在无法测试。
    猜你喜欢
    • 1970-01-01
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-17
    • 2016-08-29
    • 2019-01-05
    相关资源
    最近更新 更多