Skip to content

Commit

Permalink
Added min Gradle version check (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo committed Mar 27, 2024
1 parent fef8ac4 commit 7d3da7a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion demo/build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ import org.gradle.kotlin.dsl.always
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.mapProperty
import org.gradle.kotlin.dsl.registerIfAbsent
import org.gradle.util.GradleVersion
import javax.inject.Inject

class ReportPublicationsPlugin @Inject constructor(
private val buildEventsListenerRegistry: BuildEventsListenerRegistry,
private val flowScope: FlowScope,
) : Plugin<Project> {

companion object {
const val MIN_GRADLE_VERSION = "8.1"
}

override fun apply(project: Project): Unit = with(project) {
check(GradleVersion.current() >= GradleVersion.version(MIN_GRADLE_VERSION)) {
"Gradle version must be at least $MIN_GRADLE_VERSION"
}

if (project != rootProject) {
rootProject.apply<ReportPublicationsPlugin>()
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
*/
package io.github.gmazzo.gradle.publications.report

import io.github.gmazzo.publications.report.ReportPublicationsPlugin
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.util.GradleVersion
import java.io.File
import kotlin.test.Test
import kotlin.test.assertEquals

class ReportPublicationsPluginTest {
sealed class ReportPublicationsPluginTest(private val gradleVersion: String) {

private val rootDir = File(System.getProperty("projectRootDir"))
class Min : ReportPublicationsPluginTest(ReportPublicationsPlugin.MIN_GRADLE_VERSION)
class Current : ReportPublicationsPluginTest(GradleVersion.current().baseVersion.version)

private val rootDir = File(System.getProperty("projectRootDir"), gradleVersion)

@Test
fun `when run 'publish' on demo project, produces the expected output`() {
Expand Down Expand Up @@ -97,6 +102,7 @@ class ReportPublicationsPluginTest {
)

return GradleRunner.create()
.withGradleVersion(gradleVersion)
.withProjectDir(rootDir)
.withPluginClasspath()
.withJaCoCo()
Expand Down

0 comments on commit 7d3da7a

Please sign in to comment.