You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Mr Andersson <mr...@gmail.com> on 2016/06/18 11:40:18 UTC

Integrating Groovy with a Java EE application and Maven

Hi,

I can not find any info on this online that will actually work.

I've tried:

<dependency>
     <groupId>org.codehaus.groovy</groupId>
     <artifactId>groovy</artifactId>
     <version>2.4.7</version>
</dependency> as well as <plugin>
     <inherited>true</inherited>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>3.5.1</version>
     <configuration>
         <source>${java.version}</source>
         <target>${java.version}</target>

	<!--!!!!!!!!!!!!!!!! ALSO TRIED WITHOUT THESE TWO LINES !!!!!!!!!!!!!!!! -->
         <compilerId>groovy-eclipse-compiler</compilerId>
         <verbose>true</verbose>

         <!-- See: 
http://stackoverflow.com/questions/17944108/maven-compiler-plugin-always-detecting-a-set-of-sources-as-stale 
--> <useIncrementalCompilation>false</useIncrementalCompilation>
     </configuration>

     <dependencies>
         <dependency>
             <groupId>org.codehaus.groovy</groupId>
             <artifactId>groovy-eclipse-compiler</artifactId>
             <version>2.9.2-01</version>
         </dependency>
     </dependencies>
</plugin> but this results in an error when a Java class is referencing 
a Groovy class in the project. I am not using eclipse. What are the 
neccesary steps to get Groovy to work *seamlessly in a Groovy project in 
2016* ? What are the limitations? Thanks!


Re: Integrating Groovy with a Java EE application and Maven

Posted by Mr Andersson <mr...@gmail.com>.
I have gotten a bit further in my research and came up with this sample 
project which uses ant to compile the groovy classes but I can't get 
them to compile together.

To be able to have cyclic dependencies between Java and Groovy files.

Here is a standalone isolated maven project that contains everything:

http://www.speedyshare.com/TbQyG/Isolated.zip

Pom file:

<?xml version="1.0" encoding="UTF-8"?> <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>Isolated</groupId>
     <name>Isolated</name>
     <artifactId>Isolated</artifactId>
     <version>1.0</version>
     <url>http://maven.apache.org</url>

     <packaging>jar</packaging>
     
     <properties>
         <java.version>1.8</java.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <skipTests>true</skipTests>
         <maven.test.skip>true</maven.test.skip>
     </properties>
     
     <dependencies>
         <dependency>
             <groupId>org.codehaus.groovy</groupId>
             <artifactId>groovy-all</artifactId>
             <version>2.4.6</version>  
         </dependency>
     </dependencies>
     
     <build>
     
         <plugins>
             <plugin>
                 <inherited>true</inherited>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.5.1</version>
                 <configuration>
                     <source>${java.version}</source>
                     <target>${java.version}</target>
                 </configuration>
             </plugin>
             
             <!-- http://groovy-lang.org/groovyc.html#_ant_task --> <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.directory}"/>
                                 <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>
                     
                 </executions>
             </plugin>
         </plugins>
     </build>
</project>



Re: Integrating Groovy with a Java EE application and Maven

Posted by Jochen Theodorou <bl...@gmx.org>.
On 18.06.2016 13:40, Mr Andersson wrote:
[...]
> I've tried:
>
> <dependency>
>      <groupId>org.codehaus.groovy</groupId>
>      <artifactId>groovy</artifactId>
>      <version>2.4.7</version>
> </dependency> as well as <plugin>
>      <inherited>true</inherited>
>      <groupId>org.apache.maven.plugins</groupId>
>      <artifactId>maven-compiler-plugin</artifactId>
>      <version>3.5.1</version>
>      <configuration>
>          <source>${java.version}</source>
>          <target>${java.version}</target>
>
> 	<!--!!!!!!!!!!!!!!!! ALSO TRIED WITHOUT THESE TWO LINES !!!!!!!!!!!!!!!! -->
>          <compilerId>groovy-eclipse-compiler</compilerId>
>          <verbose>true</verbose>
>
>          <!-- See:
> http://stackoverflow.com/questions/17944108/maven-compiler-plugin-always-detecting-a-set-of-sources-as-stale
> --> <useIncrementalCompilation>false</useIncrementalCompilation>
>      </configuration>
>
>      <dependencies>
>          <dependency>
>              <groupId>org.codehaus.groovy</groupId>
>              <artifactId>groovy-eclipse-compiler</artifactId>
>              <version>2.9.2-01</version>
>          </dependency>
>      </dependencies>

according to 
https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin you 
need to define a dependency for groovy-eclipse-batch as well

> </plugin> but this results in an error when a Java class is referencing
> a Groovy class in the project.

where did you store your java and groovy source files?

> I am not using eclipse. What are the
> neccesary steps to get Groovy to work *seamlessly in a Groovy project in
> 2016* ? What are the limitations? Thanks!

you can always try the gmavenplus plugin... or migrate to gradle, it 
works much better there for me ;)

bye blackdrag