Configuring IntelliJ to Use Groovy Compiler Instead of Java Compiler

Viewed 17729

In my maven project, I'm currently mixing my Java code with some Groovy code. I'm using Groovy mostly to construct the beans at this point. Some of my Java code uses the Groovy beans directly.

I configured the Maven Compiler Plugin like this:-

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <compilerId>groovy-eclipse-compiler</compilerId>
        <source>${jdk.version}</source>
        <target>${jdk.version}</target>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>2.8.0-01</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-batch</artifactId>
            <version>2.1.5-03</version>
        </dependency>
    </dependencies>
</plugin>

When I run my testcases using mvn test, it works just fine.

However, when I run the testcases directly from IntelliJ by right clicking the test file and run it, I'm getting "cannot find symbol" errors on the Groovy beans. When I read the error log, IntelliJ uses Java compiler to compile my project before running the test... thus, the tests fail.

I can't seem to figure out how to instruct IntelliJ to always use the Groovy compiler instead of Java compiler.

What should I change under SDK so that Groovy compiler will be used? I tried adding Groovy related JAR files, but I got other errors.

enter image description here

UPDATE 1: Per @Seagull suggestion

I added groovy JARs under "Global Libraries":-

enter image description here

When I executed the test file directly from IntelliJ, I'm getting some Groovy warnings and I still get the same error:-

enter image description here

Thanks.

2 Answers
Related