Quantcast
Channel: Gradle Forums - Latest posts
Viewing all articles
Browse latest Browse all 19859

Compile project with groovy 3

$
0
0
sourceCompatibility

only works to specify the Java version, not Groovy.

This flag only instructs the normal Java compiler to reject language syntax not present in the version you specify. This doesn’t stop you from compiling with newer versions of Java, or even use newer APIs (which will of cause make it fail at runtime if you execute it on earlier version). There are no similar options for the Groovy compiler to make it reject newer syntax in your Groovy source code. I would argue that it is not all that useful anyway.

Try ext groovy.version?

If you use the Spring Dependency Plugin and you use a BOM for enforcing common versions, this will set it to another version. Outside that, it doesn’t do anything.

To be clear, I’m not asking how to add the correct groovy dependency to the artifacts, but how to ensure they are compiled with the new groovy 3 compiler.

But this is exactly how you configure a normal Groovy project in Gradle to be compiled with whatever version you like. The version of Groovy you see in gradle --version is the one used internally by Gradle for the Groovy DSL, e.g. for interpreting a build.gradle file. You can’t change this without hacking the Gradle installation, and you also really shouldn’t as it can easily cause problems with the rest of the Gradle internals.

So to ensure that you are using (at least) Groovy 3, put in the following dependency:

implementation platform("org.codehaus.groovy:groovy-bom:3.0.4")

If you want to see for yourself if you are using the Groovy 3 compiler (with the new Parrot parser), try adding some source code using the new Groovy 3 syntax features like Java-style array initialization. Compilation will fail if using an older version.


Viewing all articles
Browse latest Browse all 19859

Trending Articles