1

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?

Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115
  • Looks like the compilation is working, but then running the test happens without --enable-preview set. In case you can check out the compiled .class files from the test with `javap -v `, you can check that the minor class file version is non-zero, to verify that it was compiled with --enable-preview. – Jorn Vernee Mar 25 '19 at 13:00
  • @JornVernee Unfortunately groovy compilation is not working, it fails because it sees EndToEnd.class which is a java class compiled with --enable-preview as a result groovyc fails. – Krzysztof Krasoń Mar 25 '19 at 14:25
  • Oh I see, so groovyc is trying to load this class compiled with --enable-preview, and then it's failing because groovyc is not running in a JVM that has --enable-preview set. Maybe [setting the `JAVA_OPTS`](https://stackoverflow.com/q/5459317) environment variable to "--enable-preview" will work? (this works isolation using the groovy command line) – Jorn Vernee Mar 25 '19 at 14:58
  • 1
    Reported a bug https://github.com/groovy/GMavenPlus/issues/125 – Krzysztof Krasoń Mar 26 '19 at 09:18

1 Answers1

1

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+.

Keegan
  • 11,345
  • 1
  • 25
  • 38