โ๏ธ Gradle + TeamCity Setup with Amazon Corretto JDK and IntelliJ IDEA¶
This guide covers:
- How to configure a Gradle multi-module project with IntelliJ IDEA
- How to build it in TeamCity using a custom Amazon Corretto JDK
- How to ensure your build is portable across environments (e.g., JDK 21 locally, JDK 17 on target)
๐งฑ Project Structure (Multi-module)¶
This example assumes a root project tqpro with multiple subprojects:
tqpro/
โโโ build.gradle.kts โ Root build config
โโโ settings.gradle.kts โ Includes all subprojects
โโโ gradle.properties โ Shared properties (optional)
โโโ tqapi/ โ Subproject (Java)
โ โโโ build.gradle.kts
โโโ tqapp/
โ โโโ build.gradle.kts
โโโ tqweb/ โ Subproject (web/static assets)
โ โโโ build.gradle.kts
โ๏ธ IntelliJ IDEA Setup¶
- Open the
tqpro/directory as the root project - IntelliJ will detect all modules based on
settings.gradle.kts - Ensure each module's
build.gradle.ktsapplies the proper plugin (e.g.,java,application) - Run configurations can be set per module (e.g.,
tqapi) with proper classpaths - Gradle sync will manage all dependencies โ do not modify module dependencies via Project Structure UI
๐งฐ Example Root settings.gradle.kts¶
๐ ๏ธ Installing Amazon Corretto JDK (Non-System)¶
On each TeamCity agent, install Corretto manually into a custom location:
mkdir -p /opt/corretto-17
wget https://corretto.aws/downloads/latest/amazon-corretto-17-x64-linux-jdk.tar.gz -O /tmp/corretto.tar.gz
tar -xzf /tmp/corretto.tar.gz -C /opt/corretto-17 --strip-components=1
๐๏ธ TeamCity Build Step Configuration¶
- Open your build configuration
- In the Gradle build step:
- Runner type: Gradle
- Use Gradle wrapper: โ
- JDK:
Custom - Custom JDK path:
/opt/corretto-17
โ This ensures Gradle runs under JDK 17 even if the system JDK is 21
โ๏ธ Gradle Configuration for Toolchains (Optional)¶
You can force Java 17 compatibility using Gradle's toolchain support:
subprojects {
plugins.withId("java") {
extensions.configure<JavaPluginExtension>("java") {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}
}
Do not specify vendor.set(JvmVendorSpec.AMAZON) unless you're manually managing JDK installation โ Gradle does not support downloading Amazon Corretto automatically.
๐งช Debugging Java Setup¶
Add a task in your root build.gradle.kts:
tasks.register("debugJdk") {
doLast {
println("Java version: ${System.getProperty("java.version")}")
println("Java home: ${System.getProperty("java.home")}")
}
}
Then run:
โ Summary¶
| Item | Description |
|---|---|
| System JDK (TeamCity agent) | Java 21 (default, for agent) |
| Build JDK (Gradle step) | Amazon Corretto 17 (custom path) |
| Gradle JDK selection | Set JDK in Gradle step to Custom |
| IntelliJ support | Full sync from root project, no manual facet changes |
| Toolchains | Optional, use languageVersion.set(JavaLanguageVersion.of(17)) |
๐ฆ Optional Improvements¶
- Install multiple JDKs under
/opt/jdks/and parameterizejdkPath - Script the Corretto installation during agent provisioning
- Enable JAR packaging and distribution with
jarandcopyDependenciestasks