https://baidushabi.com 四十五 2020-03-26T08:20:49.699Z https://github.com/jpmonette/feed 随缘写写 https://baidushabi.com/images/avatar.png https://baidushabi.com/favicon.ico All rights reserved 2020, 四十五 <![CDATA[Groovy一时爽]]> https://baidushabi.com/post/groovy-is-very-ok/ 2020-03-20T05:10:54.000Z 闭包火葬场。
  • each { } : return ==> (Java) continue ----终止当前循环执行,继续后面的循环
  • find { } : return true ==> (Java) break ----终止所有闭包循环,返回当前it;
    return false ==> (Java) continue ----终止当前循环执行,继续后面的循环,如果最终没有return true,返回结果是null,find用于查找值,闭包参数用作终止条件(故需要布尔类型),也可以骚操作用来迭代。
  • with { } : 如果用来实例化类,别忘了返回值!
    def jack = new Person().with {
         name = "jack"
         age = 12
         //不return自己,就会返回age,最后jack会变成12
         return it
     }
    
  • 闭包嵌套,it傻傻分不清
    each {
          it.each {
              println it
          }
      }
    
语法骚断腿,使用需谨慎。
      // 可以
      def s = (1..10000).sum()
      println s

      //不红,会报错
      println (1..10000).sum()

      //可以,等于第一个
      println((1..10000).sum())

      //可以,不会报错,但是不太红,不是我们想要的
      1..10000.each {
          println it
      }

      //可以
      (1..10000).each {
          println it
      }

      //索引0开始,用值需谨慎
      10000.times {

      }
]]>
<![CDATA[写一个maven插件]]> https://baidushabi.com/post/write-a-maven-plugin/ 2019-03-06T05:06:45.000Z 核心类:

AbstractMojo

核心依赖注入:

@Parameter(defaultValue = "${project}", readonly = true)

参数注入(pom或-D):

@Parameter(property = "config.name")

重写:

execute()

配置pom:
<plugin>
  <groupId>xxx</groupId>
  <artifactId>xxx</artifactId>
  <!--注意使用最新版本-->
  <version>1.1</version>
  <configuration>
      <name>xxxx.xxxx.xxx</name>
  </configuration>
  <executions>
      <execution>
          <phase>process-resources</phase>
          <goals>
              <goal>xxx</goal>
          </goals>
      </execution>
  </executions>
</plugin>
]]>