Groovy
  1. Groovy
  2. GROOVY-5044

Ant Groovyc compilation error in Gradle

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.1
    • Fix Version/s: 2.0-beta-3, 1.8.7
    • Component/s: Ant integration, Compiler
    • Labels:
      None
    • Environment:
      MacOS 10.6.8

      Description

      I ran the Groovyc Ant task to compile my classes within Gradle. My code uses the @Singleton annotation. The version I set in the classpath is 1.8.1. The following snippet shows the code I use:

      def groovycClasspath = getGroovyClasspath().asPath + System.getProperty('path.separator') + getTestRuntimeClasspath().asPath
      ant.taskdef(name: 'groovyc', classname: 'org.codehaus.groovy.ant.Groovyc', classpath: getGroovyClasspath().asPath)
      
      ant.groovyc(destdir: getClassesDir().canonicalPath, includeAntRuntime: false, classpath: groovycClasspath) {
          getSrcDirs().each { srcDir ->
              src(path: srcDir)
          }
      }
      

      When I run this without the attribute fork: true I get this compilation error:

      Not an ASTTransformation: org.codehaus.groovy.transform.SingletonASTTransformation declared by groovy.lang.Singleton
      

      Running Groovyc as forked process works fine. The compilation finished without an issue. Somebody on the mailing list reported the same error except that he uses Groovyc in Ant.

        Issue Links

          Activity

          Benjamin Muschko created issue -
          Hide
          Paul King added a comment -

          The other workaround that seems to work for me is to set includeAntRuntime="true".

          Show
          Paul King added a comment - The other workaround that seems to work for me is to set includeAntRuntime="true" .
          Cédric Champeau made changes -
          Field Original Value New Value
          Assignee Cedric Champeau [ melix ]
          Hide
          Cédric Champeau added a comment -

          Yes, the problem is that the "transform class loader" used by the compilation unit (that is to say the compiler) must, at least, be the same or a child classloader of the classloader which loads groovy classes.

          When "includeAntRuntime" is set to false, then the transform classloader used to load AST transforms is an AntClassLoader which doesn't have loaded any groovy internal class. What happens, then, is that when you reach org.codehaus.groovy.transform.ASTTransformationCollectorCodeVisitor#verifyClassAndAddTransform, there are two distinct ASTTransformation classes loaded: the one used by the compiler, and the one loaded from AntClassLoader. As a workaround, I tried to force the compiler to use the same classloader as the transform to load and compare the ASTTransformation class, but it's insufficient. It requires a lot of trickery to replace casts, direct method calls with reflective method calls in the compiler just to load the AST transformation.

          I am not sure what we should do...

          Show
          Cédric Champeau added a comment - Yes, the problem is that the "transform class loader" used by the compilation unit (that is to say the compiler) must, at least, be the same or a child classloader of the classloader which loads groovy classes. When "includeAntRuntime" is set to false, then the transform classloader used to load AST transforms is an AntClassLoader which doesn't have loaded any groovy internal class. What happens, then, is that when you reach org.codehaus.groovy.transform.ASTTransformationCollectorCodeVisitor#verifyClassAndAddTransform , there are two distinct ASTTransformation classes loaded: the one used by the compiler, and the one loaded from AntClassLoader. As a workaround, I tried to force the compiler to use the same classloader as the transform to load and compare the ASTTransformation class, but it's insufficient. It requires a lot of trickery to replace casts, direct method calls with reflective method calls in the compiler just to load the AST transformation. I am not sure what we should do...
          Cédric Champeau made changes -
          Link This issue relates to GROOVY-3294 [ GROOVY-3294 ]
          Hide
          Cédric Champeau added a comment -

          The problem is related to having a transform loader.

          Show
          Cédric Champeau added a comment - The problem is related to having a transform loader.
          Hide
          Cédric Champeau added a comment -

          Future versions of Groovy will prevent the combination fork=false && includeAntRuntime==false, which can lead to various surprising issues.

          Show
          Cédric Champeau added a comment - Future versions of Groovy will prevent the combination fork=false && includeAntRuntime==false, which can lead to various surprising issues.
          Cédric Champeau made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 1.8.7 [ 18317 ]
          Fix Version/s 2.0-beta-3 [ 18244 ]
          Resolution Fixed [ 1 ]
          Paul King made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Mark Thomas made changes -
          Workflow jira [ 12733969 ] Default workflow, editable Closed status [ 12745756 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12974095 ] Default workflow, editable Closed status [ 12981263 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          141d 6h 43m 1 Cédric Champeau 14/Feb/12 04:24
          Resolved Resolved Closed Closed
          88d 23h 5m 1 Paul King 13/May/12 04:30

            People

            • Assignee:
              Cédric Champeau
              Reporter:
              Benjamin Muschko
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development