Search code examples
javagroovyjava-12gmavenplus

Groovyc and Java 12 preview feature


I'm trying to compile a project that has some tests written in groovy. The project has --enable-preview for Java 12.

I'm using gmavenplus-plugin to do that:

        <plugin>                                                            
            <groupId>org.codehaus.gmavenplus</groupId>                      
            <artifactId>gmavenplus-plugin</artifactId>                      
            <version>1.6.3</version>                                        
            <configuration>                                                 
                <targetBytecode>${java.version}</targetBytecode>            
                <testSources>                                               
                    <testSource>                                            
                        <directory>${testSourceDirectory}</directory>       
                        <includes>                                          
                            <include>**/*.groovy</include>                  
                        </includes>                                         
                    </testSource>                                           
                </testSources>                                              
            </configuration>                                                
            <executions>                                                    
                <execution>                                                 
                    <goals>                                                 
                        <goal>compileTests</goal>                                                                                                                                                                
                    </goals>                                                
                </execution>                                                
            </executions>                                                   
        </plugin>   

I have --enable-preview for maven compiler and surefire/failsafe (using argLine). Everything works if I disable the groovy plugin (and tests).

But when I enable it, it fails with:

Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.6.3:compileTests (default) on project apikey-manager-api: Error occurred while calling a method on a Groovy class from classpath.: InvocationTargetException: Preview features are not enabled for com/acme/config/EndToEndTest (class file version 56.65535). Try running with '--enable-preview' -> [Help 1]

I don't see any options that I could pass to this plugin to enable preview features. Does it use javac? Or should such option be in groovyc?


Solution

  • With the changes in Groovy (GROOVY-9073) and GMavenPlus (#125), this is now available as of GMavenPlus 1.7.1 with Groovy 2.5.7+ / 3.0.0-beta-1+.