Execute a Maven plugin with --enable-preview in POM

廉价感情. 提交于 2020-07-08 10:58:32

问题


I have a custom Maven plugin which makes use of JDK 12 preview features. I compile the plugin setting --enable-preview as compiler arg, i.e.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgs>
            <compilerArg>--enable-preview</compilerArg>
        </compilerArgs>
    </configuration>
</plugin>

When I want to execute the plugin, I add the plugin like this in the POM:

<plugin>
    <groupId>my.group</groupId>
    <artifactId>my-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>my-goal</goal>
            </goals>
        </execution>
    </executions>
</plugin>

But this fails with:

Preview features are not enabled for MyPluginMojo. Try running with '--enable-preview'

How can I enable preview features in a plugin execution?


回答1:


For me, I had to add a config file to my build directory at:

.mvn/jvm.config

containing:

--enable-preview

This will make sure that Maven passes the correct parameters to JVM



来源:https://stackoverflow.com/questions/58023240/execute-a-maven-plugin-with-enable-preview-in-pom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!