CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-codehaus-groovy--groovy-ant

Apache Groovy Ant Task integration library providing seamless integration between Groovy scripting capabilities and Apache Ant build automation framework

Pending
Overview
Eval results
Files

groovy-compilation.mddocs/

Groovy Compilation

The Groovyc Ant task provides comprehensive compilation of Groovy and Java source files with support for joint compilation, extensive configuration options, and integration with existing Java build processes.

Capabilities

Groovyc Task

Compiles Groovy source files with full support for Java integration, classpath management, and build customization.

/**
 * Compiles Groovy source files using Ant, supporting both standalone Groovy
 * compilation and joint compilation with Java sources.
 */
public class Groovyc extends org.apache.tools.ant.taskdefs.MatchingTask {
    /** Add a path for source compilation */
    public Path createSrc();
    
    /** Set the source directories to find source files */
    public void setSrcdir(Path srcDir);
    
    /** Get the source directories */
    public Path getSrcdir();
    
    /** Set the extension for Groovy source files (*.groovy, .groovy, or groovy) */
    public void setScriptExtension(String scriptExtension);
    
    /** Get the Groovy source file extension */
    public String getScriptExtension();
    
    /** Set bytecode compatibility level (1.8, 11, 17, etc.) */
    public void setTargetBytecode(String version);
    
    /** Get bytecode compatibility level */
    public String getTargetBytecode();
    
    /** Set destination directory for compiled classes */
    public void setDestdir(File destDir);
    
    /** Get destination directory */
    public File getDestdir();
    
    /** Set the sourcepath for compilation */
    public void setSourcepath(Path sourcepath);
    
    /** Get the sourcepath */
    public Path getSourcepath();
    
    /** Create nested sourcepath element */
    public Path createSourcepath();
    
    /** Set sourcepath using reference */
    public void setSourcepathRef(Reference r);
    
    /** Set compilation classpath */
    public void setClasspath(Path classpath);
    
    /** Get compilation classpath */
    public Path getClasspath();
    
    /** Create nested classpath element */
    public Path createClasspath();
    
    /** Set classpath using reference */
    public void setClasspathRef(Reference r);
    
    /** List source files being compiled */
    public void setListfiles(boolean list);
    
    /** Check if listing files */
    public boolean getListfiles();
    
    /** Continue build even if compilation errors occur */
    public void setFailonerror(boolean fail);
    
    /** Inverse of failonerror - proceed on errors */
    public void setProceed(boolean proceed);
    
    /** Get failonerror setting */
    public boolean getFailonerror();
    
    /** Set initial memory size for forked JVM */
    public void setMemoryInitialSize(String memoryInitialSize);
    
    /** Get initial memory size */
    public String getMemoryInitialSize();
    
    /** Set maximum memory size for forked JVM */
    public void setMemoryMaximumSize(String memoryMaximumSize);
    
    /** Get maximum memory size */
    public String getMemoryMaximumSize();
    
    /** Set file encoding for source files */
    public void setEncoding(String encoding);
    
    /** Get file encoding */
    public String getEncoding();
    
    /** Enable verbose compilation output */
    public void setVerbose(boolean verbose);
    
    /** Check verbose setting */
    public boolean getVerbose();
    
    /** Include Ant's classpath in compilation */
    public void setIncludeantruntime(boolean include);
    
    /** Check if including Ant runtime classpath */
    public boolean getIncludeantruntime();
    
    /** Include Java runtime libraries in classpath */
    public void setIncludejavaruntime(boolean include);
    
    /** Check if including Java runtime */
    public boolean getIncludejavaruntime();
    
    /** Fork compilation into separate JVM */
    public void setFork(boolean f);
    
    /** Set JDK home for forked compilation */
    public void setJavaHome(File home);
    
    /** Set executable for forked compilation */
    public void setExecutable(String forkExecPath);
    
    /** Get executable path */
    public String getExecutable();
    
    /** Set property name to set on successful compilation */
    public void setUpdatedProperty(String updatedProperty);
    
    /** Set property name to set on compilation failure */
    public void setErrorProperty(String errorProperty);
    
    /** Include destination classes directory in classpath */
    public void setIncludeDestClasses(boolean includeDestClasses);
    
    /** Check if including destination classes */
    public boolean isIncludeDestClasses();
    
    /** Get compilation success status */
    public boolean getTaskSuccess();
    
    /** Add nested javac task for joint compilation */
    public void addConfiguredJavac(org.apache.tools.ant.taskdefs.Javac javac);
    
    /** Enable stack trace reporting on compilation errors */
    public void setStacktrace(boolean stacktrace);
    
    /** Enable invokedynamic support */
    public void setIndy(boolean useIndy);
    
    /** Check invokedynamic setting */
    public boolean getIndy();
    
    /** Set base class for scripts */
    public void setScriptBaseClass(String scriptBaseClass);
    
    /** Get base class for scripts */
    public String getScriptBaseClass();
    
    /** Set configuration script path */
    public void setConfigscript(String configscript);
    
    /** Get configuration script path */
    public String getConfigscript();
    
    /** Set directory for Java stub generation */
    public void setStubdir(File stubDir);
    
    /** Get stub generation directory */
    public File getStubdir();
    
    /** Keep generated stub files for debugging */
    public void setKeepStubs(boolean keepStubs);
    
    /** Check if keeping stubs */
    public boolean getKeepStubs();
    
    /** Force lookup of unnamed files on classpath */
    public void setForceLookupUnnamedFiles(boolean forceLookupUnnamedFiles);
    
    /** Check force lookup setting */
    public boolean getForceLookupUnnamedFiles();
    
    /** Generate parameter metadata for reflection */
    public void setParameters(boolean parameters);
    
    /** Check parameter metadata setting */
    public boolean getParameters();
    
    /** Enable preview Java features (JDK 12+) */
    public void setPreviewFeatures(boolean previewFeatures);
    
    /** Check preview features setting */
    public boolean getPreviewFeatures();
    
    /** Execute compilation */
    public void execute() throws BuildException;
    
    /** Get list of files to compile */
    public File[] getFileList();
}

Joint Compilation Support

Integration with Java compilation through nested javac task configuration.

/**
 * Nested Javac task for joint Java/Groovy compilation.
 * Supports all standard javac attributes and nested elements.
 */
public class Javac extends org.apache.tools.ant.taskdefs.Javac {
    /** Enable debug information in compiled classes */
    public void setDebug(boolean debug);
    
    /** Set debug level (lines, vars, source) */
    public void setDebugLevel(String level);
    
    /** Show deprecation warnings */
    public void setDeprecation(boolean deprecation);
    
    /** Disable all warnings */
    public void setNowarn(boolean nowarn);
    
    /** Enable verbose output */
    public void setVerbose(boolean verbose);
    
    /** Set source compatibility level */
    public void setSource(String source);
    
    /** Set target bytecode level */
    public void setTarget(String target);
    
    /** Set release version (JDK 9+) */
    public void setRelease(String release);
    
    /** Set file encoding */
    public void setEncoding(String encoding);
    
    /** Set bootstrap classpath */
    public void setBootclasspath(Path bootclasspath);
    
    /** Set module path */
    public void setModulepath(Path modulepath);
    
    /** Set module source path */
    public void setModulesourcepath(Path modulesourcepath);
    
    /** Set upgrade module path */  
    public void setUpgrademodulepath(Path upgrademodulepath);
}

Usage Examples

Basic Groovy Compilation

<groovyc srcdir="src/main/groovy" 
         destdir="build/classes"
         includeantruntime="false">
    <classpath>
        <fileset dir="lib" includes="*.jar"/>
    </classpath>
</groovyc>

Joint Java/Groovy Compilation

<groovyc srcdir="src" 
         destdir="build/classes"
         stubdir="build/stubs"
         keepStubs="false"
         fork="true"
         includeantruntime="false">
    <classpath>
        <path refid="compile.classpath"/>
    </classpath>
    
    <!-- Configure Java compilation -->
    <javac debug="true" 
           source="1.8" 
           target="1.8"
           encoding="UTF-8">
        <compilerarg value="-Xlint:unchecked"/>
    </javac>
</groovyc>

Advanced Configuration

<groovyc srcdir="src/main/groovy"
         destdir="build/classes"
         fork="true"
         memoryInitialSize="128m"
         memoryMaximumSize="512m"
         verbose="true"
         listfiles="true"
         stacktrace="true"
         encoding="UTF-8"
         targetBytecode="11"
         indy="true"
         parameters="true"
         scriptBaseClass="com.example.CustomScriptBase"
         configscript="config/compiler-config.groovy">
    
    <classpath>
        <path refid="compile.classpath"/>
        <pathelement location="build/resources"/>
    </classpath>
    
    <include name="**/*.groovy"/>
    <exclude name="**/*Test.groovy"/>
</groovyc>

Forked Compilation with Custom JDK

<groovyc srcdir="src"
         destdir="build/classes"
         fork="true"
         javaHome="/usr/lib/jvm/java-11-openjdk"
         executable="java"
         includeantruntime="false"
         includejavaruntime="false">
    
    <classpath>
        <fileset dir="lib" includes="*.jar"/>
    </classpath>
</groovyc>

Conditional Compilation with Properties

<groovyc srcdir="src/main/groovy"
         destdir="build/classes"
         failonerror="${compilation.strict}"
         verbose="${compilation.verbose}"
         updatedProperty="groovy.compilation.success"
         errorProperty="groovy.compilation.failed">
    
    <classpath refid="compile.classpath"/>
</groovyc>

<!-- Check compilation result -->
<fail if="groovy.compilation.failed" 
      message="Groovy compilation failed"/>

Multi-Source Directory Compilation

<groovyc destdir="build/classes" includeantruntime="false">
    <src path="src/main/groovy"/>
    <src path="src/generated/groovy"/>
    <src path="build/processed-sources"/>
    
    <classpath>
        <path refid="compile.classpath"/>
    </classpath>
    
    <include name="**/*.groovy"/>
    <exclude name="**/internal/**"/>
</groovyc>

Custom Script Extension and File Patterns

<groovyc srcdir="scripts"
         destdir="build/script-classes"
         scriptExtension="*.gvy">
    
    <include name="**/*.gvy"/>
    <include name="**/*.gsh"/>
    <exclude name="**/test/**"/>
    
    <classpath>
        <path refid="runtime.classpath"/>
    </classpath>
</groovyc>

Configuration Scripts

Compiler behavior can be customized using configuration scripts:

// config/compiler-config.groovy
import org.codehaus.groovy.control.customizers.*

// Add import customization
def importCustomizer = new ImportCustomizer()
importCustomizer.addStaticStars('java.lang.Math')
importCustomizer.addImports('java.util.concurrent.TimeUnit')
configuration.addCompilationCustomizers(importCustomizer)

// Add AST transformations
def astCustomizer = new ASTTransformationCustomizer(
    CompileStatic.class
)
configuration.addCompilationCustomizers(astCustomizer)

// Configure optimization
configuration.optimizationOptions.put('indy', true)
configuration.optimizationOptions.put('int', false)

Error Handling and Diagnostics

Compilation Error Information

public class BuildException extends RuntimeException {
    /** Create exception with message */
    public BuildException(String message);
    
    /** Create exception with message and cause */
    public BuildException(String message, Throwable cause);
    
    /** Get the location where error occurred */
    public Location getLocation();
    
    /** Set the location where error occurred */
    public void setLocation(Location location);
}

public class Location {
    /** Get filename where error occurred */
    public String getFileName();
    
    /** Get line number of error */
    public int getLineNumber();
    
    /** Get column number of error */
    public int getColumnNumber();
}

Debug and Verbose Output

When verbose mode is enabled, the compiler provides detailed information about:

  • Files being processed
  • Classpath resolution
  • Compilation phases
  • Stub generation (for joint compilation)
  • Memory usage and performance metrics

Memory Management

For large codebases, proper memory configuration is essential:

  • memoryInitialSize: Starting heap size (e.g., "256m")
  • memoryMaximumSize: Maximum heap size (e.g., "1g")
  • fork="true": Required for memory settings to take effect

Install with Tessl CLI

npx tessl i tessl/maven-org-codehaus-groovy--groovy-ant

docs

ant-builder.md

file-utilities.md

groovy-compilation.md

groovy-documentation.md

groovy-execution.md

index.md

tile.json