Skip to content

Commit 1323082

Browse files
committed
changelog.publishAll no longer affects subprojects by default
Publishing the changelog to subprojects can still be done this way: ```groovy changelog { fromBase() publishAll = true includeSubprojects = true // NEW! } ``` The only projects I believe need this are Forge and Bootstrap.
1 parent 8b19240 commit 1323082

File tree

12 files changed

+119
-95
lines changed

12 files changed

+119
-95
lines changed

.gitversion.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[gradlePlugin]
2+
path = "gradle-plugin"
3+
tag = "gradle"

gradle-plugin/changelog-gradle/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ dependencies {
5959
}
6060

6161
// Removes local Gradle API from compileOnly. This is a workaround for bugged plugins.
62-
// TODO [GradleUtils][GradleAPI] Remove this once they are fixed.
6362
// Publish Plugin: https://github.com/gradle/plugin-portal-requests/issues/260
6463
// Shadow: https://github.com/GradleUp/shadow/pull/1422
6564
afterEvaluate { project ->

gradle-plugin/changelog-gradle/src/main/groovy/net/minecraftforge/gitversion/gradle/changelog/ChangelogExtension.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,17 @@ public sealed interface ChangelogExtension permits ChangelogExtensionInternal {
4444

4545
/// The property that sets if the changelog generation should be enabled for all maven publications in the project.
4646
///
47-
/// It will also set up publishing for all subprojects as long as that subproject does not have another changelog
47+
/// @apiNote To set up publishing for all subprojects, as long as that subproject does not have another changelog
4848
/// plugin overriding the propagation.
4949
///
5050
/// @return The property for if the changelog generation is enabled for all maven publications
5151
Property<Boolean> getPublishAll();
52+
53+
/// If [publishing all][#getPublishAll()], this property determines if subproject publications should be included.
54+
///
55+
/// The changelog from the parent project will be copied to the subproject using a [CopyChangelog] task as long as
56+
/// the subproject does not have another changelog plugin overriding the propagation.
57+
///
58+
/// @return The property for if the changelog generation for publishing to all should include subprojects
59+
Property<Boolean> getIncludeSubprojects();
5260
}

gradle-plugin/changelog-gradle/src/main/groovy/net/minecraftforge/gitversion/gradle/changelog/ChangelogExtensionImpl.groovy

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package net.minecraftforge.gitversion.gradle.changelog
66

77
import groovy.transform.CompileStatic
88
import groovy.transform.PackageScope
9-
import groovy.transform.PackageScopeTarget
109
import org.gradle.api.Project
1110
import org.gradle.api.model.ObjectFactory
1211
import org.gradle.api.provider.Property
@@ -17,11 +16,11 @@ import org.gradle.api.tasks.TaskProvider
1716
import javax.inject.Inject
1817

1918
@CompileStatic
20-
@PackageScope([PackageScopeTarget.CLASS, PackageScopeTarget.FIELDS])
21-
abstract class ChangelogExtensionImpl implements ChangelogExtensionInternal {
19+
@PackageScope abstract class ChangelogExtensionImpl implements ChangelogExtensionInternal {
2220
private final Project project
2321

2422
private final Property<Boolean> publishingAll
23+
private final Property<Boolean> includingSubprojects
2524
private final Property<Boolean> isGenerating
2625

2726
private @Lazy TaskProvider<? extends GenerateChangelog> task = {
@@ -38,12 +37,13 @@ abstract class ChangelogExtensionImpl implements ChangelogExtensionInternal {
3837
this.project = project
3938

4039
this.publishingAll = this.objects.property(Boolean).convention(false)
40+
this.includingSubprojects = this.objects.property(Boolean).convention(false)
4141
this.isGenerating = this.objects.property(Boolean).convention(false)
4242
}
4343

4444
private void finish(Project project) {
45-
if (this.publishAll.getOrElse(false))
46-
ChangelogUtils.setupChangelogGenerationOnAllPublishTasks(project)
45+
if (this.publishingAll.getOrElse(false))
46+
ChangelogUtils.setupChangelogGenerationOnAllPublishTasks(project, this.includingSubprojects)
4747
}
4848

4949
@Override
@@ -71,22 +71,25 @@ abstract class ChangelogExtensionImpl implements ChangelogExtensionInternal {
7171
this.publishingAll
7272
}
7373

74+
@Override
75+
Property<Boolean> getIncludeSubprojects() {
76+
this.includingSubprojects
77+
}
78+
7479
@Override
7580
boolean isGenerating() {
7681
this.isGenerating.get()
7782
}
7883

7984
@Override
80-
TaskProvider<CopyChangelog> copyTo(Project project) {
85+
TaskProvider<? extends CopyChangelog> copyTo(Project project) {
8186
// isGenerating = true and afterEvaluate ensured
8287
// See ChangelogUtils#setupChangelogGenerationForPublishingAfterEvaluation
83-
project.tasks.register(CopyChangelog.NAME, CopyChangelog) { task ->
88+
project.tasks.register(CopyChangelog.NAME, CopyChangelogImpl) { task ->
8489
task.dependsOn(this.task)
8590

8691
var dependency = project.dependencies.project('path': this.project.path, 'configuration': GenerateChangelog.NAME)
87-
var configuration = project.configurations.detachedConfiguration(dependency).tap {
88-
it.canBeConsumed = false
89-
}
92+
var configuration = project.configurations.detachedConfiguration(dependency).tap { canBeConsumed = false }
9093
task.inputFile.fileProvider(project.providers.provider(configuration.&getSingleFile))
9194
}
9295
}

gradle-plugin/changelog-gradle/src/main/groovy/net/minecraftforge/gitversion/gradle/changelog/ChangelogExtensionInternal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ default TypeOf<?> getPublicType() {
1717

1818
boolean isGenerating();
1919

20-
TaskProvider<CopyChangelog> copyTo(Project project);
20+
TaskProvider<? extends CopyChangelog> copyTo(Project project);
2121
}

gradle-plugin/changelog-gradle/src/main/groovy/net/minecraftforge/gitversion/gradle/changelog/ChangelogUtils.groovy

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import groovy.transform.PackageScope
99
import groovy.transform.PackageScopeTarget
1010
import org.gradle.api.Project
1111
import org.gradle.api.Task
12-
import org.gradle.api.file.FileCollection
12+
import org.gradle.api.provider.Property
1313
import org.gradle.api.publish.PublishingExtension
1414
import org.gradle.api.publish.maven.MavenArtifact
1515
import org.gradle.api.publish.maven.MavenPublication
16-
import org.gradle.api.tasks.TaskOutputs
1716
import org.gradle.api.tasks.TaskProvider
1817
import org.gradle.language.base.plugins.LifecycleBasePlugin
1918
import org.jetbrains.annotations.Nullable
@@ -48,22 +47,24 @@ class ChangelogUtils {
4847
*
4948
* @param project The project to add changelog generation publishing to
5049
*/
51-
static void setupChangelogGenerationOnAllPublishTasks(Project project) {
50+
static void setupChangelogGenerationOnAllPublishTasks(Project project, Property<Boolean> includingSubprojects) {
5251
setupChangelogGenerationForAllPublications(project)
5352

54-
project.subprojects {
55-
Util.ensureAfterEvaluate(it) { subproject ->
56-
// attempt to get the current subproject's changelog extension
57-
var changelog = subproject.extensions.findByType(ChangelogExtension)
53+
if (includingSubprojects.getOrElse(false)) {
54+
project.subprojects {
55+
Util.ensureAfterEvaluate(it) { subproject ->
56+
// attempt to get the current subproject's changelog extension
57+
@Nullable var changelog = subproject.extensions.findByType(ChangelogExtension)
5858

59-
// find the changelog extension for the highest project that has it, if the subproject doesn't
60-
for (var parent = project; changelog === null && parent !== null; parent = parent.parent == parent ? null : parent.parent) {
61-
changelog = parent.extensions.findByType(ChangelogExtension)
62-
}
59+
// find the changelog extension for the highest project that has it, if the subproject doesn't
60+
for (var parent = project; changelog === null && parent !== null; parent = parent.parent == parent ? null : parent.parent) {
61+
changelog = parent.extensions.findByType(ChangelogExtension)
62+
}
6363

64-
// if the project with changelog is publishing all changelogs, set up changelogs for the subproject
65-
if (changelog?.publishAll?.getOrElse(false))
66-
setupChangelogGenerationForAllPublications(subproject)
64+
// if the project with changelog is publishing all changelogs, set up changelogs for the subproject
65+
if (changelog?.publishAll?.getOrElse(false))
66+
setupChangelogGenerationForAllPublications(subproject)
67+
}
6768
}
6869
}
6970
}

gradle-plugin/changelog-gradle/src/main/groovy/net/minecraftforge/gitversion/gradle/changelog/CopyChangelog.java

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,10 @@
44
*/
55
package net.minecraftforge.gitversion.gradle.changelog;
66

7-
import org.gradle.api.DefaultTask;
8-
import org.gradle.api.file.ProjectLayout;
9-
import org.gradle.api.file.RegularFileProperty;
10-
import org.gradle.api.provider.ProviderFactory;
11-
import org.gradle.api.reflect.HasPublicType;
12-
import org.gradle.api.reflect.TypeOf;
13-
import org.gradle.api.tasks.InputFile;
14-
import org.gradle.api.tasks.Internal;
15-
import org.gradle.api.tasks.OutputFile;
16-
import org.gradle.api.tasks.TaskAction;
7+
import org.gradle.api.Task;
178

18-
import javax.inject.Inject;
19-
import java.io.File;
20-
import java.io.IOException;
21-
import java.nio.file.Files;
22-
23-
// This task class is internal. Do NOT attempt to use it directly.
24-
// If you need the output, use `project.tasks.named('copyChangelog').outputs.files` instead
25-
abstract class CopyChangelog extends DefaultTask implements HasPublicType {
26-
static final String NAME = "copyChangelog";
27-
28-
protected abstract @Inject ProviderFactory getProviders();
29-
30-
@Inject
31-
public CopyChangelog(ProjectLayout layout) {
32-
this.setDescription("Copies a changelog file to this project's build directory.");
33-
34-
this.getOutputFile().convention(layout.getBuildDirectory().file("changelog.txt"));
35-
}
36-
37-
@Override
38-
public @Internal TypeOf<?> getPublicType() {
39-
return TypeOf.typeOf(DefaultTask.class);
40-
}
41-
42-
public abstract @OutputFile RegularFileProperty getOutputFile();
43-
44-
public abstract @InputFile RegularFileProperty getInputFile();
45-
46-
@TaskAction
47-
public void exec() {
48-
byte[] input;
49-
try {
50-
// ProviderFactory#fileContents so Gradle is aware of our usage of the input
51-
input = this.getProviders().fileContents(this.getInputFile()).getAsBytes().get();
52-
} catch (IllegalStateException e) {
53-
throw new RuntimeException(e);
54-
}
55-
56-
File output = this.getOutputFile().get().getAsFile();
57-
58-
if (!output.getParentFile().exists() && !output.getParentFile().mkdirs())
59-
throw new IllegalStateException();
60-
61-
try {
62-
Files.write(
63-
output.toPath(),
64-
input
65-
);
66-
} catch (IOException e) {
67-
throw new RuntimeException(e);
68-
}
69-
}
9+
/// Copies a changelog from a parent project to this subproject.
10+
public sealed interface CopyChangelog extends Task permits CopyChangelogInternal {
11+
/// The name for this task.
12+
String NAME = "copyChangelog";
7013
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
package net.minecraftforge.gitversion.gradle.changelog
6+
7+
import groovy.transform.CompileStatic
8+
import groovy.transform.PackageScope
9+
import groovy.transform.PackageScopeTarget
10+
import org.gradle.api.DefaultTask
11+
import org.gradle.api.file.RegularFileProperty
12+
import org.gradle.api.provider.ProviderFactory
13+
import org.gradle.api.tasks.InputFile
14+
import org.gradle.api.tasks.OutputFile
15+
import org.gradle.api.tasks.TaskAction
16+
17+
import javax.inject.Inject
18+
19+
// This task class is internal. Do NOT attempt to use it directly.
20+
// If you need the output, use `project.tasks.named('copyChangelog').outputs.files` instead
21+
@CompileStatic
22+
@PackageScope abstract class CopyChangelogImpl extends DefaultTask implements CopyChangelogInternal {
23+
protected abstract @Inject ProviderFactory getProviders()
24+
25+
@Inject
26+
CopyChangelogImpl() {
27+
this.description = 'Copies a changelog file to this project\'s build directory.'
28+
29+
this.outputFile.convention(this.getDefaultOutputFile('txt'))
30+
}
31+
32+
protected abstract @InputFile RegularFileProperty getInputFile()
33+
protected abstract @OutputFile RegularFileProperty getOutputFile()
34+
35+
@TaskAction
36+
void exec() {
37+
var input = this.providers.fileContents(this.inputFile).asBytes.get()
38+
var output = this.outputFile.asFile.get()
39+
40+
output.bytes = input
41+
}
42+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) Forge Development LLC
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
package net.minecraftforge.gitversion.gradle.changelog;
6+
7+
import net.minecraftforge.gradleutils.shared.EnhancedPlugin;
8+
import net.minecraftforge.gradleutils.shared.EnhancedTask;
9+
import org.gradle.api.Project;
10+
import org.gradle.api.reflect.HasPublicType;
11+
import org.gradle.api.reflect.TypeOf;
12+
import org.gradle.api.tasks.Internal;
13+
14+
non-sealed interface CopyChangelogInternal extends CopyChangelog, EnhancedTask, HasPublicType {
15+
@Override
16+
default Class<? extends EnhancedPlugin<? super Project>> pluginType() {
17+
return ChangelogPlugin.class;
18+
}
19+
20+
@Override
21+
default @Internal TypeOf<?> getPublicType() {
22+
return TypeOf.typeOf(CopyChangelog.class);
23+
}
24+
}

gradle-plugin/common/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ dependencies {
1212
// Static Analysis
1313
compileOnly libs.nulls
1414

15+
// Gradle
16+
compileOnly libs.gradle
17+
1518
// GradleUtils
1619
implementation libs.gradleutils.shared
1720
}

0 commit comments

Comments
 (0)