This project requires Gradle 6.6 or newer
TIP: Upgrade Gradle Wrapper with
./gradlew wrapper --gradle-version 6.8.2
A Gradle plugin that provides tasks and helper methods to simplify working with a changelog that is managed in the keep a changelog style.
- Usage
- Configuration
- Tasks
- Extension Methods
Changelog.Item
- Gradle Closure in Kotlin DSL
- Helper Methods
- Usage Examples
- Contributing
Kotlin:
import org.jetbrains.changelog.closure
import org.jetbrains.changelog.date
plugins {
id("org.jetbrains.changelog") version "1.1.1"
}
tasks {
// ...
patchPluginXml {
changeNotes(closure { changelog.getUnreleased().toHTML() })
}
}
changelog {
version = "1.0.0"
path = "${project.projectDir}/CHANGELOG.md"
header = closure { "[$version] - ${date()}" }
itemPrefix = "-"
keepUnreleasedSection = true
unreleasedTerm = "[Unreleased]"
groups = listOf("Added", "Changed", "Deprecated", "Removed", "Fixed", "Security")
}
Groovy:
import org.jetbrains.changelog.ExtensionsKt
plugins {
id 'org.jetbrains.changelog' version '1.1.1'
}
apply plugin: 'org.jetbrains.changelog'
intellij {
// ...
patchPluginXml {
changeNotes({ changelog.getUnreleased().toHTML() })
}
}
changelog {
version = "1.0.0"
path = "${project.projectDir}/CHANGELOG.md"
header = { "[$version] - ${ExtensionsKt.date()}" }
headerParserRegex = ~/\d+\.\d+/
itemPrefix = "-"
keepUnreleasedSection = true
unreleasedTerm = "[Unreleased]"
groups = ["Added", "Changed", "Deprecated", "Removed", "Fixed", "Security"]
}
Note:
closure
is a wrapper for theKotlinClosure0
class and can be used directly as following:import org.gradle.kotlin.dsl.KotlinClosure0 changeNotes(KotlinClosure0({ changelog.getUnreleased() }))
Plugin can be configured with the following properties set in the changelog {}
closure:
Property | Description | Default value |
---|---|---|
version |
Required. Current project's version. | |
groups |
List of groups created with a new Unreleased section. | ["Added", "Changed", "Deprecated", "Removed", "Fixed", "Security"] |
header |
Closure that returns current header value. | { "[$version]" } |
headerParserRegex |
Regex /Pattern /String used to extract version from the header string. |
null , fallbacks to Changelog#semVerRegex |
itemPrefix |
Single item's prefix, allows to customise the bullet sign. | "-" |
keepUnreleasedSection |
Add Unreleased empty section after patching. | true |
patchEmpty |
Patches changelog even if no release note is provided. | true |
path |
Path to the changelog file. | "${project.projectDir}/CHANGELOG.md" |
unreleasedTerm |
Unreleased section text. | "[Unreleased]" |
Note:
header
closure has the delegate explicitly set to the extension's context for the sake of the Configuration cache support.
The plugin introduces the following tasks:
Task | Description |
---|---|
getChangelog |
Retrieves changelog for the specified version. |
initializeChangelog |
Creates new changelog file with Unreleased section and empty groups. |
patchChangelog |
Updates the unreleased section to the given version. Requires unreleased section to be present in the changelog file. |
$ ./gradlew initializeChangelog
$ cat CHANGELOG.md
## [Unreleased]
### Added
- Example item
### Changed
### Deprecated
### Removed
### Fixed
### Security
Option | Description |
---|---|
--no-header |
Skips the first version header line in the output. |
--unreleased |
Returns Unreleased change notes. |
$ ./gradlew getChangelog --console=plain -q --no-header
### Added
- Initial project scaffold
- GitHub Actions to automate testing and deployment
- Kotlin support
All the methods are available via the changelog
extension and allow for reading the changelog file within the Gradle tasks to provide the latest (or specific) change notes.
Note: Following methods depend on the
changelog
extension, which is set in the Configuration build phase. To make it running properly, it's required to place the configuration before the fist usage of such a method. Alternatively, you can pass the Gradle closure to the task, which will postpone the method invocation.
The method returns a Changelog.Item
object for the specified version.
Throws MissingVersionException
if the version is not available.
It is possible to specify the unreleased section with setting the ${changelog.unreleasedTerm}
value.
Parameter | Type | Description | Default value |
---|---|---|---|
version |
String |
Change note version. | ${changelog.version} |
Kotlin:
tasks {
patchPluginXml {
changeNotes(closure { changelog.get("1.0.0").toHTML() })
}
}
Groovy:
tasks {
patchPluginXml {
changeNotes({ changelog.get("1.0.0").toHTML() })
}
}
The method returns a Changelog.Item
object for the unreleased version.
Kotlin:
tasks {
patchPluginXml {
changeNotes(closure { changelog.getUnreleased().toHTML() })
}
}
Groovy:
tasks {
patchPluginXml {
changeNotes({ changelog.getUnreleased().toHTML() })
}
}
The method returns the latest Changelog.Item
object (first on the list).
Kotlin:
tasks {
patchPluginXml {
changeNotes(closure { changelog.getLatest().toHTML() })
}
}
Groovy:
tasks {
patchPluginXml {
changeNotes({ changelog.getLatest().toHTML() })
}
}
The method returns all available Changelog.Item
objects.
Kotlin:
extension.getAll().values.map { it.toText() }
Groovy:
extension.getAll().values().each { it.toText() }
The method checks if the given version exists in the changelog.
Kotlin:
tasks {
patchPluginXml {
closure { changelog.has("1.0.0") }
}
}
Groovy:
tasks {
patchPluginXml {
{ changelog.has("1.0.0") }
}
}
Methods described in the above section return Changelog.Item
object, which is a representation of the single changelog section for the specific version.
It provides a couple of properties and methods that allow altering the output form of the change notes:
Name | Type | Description |
---|---|---|
version |
String |
Change note version. |
Name | Description | Returned type |
---|---|---|
noHeader() |
Excludes header part. | this |
noHeader(Boolean) |
Includes/excludes header part. | this |
getHeader() |
Returns header text. | String |
toText() |
Generates Markdown output. | String |
toPlainText() |
Generates Plain Text output. | String |
toString() |
Generates Markdown output. | String |
toHTML() |
Generates HTML output. | String |
To produce Gradle-specific closure in Kotlin DSL, required by some third-party plugins, like gradle-intellij-plugin it is required to wrap the Kotlin Unit with KotlinClosure0
class:
KotlinClosure0({ changelog.get("1.0.0") })
There is also a neater method available:
import org.jetbrains.changelog.closure
closure { changelog.get("1.0.0") }
Name | Description | Returned type |
---|---|---|
closure(function: () -> T) |
Produces Gradle-specific Closure for Kotlin DSL. | Closure<T> |
date(pattern: String = "yyyy-MM-dd") |
Shorthand for retrieving the current date in the given format. | String |
markdownToHTML(input: String) |
Converts given Markdown content to HTML output. | String |
markdownToPlainText(input: String) |
Converts given Markdown content to Plain Text output. | String |
Note: To use package-level Kotlin functions in Groovy, you need to import the containing file as a class:
import org.jetbrains.changelog.ExtensionsKt changelog { header = { "[$version] - ${ExtensionsKt.date('yyyy-MM-dd')}" } }
To perform integration tests with an existing project, bind the gradle-changelog-plugin
sources in the Gradle settings file:
settings.gradle
:
rootProject.name = "IntelliJ Platform Plugin Template"
includeBuild '/Users/hsz/Projects/JetBrains/gradle-changelog-plugin'
settings.gradle.kts
:
rootProject.name = "IntelliJ Platform Plugin Template"
includeBuild("/Users/hsz/Projects/JetBrains/gradle-changelog-plugin")