How does an IntelliJ Gradle-based build work?

Answered

Hi,

 

What is the relationship (in IntelliJ 2020.1) between the following:

1. An explicit Gradle build either via ./gradlew build or going to the Gradle Tool Window, right-clicking build under Tasks and running that.

2. Building the imported project via Build > Build Project

#2 is much faster than #1 and seems to have all the correctness of #1 (for example the use of plugins, Kotlin compilation flags, exclusions etc. all set in build.gradle).

But that would imply that IntelliJ re-implemented Gradle entirely, and did so much faster, which makes no sense.

How does #2 work exactly?

Thank you,

Will

0
3 comments
Avatar
Yaroslav Bedrov

Hello,

There is no difference in build via ./gradlew build or going to the Gradle Tool Window - execution from tool window calls gradlew directly.

> Building the imported project via Build > Build Project

Do you have "Delegate build/run actions to Gradle" option enabled in "Settings/Preferences | Build, Execution, Deployment | Build Tools | Gradle"?

0

No, this is set to "IntelliJ IDEA" for both main and test. But it's also able to pick up more than just dependencies. It successfully works with this part of my build.gradle, as well. Does this mean you're actually implementing some Gradle features in-house?

buildscript {
ext {
experimentalsInTestEnabled = [
"-progressive",
"-Xuse-experimental=kotlinx.serialization.UnstableDefault",
"-Xuse-experimental=kotlinx.serialization.ImplicitReflectionSerializer"
]
}
...
}

...

compileKotlin {
kotlinOptions {
jvmTarget = '11'
freeCompilerArgs += experimentalsInTestEnabled
}
}
0
Avatar
Yaroslav Bedrov

We use Gradle build as an initial source for project/build configuration. But when delegation is disabled internal build is executed which may differ from Gradle one.

1

Please sign in to leave a comment.