Added check for Gradle version.
This commit is contained in:
parent
0c62bba423
commit
5b8a298a2b
1 changed files with 7 additions and 2 deletions
|
@ -34,12 +34,14 @@ package net.thauvin.erik.gradle.semver
|
||||||
import org.gradle.api.GradleException
|
import org.gradle.api.GradleException
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.util.GradleVersion
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
|
|
||||||
class SemverPlugin : Plugin<Project> {
|
class SemverPlugin : Plugin<Project> {
|
||||||
|
private val simpleName = SemverPlugin::class.simpleName
|
||||||
private var version = Version()
|
private var version = Version()
|
||||||
private lateinit var config: SemverConfig
|
private lateinit var config: SemverConfig
|
||||||
|
|
||||||
|
@ -65,6 +67,9 @@ class SemverPlugin : Plugin<Project> {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun apply(project: Project?) {
|
override fun apply(project: Project?) {
|
||||||
|
if (GradleVersion.current() < GradleVersion.version("4.8.1")) {
|
||||||
|
throw GradleException("The $simpleName plugin requires Gradle version 4.8.1 or greater.")
|
||||||
|
}
|
||||||
project!!.afterEvaluate(this::afterEvaluate)
|
project!!.afterEvaluate(this::afterEvaluate)
|
||||||
config = project.extensions.create("semver", SemverConfig::class.java)
|
config = project.extensions.create("semver", SemverConfig::class.java)
|
||||||
|
|
||||||
|
@ -83,9 +88,9 @@ class SemverPlugin : Plugin<Project> {
|
||||||
}
|
}
|
||||||
propsFile.apply {
|
propsFile.apply {
|
||||||
project.logger.info(
|
project.logger.info(
|
||||||
"[${SemverPlugin::class.simpleName}] Attempting to read properties from: `$absoluteFile`. [exists: ${exists()}, canRead: ${canRead()}]")
|
|
||||||
if (canRead()) {
|
if (canRead()) {
|
||||||
FileInputStream(this).use { fis ->
|
FileInputStream(this).use { fis ->
|
||||||
|
"[$simpleName] Attempting to read properties from: `$absoluteFile`. [exists: ${exists()}, isFile: $isFile, canRead: ${canRead()}]")
|
||||||
Properties().apply {
|
Properties().apply {
|
||||||
load(fis)
|
load(fis)
|
||||||
version.major = getProperty(config.majorKey, Version.DEFAULT_MAJOR)
|
version.major = getProperty(config.majorKey, Version.DEFAULT_MAJOR)
|
||||||
|
@ -104,7 +109,7 @@ class SemverPlugin : Plugin<Project> {
|
||||||
throw GradleException("Unable to read version from: `$absoluteFile`")
|
throw GradleException("Unable to read version from: `$absoluteFile`")
|
||||||
}
|
}
|
||||||
project.version = version.semver
|
project.version = version.semver
|
||||||
project.logger.info("[${SemverPlugin::class.simpleName}] Project version set to: ${project.version}")
|
project.logger.info("[$simpleName] Project version set to: ${project.version}")
|
||||||
saveProperties(config, version)
|
saveProperties(config, version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue