Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Dashboard
Groovy
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<p>There are several approaches to compiling Groovy code in your Maven projects. <a href="http://docs.codehaus.org/display/GMAVEN/Home">GMaven</a> is the most flexible and feature rich, but it has some difficulties with joint Java-Groovy projects and it is no longer under active development. The <a class="confluence-link" href="/display/GROOVY/Groovy-Eclipse+compiler+plugin+for+Maven" data-linked-resource-id="193888332" data-linked-resource-type="page" data-linked-resource-default-alias="Groovy-Eclipse compiler plugin for Maven" data-base-url="http://docs.codehaus.org">Groovy-Eclipse compiler plugin for Maven</a> sidesteps the joint compilation issues. Read <a class="confluence-link" href="/display/GROOVY/Groovy-Eclipse+compiler+plugin+for+Maven" data-linked-resource-id="193888332" data-linked-resource-type="page" data-linked-resource-default-alias="Groovy-Eclipse compiler plugin for Maven" data-base-url="http://docs.codehaus.org">this page</a> for a deeper discussion of the benefits and disadvantages of the two approaches.</p> <p>A third approach is to use Maven's Ant plugin to compile a groovy project. Note that the Ant plugin is bound to the compile and test-compile phases of the build in the example below. It will be invoked during these phases and the contained tasks will be carried out which runs the Groovy compiler over the source and test directories. The resulting Java classes will coexist with and be treated like any standard Java classes compiled from Java source and will appear no different to the JRE, or the JUnit runtime.</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycomp.MyGroovy</groupId> <artifactId>MyGroovy</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>Maven Example building a Groovy project</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>groovy</groupId> <artifactId>groovy-all-1.0-jsr</artifactId> <version>05</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>compile</id> <phase>compile</phase> <configuration> <tasks> <mkdir dir="${basedir}/src/main/groovy"/> <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc"> <classpath refid="maven.compile.classpath"/> </taskdef> <mkdir dir="${project.build.outputDirectory}"/> <groovyc destdir="${project.build.outputDirectory}" srcdir="${basedir}/src/main/groovy/" listfiles="true"> <classpath refid="maven.compile.classpath"/> </groovyc> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> <execution> <id>test-compile</id> <phase>test-compile</phase> <configuration> <tasks> <mkdir dir="${basedir}/src/test/groovy"/> <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc"> <classpath refid="maven.test.classpath"/> </taskdef> <mkdir dir="${project.build.testOutputDirectory}"/> <groovyc destdir="${project.build.testOutputDirectory}" srcdir="${basedir}/src/test/groovy/" listfiles="true"> <classpath refid="maven.test.classpath"/> </groovyc> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> </pre></td></tr></table> <p>This assumes you have a Maven project setup with "groovy" subfolders as peers to the java src and test subfolders. You can use the java/jar archetype to set this up then rename the java folders to groovy or keep the java folders and just create groovy peer folders. There exists, also a groovy plugin which has not been tested or used in production. After defining the build section as in the above example, you can invoke the typical Maven build phases normally. For example, "mvn test" will execute the test phase, compiling Groovy source and Groovy test source and finally executing the unit tests. If you run "mvn jar" it will execute the jar phase bundling up all of your compiled production classes into a jar after all of the unit tests pass. For more detail on Maven build phases consult the Maven2 documentation.</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced