Skip to content

Commit 26845e0

Browse files
committed
Use configurations for passing changelog files in gradle
1 parent a249b1e commit 26845e0

File tree

2 files changed

+55
-52
lines changed

2 files changed

+55
-52
lines changed

Changelog/build.gradle.kts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
val specificationVersion: String by extra
1010
val changelogUntaggedName = "Current release $specificationVersion"
1111

12-
tasks.register<GitChangelogTask>("makeChangelog") {
12+
val makeHtmlChangelog = tasks.register<GitChangelogTask>("makeHtmlChangelog") {
1313
val output = layout.buildDirectory.file("changelog.html")
1414

1515
fromRepo.set(project.rootProject.rootDir.absolutePath)
@@ -23,7 +23,7 @@ tasks.register<GitChangelogTask>("makeChangelog") {
2323
outputs.file(output)
2424
}
2525

26-
tasks.register<GitChangelogTask>("makeMarkdownChangelog") {
26+
val makeMarkdownChangelog = tasks.register<GitChangelogTask>("makeMarkdownChangelog") {
2727
val output = layout.buildDirectory.file("changelog.md")
2828

2929
fromRepo.set(project.rootProject.rootDir.absolutePath)
@@ -40,3 +40,27 @@ tasks.register<GitChangelogTask>("makeMarkdownChangelog") {
4040
tasks.withType<GitChangelogTask> {
4141
outputs.upToDateWhen { false } // Always run
4242
}
43+
44+
val changelogHtml = configurations.create("changelogHtml") {
45+
isCanBeConsumed = true
46+
isCanBeResolved = false
47+
isVisible = false
48+
attributes {
49+
attribute(Usage.USAGE_ATTRIBUTE, objects.named<Usage>("changelogHtml"))
50+
}
51+
outgoing.artifact(makeHtmlChangelog.map { it.outputs.files.singleFile }) {
52+
type = "html"
53+
}
54+
}
55+
56+
val changelogMarkdown = configurations.create("changelogMarkdown") {
57+
isCanBeConsumed = true
58+
isCanBeResolved = false
59+
isVisible = false
60+
attributes {
61+
attribute(Usage.USAGE_ATTRIBUTE, objects.named<Usage>("changelogMarkdown"))
62+
}
63+
outgoing.artifact(makeMarkdownChangelog.map { it.outputs.files.singleFile }) {
64+
type = "markdown"
65+
}
66+
}

NeoForge/build.gradle.kts

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import me.modmuss50.mpp.PublishModTask
2-
import me.modmuss50.mpp.platforms.curseforge.Curseforge
31
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
42
import org.gradle.api.tasks.testing.logging.TestLogEvent
53
import org.slf4j.event.Level
@@ -56,7 +54,6 @@ val dependencyProjects: List<Project> = listOf(
5654
dependencyProjects.forEach {
5755
project.evaluationDependsOn(it.path)
5856
}
59-
project.evaluationDependsOn(":Changelog")
6057

6158
tasks.withType<JavaCompile>().configureEach {
6259
dependencyProjects.forEach {
@@ -77,6 +74,31 @@ java {
7774
withSourcesJar()
7875
}
7976

77+
val changelogHtml = configurations.create("changelogHtml") {
78+
isCanBeConsumed = false
79+
isCanBeResolved = true
80+
isVisible = false
81+
attributes {
82+
attribute(Usage.USAGE_ATTRIBUTE, objects.named<Usage>("changelogHtml"))
83+
}
84+
}
85+
86+
val changelogMarkdown = configurations.create("changelogMarkdown") {
87+
isCanBeConsumed = false
88+
isCanBeResolved = true
89+
isVisible = false
90+
attributes {
91+
attribute(Usage.USAGE_ATTRIBUTE, objects.named<Usage>("changelogMarkdown"))
92+
}
93+
}
94+
95+
fun Configuration.singleFileContents(): Provider<String> =
96+
incoming
97+
.files
98+
.elements
99+
.map { elements -> elements.single() }
100+
.map { it.asFile.readText() }
101+
80102
dependencies {
81103
dependencyProjects.forEach {
82104
implementation(it)
@@ -91,6 +113,8 @@ dependencies {
91113
name = "junit-jupiter-engine",
92114
version = jUnitVersion
93115
)
116+
changelogHtml(project(":Changelog"))
117+
changelogMarkdown(project(":Changelog"))
94118
}
95119

96120
neoForge {
@@ -150,47 +174,6 @@ val sourcesJarTask = tasks.named<Jar>("sourcesJar") {
150174
archiveClassifier.set("sources")
151175
}
152176

153-
154-
abstract class ReadChangelog : DefaultTask() {
155-
@get:InputFile
156-
abstract val inputFile: RegularFileProperty
157-
158-
@get:OutputFile
159-
abstract val outputFile: RegularFileProperty
160-
161-
@TaskAction
162-
fun read() {
163-
val text = inputFile.get().asFile.readText()
164-
outputFile.get().asFile.writeText(text)
165-
}
166-
}
167-
168-
val changelogHtmlFile: Provider<RegularFile> =
169-
project(":Changelog").layout.buildDirectory.file("changelog.html")
170-
171-
val changelogHtmlTask = tasks.register<ReadChangelog>("readChangelogHtml") {
172-
dependsOn(":Changelog:makeChangelog")
173-
inputFile.set(changelogHtmlFile)
174-
outputFile.set(layout.buildDirectory.file("intermediates/changelog.html"))
175-
}
176-
177-
val changelogHtmlContent: Provider<String> = changelogHtmlTask.flatMap {
178-
it.outputFile.map { f -> f.asFile.readText() }
179-
}
180-
181-
val changelogMdFile: Provider<RegularFile> =
182-
project(":Changelog").layout.buildDirectory.file("changelog.md")
183-
184-
val changelogMdTask = tasks.register<ReadChangelog>("readChangelogMd") {
185-
dependsOn(":Changelog:makeMarkdownChangelog")
186-
inputFile.set(changelogMdFile)
187-
outputFile.set(layout.buildDirectory.file("intermediates/changelog.md"))
188-
}
189-
190-
val changelogMdContent: Provider<String> = changelogMdTask.flatMap {
191-
it.outputFile.map { f -> f.asFile.readText() }
192-
}
193-
194177
publishMods {
195178
file.set(tasks.jar.get().archiveFile)
196179
type = BETA
@@ -201,7 +184,7 @@ publishMods {
201184
curseforge {
202185
projectId = curseProjectId
203186
accessToken.set(curseforgeApikey ?: "0")
204-
changelog.set(changelogHtmlContent)
187+
changelog.set(changelogHtml.singleFileContents())
205188
changelogType = "html"
206189
minecraftVersionRange {
207190
start = minecraftVersionRangeStart
@@ -213,18 +196,14 @@ publishMods {
213196
modrinth {
214197
projectId = modrinthId
215198
accessToken = modrinthToken
216-
changelog.set(changelogMdContent)
199+
changelog.set(changelogMarkdown.singleFileContents())
217200
minecraftVersionRange {
218201
start = minecraftVersionRangeStart
219202
end = minecraftVersion
220203
}
221204
}
222205
}
223206

224-
tasks.withType<PublishModTask> {
225-
dependsOn(tasks.jar, changelogHtmlTask, changelogMdTask)
226-
}
227-
228207
tasks.named<Test>("test") {
229208
useJUnitPlatform()
230209
include("mezz/jei/test/**")

0 commit comments

Comments
 (0)