Skip to content

Commit

Permalink
Use the built-in Gradle version checker
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhbd committed Mar 2, 2024
1 parent 78836dc commit cac422e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
17 changes: 11 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,22 @@ dependencies {
testFixturesImplementation(libs.annotations)
}

configurations.configureEach {
if (isCanBeConsumed) {
attributes {
attribute(
GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE,
objects.named<GradlePluginApiVersion>(GradleVersion.version("8.1").version)
)
}
}
}

kotlin {
jvmToolchain(11)
}

tasks {
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
}
}

wrapper {
gradleVersion = properties("gradleVersion").get()
distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ object Constants {
const val VERSION_LATEST = "latest"

object Constraints {
val MINIMAL_GRADLE_VERSION: GradleVersion = GradleVersion.version("8.1")
val MINIMAL_INTELLIJ_PLATFORM_BUILD_NUMBER = "223".toVersion()
val MINIMAL_INTELLIJ_PLATFORM_VERSION = "2022.3".toVersion()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@
package org.jetbrains.intellij.platform.gradle.plugins

import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.PluginInstantiationException
import org.gradle.kotlin.dsl.create
import org.gradle.util.GradleVersion
import org.jetbrains.intellij.platform.gradle.Constants.Constraints
import org.jetbrains.intellij.platform.gradle.Constants.PLUGIN_NAME

internal inline fun <reified T : Any> Any.configureExtension(name: String, vararg constructionArguments: Any, noinline configuration: T.() -> Unit = {}) {
with((this as ExtensionAware).extensions) {
val extension = findByName(name) as? T ?: create<T>(name, *constructionArguments)
extension.configuration()
}
}

internal fun checkGradleVersion() {
if (GradleVersion.current() < Constraints.MINIMAL_GRADLE_VERSION) {
throw PluginInstantiationException("$PLUGIN_NAME requires Gradle ${Constraints.MINIMAL_GRADLE_VERSION} and higher")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ abstract class IntelliJPlatformBasePlugin : Plugin<Project> {
override fun apply(project: Project) {
log.info("Configuring plugin: $PLUGIN_BASE_ID")

checkGradleVersion()

with(project) {
with(plugins) {
apply(JavaPlugin::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ abstract class IntelliJPlatformSettingsPlugin @Inject constructor(
override fun apply(settings: Settings) {
log.info("Configuring plugin: $PLUGIN_SETTINGS_ID")

checkGradleVersion()

@Suppress("UnstableApiUsage")
with(settings.dependencyResolutionManagement.repositories) {
configureExtension<IntelliJPlatformRepositoriesExtension>(
Expand Down

0 comments on commit cac422e

Please sign in to comment.