Can not build a project with mixed java and groovy code

Hello

I have few maven-based spring projects that have java and groovy code mixed (groovy and java classes are in the same directories). It compiles successfuly in eclipse using groovy plugin and also compiles using maven with groovy-eclipse-compiler.
I'm trying to import these project in IntelliJ IDEA but groovy code isn't built if I use ajc compiler (default for these project) and I get "illegal start of type" error for groovy java stub if use javac compiler.

Has anybody met such problem?

Thanks in advance

21 comments

Please provide details about your IDEA version (exact build), compilation settings, the exact compilation error you get.
Are javac and ajc compilers freely interchangeable for this project?

0

IDEA version is 12.1.4
build IU-129.713


I'd use javac, ajc was set automatically by IDEA when I imported the project (there is aspectj dependency from spring). Maven file contains the following plugin descriptions, can be useful.

<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <compilerId>groovy-eclipse-compiler</compilerId>
                        <source>1.6</source>
                        <target>1.6</target>
                        <encoding>ISO-8859-1</encoding>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.codehaus.groovy</groupId>
                            <artifactId>groovy-eclipse-compiler</artifactId>
                            <version>2.6.0-01</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>default-compile</id>
                            <configuration>
                                <outputDirectory>${project.build.directory}/unwoven-classes</outputDirectory>
                            </configuration>
                        </execution>
                        <execution>
                            <id>default-testCompile</id>
                            <configuration>
                                <outputDirectory>${project.build.directory}/unwoven-test-classes</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>aspectj-maven-plugin</artifactId>
                    <version>1.4</version>
                    <dependencies>
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjrt</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>org.aspectj</groupId>
                            <artifactId>aspectjtools</artifactId>
                            <version>${aspectj.version}</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>weave-classes</id>
                            <phase>process-classes</phase>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                            <configuration>
                                <!-- prevent it from finding and recompiling the already compiled source files -->
                                <sources/>
                                <!-- weave the output from the groovy eclipse compiler instead -->
                                <weaveDirectories>
                                    <weaveDirectory>${project.build.directory}/unwoven-classes</weaveDirectory>
                                </weaveDirectories>
                            </configuration>
                        </execution>
                        <execution>
                            <id>weave-test-classes</id>
                            <phase>process-test-classes</phase>
                            <goals>
                                <goal>test-compile</goal>
                            </goals>
                            <configuration>
                                <!-- prevent it from finding and recompiling the already compiled source files -->
                                <sources/>
                                <!-- weave the output from the groovy eclipse compiler instead -->
                                <weaveDirectories>
                                    <weaveDirectory>${project.build.directory}/unwoven-test-classes</weaveDirectory>
                                </weaveDirectories>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <aspectLibraries>
                            <aspectLibrary>
                                <groupId>org.springframework</groupId>
                                <artifactId>spring-aspects</artifactId>
                            </aspectLibrary>
                        </aspectLibraries>
                        <source>1.6</source>
                        <target>1.6</target>
                        <encoding>ISO-8859-1</encoding>
                        <Xlint>ignore</Xlint>
                        <!-- force it to weave the already compiled files even though there's no source files -->
                        <forceAjcCompile>true</forceAjcCompile>
                    </configuration>
                </plugin>



Examples of compilation errors with javac compiler are here https://www.monosnap.com/image/rp0dx2Q6WCBeHCuNeOeVOZ9tg
ajc just ignores groovy files.  

I tried to use Groovy 1.8.5 and Groovy 2.1.6 with the same result
0

Could you please attach the whole generated stub file? It's hard to tell anything from this partial screenshot.

0

Thanks. What's the first error reported by the compiler? Could it be that your ajc doesn't support varargs?

0

This is javac. AJC just ignores groovy files at all. The very first error is java: /Users/ik/Library/Caches/IntelliJIdea12/compile-server/rta_861f0ae/groovyStubs/rta-model/java-production/com/iodinesoftware/rta/model/loaders/BaseDataLoader.java:51: illegal start of type

0

Aha, now I see the problem. The stubs groovyc generates are malformed, they have invalid "java.util.Map<java.lang.Class<?>, [Ljava.lang.String;[]>" type in the getData(String...) method. Is it Map<Class,String[]> in the Groovy original?

Please try to exclude this file from Groovy stub generation (e.g. from right-click menu on its editor tab), if this Groovy class is not used from Java.

0

There is protected abstract Map<Class<?>, String[][]> getData(String[] args) method defined

I excluded this class from stub generation and got a new surprise - looks like groovy scripts get compiled and linked before java compilation so they don't see our java code:

Groovyc: java.lang.NoClassDefFoundError: com/iodinesoftware/rta/model/framework/Entity
 at java.lang.Class.getDeclaredMethods0(Native Method)
 at java.lang.Class.privateGetDeclaredMethods(Class.java:2475)
 at java.lang.Class.getDeclaredMethods(Class.java:1818)
 at org.codehaus.groovy.vmplugin.v5.Java5.configureClassNode(Java5.java:354)
 at org.codehaus.groovy.ast.ClassNode.lazyClassInit(ClassNode.java:258)
 at org.codehaus.groovy.ast.ClassNode.getUnresolvedSuperClass(ClassNode.java:973)
 at org.codehaus.groovy.ast.ClassNode.getUnresolvedSuperClass(ClassNode.java:968)
 at org.codehaus.groovy.control.ResolveVisitor.checkCyclicInheritence(ResolveVisitor.java:1204)
 at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1181)
 at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141)
 at org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit$1.call(JavaAwareCompilationUnit.java:67)
 at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1036)
 at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:572)
 at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:550)
 at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:527)
 at org.jetbrains.groovy.compiler.rt.GroovyCompilerWrapper.compile(GroovyCompilerWrapper.java:54)
 at org.jetbrains.groovy.compiler.rt.DependentGroovycRunner.runGroovyc(DependentGroovycRunner.java:80)
 at org.jetbrains.groovy.compiler.rt.GroovycRunner.main(GroovycRunner.java:85)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121)
Caused by: java.lang.ClassNotFoundException: com.iodinesoftware.rta.model.framework.Entity
 at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
 ... 23 more

0

Where's com/iodinesoftware/rta/model/framework/Entity class defined? In Java/Groovy or AspectJ? Is in the same module? Is it extended by a Groovy class? Does rebuilding the project help?

0

It's just another java class defined in the same module. I have mixed java and groovy code - one package may contain java and groovy classes both are in the same directory. This works pretty straightforwad in eclipse. It isn't extended by groovy class but used in some groovy classes.

0

Does rebuilding the project help?

How is Entity class used in the Groovy code? Is it field type/method parameter/anything else?

0

rebuild helps. But currently I see that groovy class I excluded from stub generation is used in
java code. So I can't build the project without it

0

Then please try enabling stub generation back for this file, and disabling "Settings | Compilre | Use external build". And rebuild. Does this help?

0

Now I receive "cannot find symbol class ..." for all my groovy classes

0

Is it the only kind of error you get? Any other messages, maybe warning/infos?

0

This is the top of messages window:
https://www.monosnap.com/image/XE8WDvHgc7PUFz9y5JFRO46vg

everything else is the same as errors here. Package com.iodinesoftware.rta.model.fetaures that "does not exist" according to the log, contains only groovy classes

0

Please add the following to bin/log.xml:

<category name="#org.jetbrains.jps.incremental.groovy.GroovycOSProcessHandler">
  <level value="DEBUG"/>
  <appender-ref ref="FILE"/>
</category>
<category name="#org.jetbrains.plugins.groovy">
  <level value="DEBUG"/>
  <appender-ref ref="FILE"/>
</category>
<category name="#com.intellij.compiler">
  <level value="DEBUG"/>
  <appender-ref ref="FILE"/>
</category>


After that please compile the project (or just the modules necessary to reproduce the bug; the less the better) and then attach the log file (Help | Show log).

0

These logs are taken with "Use external build" option turned off



Attachment(s):
logs.zip
0

Thanks. Please try disabling annotation processing.

0

wow, it works!!! Thanks for your help!

0

That's great. I've reported the bug to Groovy (http://jira.codehaus.org/browse/GROOVY-6302) and strongly encourage you to switch back to external build as soon as you have a release of Groovy containing a fix. I'd also recommend you to remove the logging since it can slow down things a bit.

0

Please sign in to leave a comment.