Commits

James Sumners committed 63b23c4

Adds support for using Groovy in the project

Comments (0)

Files changed (3)

src/main/resources/META-INF/maven/archetype-metadata.xml

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <fileSets>
     <fileSet filtered="true" packaged="true" encoding="UTF-8">
+      <directory>src/main/groovy</directory>
+      <includes>
+        <include>**/*.groovy</include>
+      </includes>
+    </fileSet>
+    <fileSet filtered="true" packaged="true" encoding="UTF-8">
       <directory>src/main/java</directory>
       <includes>
         <include>**/*.java</include>
       <directory>src/test/</directory>
     </fileSet>
     <fileSet encoding="UTF-8" filtered="false" packaged="false">
+      <directory>src/test/groovy/</directory>
+    </fileSet>
+    <fileSet encoding="UTF-8" filtered="false" packaged="false">
       <directory>src/test/java/</directory>
     </fileSet>
     <fileSet encoding="UTF-8" filtered="false" packaged="false">

src/main/resources/archetype-resources/pom.xml

     <maven.compiler.target>1.7</maven.compiler.target>
 
     <cglib.version>2.2.2</cglib.version>
+    <groovy.version>2.3.0</groovy.version>
     <guava.version>17.0</guava.version>
     <jackson.version>2.3.1</jackson.version>
     <javax-servlet.version>3.1.0</javax-servlet.version>
     </dependency>
 
     <dependency>
+      <groupId>org.codehaus.groovy</groupId>
+      <artifactId>groovy-all</artifactId>
+      <version>${groovy.version}</version>
+    </dependency>
+
+    <dependency>
       <groupId>com.google.guava</groupId>
       <artifactId>guava</artifactId>
       <version>${guava.version}</version>
           <failOnMissingWebXml>false</failOnMissingWebXml>
         </configuration>
       </plugin>
+
+      <plugin>
+        <!-- This will make IntelliJ mark Groovy source directories correctly -->
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <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>
     </plugins>
   </build>
 

src/main/resources/archetype-resources/src/main/groovy/webapp/controllers/FooController.groovy

+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+package ${package}.webapp.controllers
+
+import groovy.json.JsonOutput
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+import org.springframework.http.MediaType
+import org.springframework.web.bind.annotation.RequestMapping
+import org.springframework.web.bind.annotation.RestController
+
+@RestController
+public class FooController {
+  private static final Logger log = LoggerFactory.getLogger(FooController.class)
+
+  @RequestMapping(
+      value = "/foo",
+      produces = MediaType.APPLICATION_JSON_VALUE
+  )
+  def foo() {
+    log.info("Displaying foo")
+    return JsonOutput.toJson([foo: "foo"])
+  }
+}