groovy入门(2-1)Groovy的Maven插件安装:Plugin execution not covered by lifecycle configuration

时间:2023-01-26 09:58:16

参考链接:http://www.cnblogs.com/rightmin/p/4945797.html

1、引入groovy的jar包

groovy入门(2-1)Groovy的Maven插件安装:Plugin execution not covered by lifecycle configuration

 2、引入groovy编译插件

groovy入门(2-1)Groovy的Maven插件安装:Plugin execution not covered by lifecycle configuration

3、遇到问题 Plugin execution not covered by lifecycle configuration

groovy入门(2-1)Groovy的Maven插件安装:Plugin execution not covered by lifecycle configuration

4、解决办法

      quickfix+删除重导入工程大法!!

      下面是网上介绍的解决方法,下次遇到再试试:

     groovy入门(2-1)Groovy的Maven插件安装:Plugin execution not covered by lifecycle configuration

 

5、附录代码 - eclipse开发Groovy代码,与java集成,maven打包编译

5.1、设置类路径 src/main/groovy

maven工程的java代码一般是这么放的 src/main/java/com.xxx.xxx

而我们的groovy的代码可以这么放,并把这个目录设置为classpath, src/main/groovy/com.xxx.xxx

5.2、测试程序HelloWorld.groovy

写一个hello world程序,创建的工程不是Groovy Project,所以这个文件eclipse是不认识的,会报错,不过只需要引入Groovy的相关jar就可以识别了

class AppGroovy {

static main(args) {
def closure = { param -> println "hello ${param}" }
closure("world")
}
}

5.3、引入pom依赖jar包


pmo.xml里面加入Groovy的引用

 

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.7</version>
</dependency>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.9.2-01</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.4.3-01</version>
</dependency>

5.4、引入pom依赖 编译插件

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.7.0-01</version>
</dependency>
</dependencies>
</plugin>

这样,上面那个Groovy类就可以被编译和识别了

5.5、编译运行

mvn package就可以打包进去了!!

运行方法:右键Groovy文件,Run As -> Groovy Sctipt

如果要嵌入Java类中也很简单,直接在java里面引用就好了

public class App {
public static void main(String[] args) {
AppGroovy.main(args);
}
}
运行方法:右键Java文件,Run As -> Java Application