Groovy-Eclipse compiler plugin for Maven
Groovy-Eclipse provides a compiler plugin for Maven. Using the compiler plugin,it is possible to compile your maven projects using the Groovy-Eclipse compiler.
How to use the compiler plugin---Setting up the POMIn your plugin section,you must change the compiler used by the maven-compiler-plugin. Like the javac ant task,the maven-compiler-plugin does not actually compile,but rather delegates the compilation to a different artifact (in our case,the t;build> ... <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</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.6.0-01</version> </dependency> </dependencies> </plugin> ... </plugins> </build> By default,this will use Groovy 1.8.4 to compile your code. If you would prefer to use 1.7.10,then add another dependency to the maven-compiler-plugin: t;dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-batch</artifactId> <version>1.7.10-06</version> </dependency> This will allow Groovy files to be compiled. The groovy-eclipse-compiler recognizes all settings supported by the maven-compiler-plugin. Note that the groovy-eclipse-compiler and groovy-eclipse-batch artifacts are available in Maven-central,so there is no need to explicitly declare any extra repositories. Setting up the source foldersThere are several ways to set up your maven project to recognize Groovy source files Do nothingThe simplest way to set up your source folders is to do nothing at all: add all of your Groovy files to Do almost nothingIf there is at least one file (Java or not) in Use the
|
The SVN repository URL is:
There are several projects in the repository:
|
The sample project and archetype is not maintained as well as we would like. Some community help with this would be greatly appreciated. Please see GRECLIPSE-1285.
Why another Groovy compiler for Maven? What about GMaven?
There are several benefits that the compiler plugin provides over GMaven,but at the same time it has a few limitations. First,the benefits:
- The compiler plugin does not require the creation of Java stubs so that your Groovy files can compile against Java files. This will prevent some arcane compile errors from appearing.
- The Groovy-Eclipse compiler is the same inside Eclipse and inside Maven,and so configuration across the two platforms can be simplified.
- The compiler plugin is a standard compiler plugin for Maven. It therefore follows all allows all the same standard configuration that the Javac compiler plugin uses. This makes it simpler to introduce Groovy into an existing Maven project. All you need to do is change the compiler plugin that the pom references.
There are some limitations:
- GroovyDoc tool is not supported because the compiler plugin does not produce stubs.
- Groovy Mojos are not supported.
- Groovy scripts cannot be executed in your poms.
- Groovy compiler options are not passed through to the compiler.
- The
defaultScriptExtension
compiler option is not supported.
Whether or not the Groovy-Eclipse compiler plugin for Maven is appropriate for your project will depend on your requirements.
Project Lombok
Project Lombok is compatible with the groovy-eclipse-compiler.? There is some extra configuration that you need to do.? The lombok jar needs to be added to both the build and compile dependencies sections:
t;dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>0.10.4</version> </dependency>
Also,the following configuration needs to be added to the maven-compiler-plugin configuration:
t;configuration> <compilerId>groovy-eclipse-compiler</compilerId> <verbose>true</verbose> <compilerArguments> <javaAgentClass>lombok.core.Agent</javaAgentClass> </compilerArguments> <fork>true</fork> </configuration>
Groovy-Eclipse configurator for m2Eclipse
If you are going to be working with your maven project inside of Eclipse,it is strongly recommended that you use m2eclipse. And to use your Groovy projects with m2eclipse,you will need to install the Groovy-Eclipse configurator for m2eclipse. This feature is available any of the Groovy-Eclipse update sites (e.g.,nightly,milestone,or release). Just go to your Eclipse update manager and add the Groovy-Eclipse update sites (if you haven't done so already). Select the Groovy-Eclipse M2E integration.
Release update site for Eclipse 3.7:
http://dist.springsource.org/release/GRECLIPSE/e3.7/
and 3.6:
http://dist.springsource.org/release/GRECLIPSE/e3.6/
Nightly update site for Eclipse 3.7:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.7/
and 3.6:
http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.6/
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!