Groovy-Eclipse compiler plugin for Maven
2012-04-21 03:27
645 查看
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 POM
Setting up the source folders
Do nothing
Do almost nothing
Use the
Use the
Sample project and source code
Why another Groovy compiler for Maven? What about GMaven?
Project Lombok
Groovy-Eclipse configurator for m2Eclipse
Where to find more information and ask questions
In 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
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:
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.
it is possible to put your Groovy files in
GRECLIPSE-1221.
(You only need this approach if your project has an empty
If your project has no Java files and you don't want to add an empty file in
The
Use the
(You only need this approach if your project has an empty
The
The benefit of using this approach is that you do not need to make any changes to the default lifecycle. The downside is, of course, that you need 31 lines of configuration to do this!
A
sample project using the compiler plugin as well as the source code for the plugin itself are available from the Codehaus.org subversion 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.
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
Whether or not the Groovy-Eclipse compiler plugin for Maven is appropriate for your project will depend on your requirements.
both the build and compile dependencies sections:
Also, the following configuration needs to be added to the maven-compiler-plugin configuration:
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/
How to use the compiler plugin---Setting up the POM
Setting up the source folders
Do nothing
Do almost nothing
Use the
groovy-eclipse-compilermojo for configuring source folders
Use the
build-helper-maven-plugin
Sample project and source code
Why another Groovy compiler for Maven? What about GMaven?
Project Lombok
Groovy-Eclipse configurator for m2Eclipse
Where to find more information and ask questions
The most recent version of the Groovy-Eclipse-Compiler plugin for maven is 2.6.0-01. If necessary, 2.6.1-01-SNAPSHOT versions will be available from *http://nexus.codehaus.org/snapshots/*. |
How to use the compiler plugin---Setting up the POM
In your plugin section, you must change the compiler used by themaven-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
groovy-eclipse-batchartifact):
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 folders
There are several ways to set up your maven project to recognize Groovy source filesDo nothing
The simplest way to set up your source folders is to do nothing at all: add all of your Groovy files tosrc/main/javaand
src/test/java. This requires absolutely no extra configuration and is easy to implement. However, this is not a standard maven approach to setting up your project. If you require a more standard maven approach, then
it is possible to put your Groovy files in
src/main/groovyand
src/test/groovyand you Java files in
src/main/javaand
src/test/java. There are several ways of doing this.
Do almost nothing
If there is at least one file (Java or not) insrc/main/java, then all files in
src/main/groovywill be found. If, however,
src/main/javais empty, then
src/main/groovywill be ignored. You can get around this by placing an empty file in
src/main/javajust so that
src/main/groovywill be recognized. The same is true for
src/test/javaand
src/test/groovy. This is actually a workaround for
GRECLIPSE-1221.
Use the groovy-eclipse-compiler
mojo for configuring source folders
(You only need this approach if your project has an empty src/main/javaor
src/test/java.)
If your project has no Java files and you don't want to add an empty file in
src/main/java, then you can configure source files by referencing the groovy-eclipse-compiler mojo. Just add this to the
pluginssection of your pom:
t;build> ... <plugin> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.6.0-01-SNAPSHOT</version> <extensions>true</extensions> </plugin> ... </build>
The
<extensions>true</extensions>section is important because this redefines the default lifecycle of your project so that an extra phase is added. This phase has an extra goal attached to it that adds the two Groovy source folders.
Use the
build-helper-maven-plugin
(You only need this approach if your project has an empty src/main/javaor
src/test/java.)
The
build-helper-maven-pluginallows you to do things like adding extra source folders to your project without needing to redefine the default lifecycle. You need to add this configuration to your build plugin section:
t;build> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.5</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/main/groovy</source> </sources> </configuration> </execution> <execution> <id>add-test-source</id> <phase>generate-test-sources</phase> <goals> <goal>add-test-source</goal> </goals> <configuration> <sources> <source>src/test/groovy</source> </sources> </configuration> </execution> </executions> </plugin> ... </build>
The benefit of using this approach is that you do not need to make any changes to the default lifecycle. The downside is, of course, that you need 31 lines of configuration to do this!
Sample project and source code
There is an archetype available for this project. You can use it through a command like this:n archetype:generate \ -DarchetypeGroupId=org.codehaus.groovy \ -DarchetypeArtifactId=groovy-eclipse-quickstart \ -DarchetypeVersion=2.5.2-01 \ -DgroupId=foo \ -DartifactId=bar \ -Dversion=1 \ -DinteractiveMode=false \ -DarchetypeRepository=https://nexus.codehaus.org/content/repositories/snapshots/
A
sample project using the compiler plugin as well as the source code for the plugin itself are available from the Codehaus.org subversion repository:
The SVN repository URL is:https://svn.codehaus.org/groovy/eclipse/trunk/extras There are several projects in the repository: groovy-eclipse-compiler: the compiler plugin itself (an m2eclipse project). groovy-eclipse-batch-builder: a set of ant scripts and configuration files used to build the groovy-eclipse-batchartifact. This artifact is an amalgamation of all jars required for compiling Groovy and Java code in Eclipse, including ecj (the Eclipse compiler for Java), the non-UI components of Groovy-Eclipse, the Groovy jars, and various required Eclipse bundles. groovy-eclipse-maven-tests: a sample project that uses the compiler plugin (an m2eclipse project). org.codehaus.groovy.m2eclipse: an Eclipse plugin that provides integration between Groovy-Eclipse and m2eclipse (the Maven tooling for Eclipse). Feature org.codehaus.groovy.m2eclipse: an Eclipse feature that is required for building and releasing the org.codehaus.groovy.m2eclipseplugin. |
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
defaultScriptExtensioncompiler 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 toboth 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 usem2eclipse. 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/
相关文章推荐
- run-jetty-run - Jetty Eclipse Plugin! Best plugin for running Jetty in Eclipse! Jetty,Eclipse,Maven,Web - Google Project Hosting
- 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing
- [Maven] - Eclipse "maven compiler plugin" 冲突解决
- 在用Eclipse IDE for Java EE Developers进行maven项目的开发时,报错Could not calculate build plan: Plugin org.apach
- Maven Incremental hot deploy - a plugin for the Eclipse IDE
- Maven Eclipse Plugin vs. Maven Integration for Eclipse
- Keil compiler plugin for eclipse
- Eclipse结合Maven出现[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin错误的解决方法
- eclipse maven 报错Could not get the value for parameter encoding for plugin execution default
- Maven错误:'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing
- Missing requirement: JDT Core patch for Groovy-Eclipse plugin 2.5.1.xx-20110627-1300-e36 (org.codehaus.groovy.jdt.patch.
- [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 122, column 12
- maven打包出错Using Groovy-Eclipse compiler……
- CoreException: Could not get the value for parameter compilerId for plugin execution default-compile: PluginResolutionException: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1
- Q for Eclipse is an Apache Maven plugin for the Eclipse IDE
- eclipse开发Groovy代码,与java集成,maven打包编译
- Error:No such property: GROUP for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovy
- maven install时报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
- 天生一对"Maven2+Jetty" -- Maven2创建并管理WebApp,并使用Maven Jetty Plugin在Eclipse中调试
- Maven error in eclipse (pom.xml) : Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4