Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the language level in Gradle ? (so it is IDE-agnostic)

I would like to set the java language level in gradle, in an IDE-agnostic fashion.

sourceCompatibility = 1.x at the root level seems deprecated in Gradle 2.21.

(edit: or is it? IntelliJ gives me a groovy inspection error)

So I found this, which works.

idea {
    project {
        languageLevel = '1.7'
    }
}

But doesn't the configuration here tie gradle to IntelliJ IDEA, because of the idea { } structure...

Is there a way to do this in an IDE-agnostic fashion?

I would like my gradle build script to run in any IDE (be it IntelliJ IDEA or Eclipse) or on Jenkins (or whatever).

like image 263
vikingsteve Avatar asked Feb 11 '15 09:02

vikingsteve


People also ask

Does Gradle have IDE integration?

Gradle can be integrated with many different third-party tools such as IDEs and continuous integration platforms.

Is Gradle an IDE?

Gradle allows for generating IDE project files with the help of plugins. The standard Gradle distribution provides two out-of-the-box plugins: Eclipse and IDEA. Each plugin understands how to model IDE-specific project files. The plugins also expose a powerful DSL for customizing the generated project settings.

Which programming language should you know to configure a project in Gradle?

Gradle's build script are written in Groovy programming language. The whole design of Gradle is oriented towards being used as a language and not as a rigid framework. Groovy allows you to write your own script with some abstractions.

In what language build Gradle is written?

The Gradle build language Gradle provides a domain specific language, or DSL, for describing builds. This build language is available in Groovy and Kotlin. A Groovy build script can contain any Groovy language element. A Kotlin build script can contain any Kotlin language element.


1 Answers

The way to do this for CLI builds is shown. However I'm not sure if every IDE will pick this up.

allprojects {
    tasks.withType(JavaCompile) {
        sourceCompatibility = '1.7'
        targetCompatibility = '1.7'
    } 
}
like image 163
cmcginty Avatar answered Sep 27 '22 22:09

cmcginty