Reputation: 15316
I have a very simple test project in Intellij IDEA in which I try to mix Java 9 and Groovy code. Additionally, this project has Maven Support, i.e. it is organized according to a Maven archetype and has a POM.
Now I have two classes in the default package calling each other (though not cyclically as compilation for that fails) and all is working well, i.e. Build > Build Project and Run > Run 'Main' are working.
However, this compilation seems to be independent of Maven configuration. There is no Groovy support in the POM for one. If I just compile from the command line with mvn compile
compilation fails as the linker cannot find any object that would result from Groovy compilation.
The POM just contains configuration for the maven-compiler-plugin
and I added that by hand with source
and target
nodes under configuration
set to 1.9
to have IDEA compile from/to Java 9 instead of from/to Java 5. So there is some interaction between what is in the POM and what IDEA does when I select Rebuild Project
.
What is correct way to configure IDEA and/or configure the POM so that compilation succeeds both in IDEA and on the command line. And if anyone knows, what are the interactions between what's in the POM and IDEA?
Do I have to configure the Groovy Eclipse Maven plugin in the POM? (I will try to do that)
Upvotes: 0
Views: 1365
Reputation: 14951
This is what I have working for Java 8 and Eclipse, for a project with both Java and Groovy code. I know I found the basis for this via Google at one point but did not save the URL, alas. Not sure if it will work with Java 9 and IntelliJ but worth a shot?
<properties>
<groovy.eclipse.compiler.plugin.version>2.9.1-01</groovy.eclipse.compiler.plugin.version>
</properties>
....
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- 2.8.0-01 and later require maven-compiler-plugin 3.1 or higher -->
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<!-- set verbose to be true if you want lots of uninteresting messages -->
<!-- <verbose>true</verbose> -->
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>${groovy.eclipse.compiler.plugin.version}</version>
</dependency>
<!-- for 2.8.0-01 and later you must have an explicit dependency on groovy-eclipse-batch -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.3.7-01</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>${groovy.eclipse.compiler.plugin.version}</version>
<extensions>true</extensions> <!-- required to get plugin to compile tests when no src/main/java dir exists -->
</plugin>
Upvotes: 1