Bohužel jsem zjistil, že rozchodit Groovy v Mavenu není jen jeden řádek. Existuji na to sice pluginy, ale u mě prostě nefungovaly :(. Takže tady je jenden navod jak rozchodit sice je dlouhý, ale funkční
(update: ještě lepší způsob je tady: Kompilace Groovy pomocí groovy-eclipse-compiler pluginu).
Java + Groovy s Mavenem
Je potřeba udělat 2 věci v pom.xml1) Nejprve přidat do projektu závislost na groovy:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.codehaus.groovy</groupId> | |
<artifactId>groovy-all</artifactId> | |
<version>1.8.0</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<build> | |
<plugins> | |
... | |
<plugin> | |
<artifactId>maven-antrun-plugin</artifactId> | |
<executions> | |
<execution> | |
<id>compile</id> | |
<!--<phase>compile</phase>--> | |
<phase>generate-sources</phase> | |
<configuration> | |
<tasks> | |
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc"> | |
<classpath refid="maven.compile.classpath"></classpath> | |
</taskdef> | |
<mkdir dir="${project.build.outputDirectory}"></mkdir> | |
<groovyc destdir="${project.build.outputDirectory}" | |
srcdir="${basedir}/src/main/java/" | |
listfiles="true"> | |
<classpath refid="maven.compile.classpath"></classpath> | |
</groovyc> | |
</tasks> | |
</configuration> | |
<goals> | |
<goal>run</goal> | |
</goals> | |
</execution> | |
<execution> | |
<id>test-compile</id> | |
<phase>test-compile</phase> | |
<configuration> | |
<tasks> | |
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc"> | |
<classpath refid="maven.compile.classpath"></classpath> | |
</taskdef> | |
<mkdir dir="${project.build.testOutputDirectory}"></mkdir> | |
<groovyc destdir="${project.build.testOutputDirectory}" | |
srcdir="${basedir}/src/test/java/" listfiles="true"> | |
<classpath refid="maven.test.classpath"></classpath> | |
</groovyc> | |
</tasks> | |
</configuration> | |
<goals> | |
<goal>run</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> |
Poznámka - Použití Groovy pouze pro testy.
Pokud chcete používat groovy pouze v testech:1) dependency na groovy nastavime pouze pro testy:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.codehaus.groovy</groupId> | |
<artifactId>groovy-all</artifactId> | |
<version>1.8.0</version> | |
</dependency> |
2) Definici pluginu nastavíme pouze pro testy a přidáme groovy do závislostí pluginu, protože jinak by mu při kompilaci chybělo:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<artifactId>maven-antrun-plugin</artifactId> | |
<executions> | |
<execution> | |
<id>test-compile</id> | |
<phase>test-compile</phase> | |
<configuration> | |
<tasks> | |
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc"> | |
<classpath refid="maven.compile.classpath"></classpath> | |
</taskdef> | |
<mkdir dir="${project.build.testOutputDirectory}"></mkdir> | |
<groovyc destdir="${project.build.testOutputDirectory}" | |
listfiles="true" srcdir="${basedir}/src/test/java/"> | |
<classpath refid="maven.test.classpath" ></classpath> | |
</groovyc> | |
</tasks> | |
</configuration> | |
<goals> | |
<goal>run</goal> | |
</goals> | |
</execution> | |
<dependencies> | |
<dependency> | |
<groupId>org.codehaus.groovy</groupId> | |
<artifactId>groovy-all</artifactId> | |
<version>1.8.0</version> | |
</dependency> | |
</dependencies> | |
</executions> | |
</plugin> |