Skip to content

Instantly share code, notes, and snippets.

@keeganwitt
Last active February 1, 2022 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keeganwitt/d56b4b81165a264061d5 to your computer and use it in GitHub Desktop.
Save keeganwitt/d56b4b81165a264061d5 to your computer and use it in GitHub Desktop.
Groovyc via Maven AntRun Example
<?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>org.codehaus.groovy</groupId>
<artifactId>groovyc-antrun-example</artifactId>
<name>Groovyc Maven AntRun Example</name>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<groovyGroupId>org.codehaus.groovy</groovyGroupId>
<groovyVersion>3.0.9</groovyVersion>
<!-- <groovyGroupId>org.apache.groovy</groovyGroupId> -->
<!-- <groovyVersion>4.0.0</groovyVersion> -->
</properties>
<dependencies>
<dependency>
<groupId>${groovyGroupId}</groupId>
<artifactId>groovy</artifactId>
<version>${groovyVersion}</version>
<classifier>indy</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.9.0</version>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
<classpath refid="maven.compile.classpath" />
</taskdef>
<mkdir dir="${project.build.outputDirectory}" />
<groovyc srcdir="${basedir}/src/main/groovy" destdir="${project.build.outputDirectory}"
targetBytecode="${maven.compiler.target}" indy="true" encoding="${project.build.sourceEncoding}">
<classpath refid="maven.compile.classpath" />
<src>
<pathelement path="${project.basedir}/src/main/java" />
</src>
<javac source="${maven.compiler.source}" target="${maven.compiler.target}" />
</groovyc>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<configuration>
<target>
<taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
<classpath refid="maven.test.classpath" />
</taskdef>
<mkdir dir="${project.build.testOutputDirectory}" />
<groovyc srcdir="${basedir}/src/test/groovy" destdir="${project.build.testOutputDirectory}"
targetBytecode="${maven.compiler.target}" indy="true" encoding="${project.build.sourceEncoding}">
<classpath refid="maven.test.classpath" />
<src>
<pathelement path="${project.basedir}/src/test/java" />
</src>
<javac source="${maven.compiler.source}" target="${maven.compiler.target}" />
</groovyc>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-ant</artifactId>
<version>${groovyVersion}</version>
<classifier>indy</classifier>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
@keeganwitt
Copy link
Author

I've updated the example to use a nested javac task instead of the normal compiler plugin (and changed the phase AntRun is bound to), this should allow circular dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment