Skip to content

Commit 54e9798

Browse files
committed
Build ourselves using GradleUtils 3.3.16
1 parent eb56efb commit 54e9798

File tree

6 files changed

+93
-50
lines changed

6 files changed

+93
-50
lines changed

build.gradle

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ plugins {
66
id 'idea'
77
id 'eclipse'
88
id 'maven-publish'
9-
//id 'io.freefair.javadoc-links'
10-
id 'net.minecraftforge.gradleutils'
11-
id 'net.minecraftforge.gitversion'
12-
alias libs.plugins.changelog
9+
alias libs.plugins.javadoc.links
10+
alias libs.plugins.versions
1311
alias libs.plugins.licenser
12+
alias libs.plugins.gradleutils
13+
alias libs.plugins.gitversion
14+
alias libs.plugins.changelog
1415
alias libs.plugins.plugin.publish
1516
alias libs.plugins.shadow
1617
}
1718

1819
gradleutils.displayName = 'Forge Gradle Utilities'
19-
description = 'Small collection of utilities for standardizing MinecraftForge gradle scripts'
20-
base.archivesName = 'gradleutils'
20+
description = "Small collection of utilities for standardizing Forge's buildscripts."
2121
group = 'net.minecraftforge'
22-
// version set by gitversion in settings.gradle
22+
version = gitversion.tagOffset
23+
24+
println "Version: $version"
2325

2426
java {
2527
toolchain.languageVersion = JavaLanguageVersion.of(17)

gradle.properties

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@ org.gradle.configuration-cache=true
66
org.gradle.configuration-cache.parallel=true
77
org.gradle.configuration-cache.problems=warn
88

9-
systemProp.org.gradle.unsafe.suppress-gradle-api=true
10-
119
net.minecraftforge.gradleutils.ide.automatic.sources=true
1210
net.minecraftforge.gradleutils.compilation.defaults=true
13-
14-
net.minecraftforge.gitversion.log.version=true

gradleutils-shared/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ plugins {
77
id 'idea'
88
id 'eclipse'
99
id 'maven-publish'
10-
//id 'io.freefair.javadoc-links'
11-
id 'net.minecraftforge.gradleutils'
10+
alias libs.plugins.javadoc.links
11+
alias libs.plugins.versions
1212
alias libs.plugins.licenser
13+
alias libs.plugins.gradleutils
14+
alias libs.plugins.gitversion
1315
alias libs.plugins.shadow
1416
}
1517

1618
gradleutils.displayName = 'GradleUtils Shared'
1719
description = 'The shared base used by all of Forge\'s Gradle plugins.'
1820
base.archivesName = 'gradleutils-shared'
1921
group = 'net.minecraftforge'
20-
// version set by gitversion in settings.gradle
22+
version = gitversion.tagOffset
2123

2224
java {
2325
toolchain.languageVersion = JavaLanguageVersion.of(17)

gradleutils-shared/src/main/java/net/minecraftforge/gradleutils/shared/SharedUtil.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.io.PipedInputStream;
4343
import java.io.PipedOutputStream;
4444
import java.util.ArrayList;
45+
import java.util.Collection;
4546
import java.util.List;
4647
import java.util.Objects;
4748
import java.util.Set;
@@ -201,8 +202,10 @@ public static void ensureAfterEvaluate(Project project, Action<? super Project>
201202
///
202203
/// This *does not* break the configuration cache as long as the task is always applied using this.
203204
///
205+
/// @param <T> The type of task to be run
204206
/// @param project The project
205-
/// @param task The task to run first
207+
/// @param task The provider of the task to run first
208+
/// @return The task provider
206209
public static <T extends TaskProvider<?>> T runFirst(Project project, T task) {
207210
// copy the requests because the backed list isn't concurrent
208211
var requests = new ArrayList<>(project.getGradle().getStartParameter().getTaskRequests());
@@ -306,13 +309,25 @@ public static Set<Dependency> collect(ConfigurationContainer configurations, Sou
306309

307310
private static <T> void guardCheck(T t) { }
308311

312+
/// Iterates through the given source set's classpath configurations using the given action.
313+
///
314+
/// @param configurations The configuration container
315+
/// @param sourceSet The source set
316+
/// @param action The action to run
317+
/// @see #forEach(DomainObjectCollection, Action)
309318
public static void forEachClasspath(ConfigurationContainer configurations, SourceSet sourceSet, Action<? super Configuration> action) {
310319
forEach(configurations.named(
311320
name -> name.equals(sourceSet.getCompileClasspathConfigurationName())
312321
|| name.equals(sourceSet.getRuntimeClasspathConfigurationName())
313322
), action);
314323
}
315324

325+
/// Iterates through the given source set's classpath configurations eagerly using the given action.
326+
///
327+
/// @param configurations The configuration container
328+
/// @param sourceSet The source set
329+
/// @param action The action to run
330+
/// @see #forEachEagerly(DomainObjectCollection, Action)
316331
public static void forEachClasspathEagerly(ConfigurationContainer configurations, SourceSet sourceSet, Action<? super Configuration> action) {
317332
forEachEagerly(configurations.named(
318333
name -> name.equals(sourceSet.getCompileClasspathConfigurationName())
@@ -322,6 +337,16 @@ public static void forEachClasspathEagerly(ConfigurationContainer configurations
322337
//endregion
323338

324339
//region Domain Object Handling
340+
341+
/// Iterates through the given collection using the given action.
342+
///
343+
/// This iterator will attempt to use [DomainObjectCollection#configureEach(Action)] if it is in an eager context.
344+
/// If it is not, a [copy of][List#copyOf(Collection)] the collection will be iterated through using
345+
/// [List#forEach(Consumer)] instead to prevent a [java.util.ConcurrentModificationException].
346+
///
347+
/// @param <T> The type for the collection
348+
/// @param collection The collection to iterate through
349+
/// @param action The action to run
325350
public static <T> void forEach(DomainObjectCollection<T> collection, Action<? super T> action) {
326351
boolean eager = false;
327352
try {
@@ -331,12 +356,20 @@ public static <T> void forEach(DomainObjectCollection<T> collection, Action<? su
331356
}
332357

333358
if (eager) {
334-
collection.forEach(action::execute);
359+
List.copyOf(collection).forEach(action::execute);
335360
} else {
336361
collection.configureEach(action);
337362
}
338363
}
339364

365+
/// Iterates through the given collection eagerly using the given action.
366+
///
367+
/// This iterator will iterate over a [copy of][List#copyOf(Collection)] the collection using
368+
/// [List#forEach(Consumer)] to prevent a [java.util.ConcurrentModificationException].
369+
///
370+
/// @param <T> The type for the collection
371+
/// @param collection The collection to iterate through
372+
/// @param action The action to run
340373
public static <T> void forEachEagerly(DomainObjectCollection<T> collection, Action<? super T> action) {
341374
List.copyOf(collection).forEach(action::execute);
342375
}
@@ -347,6 +380,7 @@ public static <T> void forEachEagerly(DomainObjectCollection<T> collection, Acti
347380
/// Creates an output stream that logs to the given action.
348381
///
349382
/// @param logger The logger to log to
383+
/// @param level The log level to log at
350384
/// @return The output stream
351385
public static PipedOutputStream toLog(Logger logger, LogLevel level) {
352386
return toLog(s -> logger.log(level, s));

settings.gradle

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,41 @@
1-
pluginManagement {
2-
repositories {
3-
mavenCentral()
4-
gradlePluginPortal()
5-
maven { url = 'https://maven.minecraftforge.net/' }
6-
//mavenLocal()
7-
}
8-
}
9-
101
plugins {
11-
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0' // https://plugins.gradle.org/plugin/org.gradle.toolchains.foojay-resolver-convention
12-
13-
// NOTE: We need to load this into the classpath before GradleUtils for the service to load correctly
14-
id 'io.freefair.javadoc-links' version '8.14' apply false // https://plugins.gradle.org/plugin/io.freefair.javadoc-links
15-
16-
id 'net.minecraftforge.gradleutils' version '3.2.25' // https://plugins.gradle.org/plugin/net.minecraftforge.gradleutils
17-
id 'net.minecraftforge.gitversion' version '3.0.7' // https://plugins.gradle.org/plugin/net.minecraftforge.gitversion
2+
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
183
}
194

205
rootProject.name = 'gradleutils'
216

227
include 'gradleutils-shared'
238

24-
dependencyResolutionManagement {
25-
repositories {
26-
mavenCentral()
27-
gradlePluginPortal()
28-
maven gradleutils.forgeMaven
29-
maven { url = 'https://maven.moddinglegacy.com' } // Gradle API
30-
//mavenLocal()
9+
// Applying plugins causes them to not have any IDE support when also applied to any build.gradle files
10+
// The workaround for now is to use this listener here so that it can stay in settings.gradle
11+
// See: https://youtrack.jetbrains.com/issue/IDEA-332061/Gradle-Missing-Code-Completion-Suggestions-for-Settings-Plugins-in-Groovy-DSL
12+
gradle.beforeProject { Project project ->
13+
project.pluginManager.withPlugin('net.minecraftforge.gradleutils') {
14+
project.repositories {
15+
mavenCentral()
16+
gradlePluginPortal()
17+
maven project.gradleutils.forgeMaven
18+
maven { url = 'https://maven.moddinglegacy.com' } // Gradle API
19+
//mavenLocal()
20+
}
3121
}
22+
}
3223

24+
//@formatter:off
25+
dependencyResolutionManagement {
3326
versionCatalogs {
3427
register('libs') {
3528
version 'gradle-javadoc-links', '8.14'
36-
version 'gradle-versions', '0.53.0'
29+
version 'gradle-versions', '0.53.0'
3730

38-
plugin 'licenser', 'net.minecraftforge.licenser' version '1.2.0' // https://plugins.gradle.org/plugin/net.minecraftforge.licenser
39-
plugin 'changelog', 'net.minecraftforge.changelog' version '3.0.6' // https://plugins.gradle.org/plugin/net.minecraftforge.changelog
40-
plugin 'plugin-publish', 'com.gradle.plugin-publish' version '1.3.1' // https://plugins.gradle.org/plugin/com.gradle.plugin-publish
41-
plugin 'shadow', 'com.gradleup.shadow' version '9.0.2' // https://plugins.gradle.org/plugin/com.gradleup.shadow
31+
plugin 'javadoc-links', 'io.freefair.javadoc-links' versionRef 'gradle-javadoc-links'
32+
plugin 'versions', 'com.github.ben-manes.versions' versionRef 'gradle-versions'
33+
plugin 'licenser', 'net.minecraftforge.licenser' version '1.2.0'
34+
plugin 'gradleutils', 'net.minecraftforge.gradleutils' version '3.3.16'
35+
plugin 'gitversion', 'net.minecraftforge.gitversion' version '3.1.1'
36+
plugin 'changelog', 'net.minecraftforge.changelog' version '3.1.2'
37+
plugin 'plugin-publish', 'com.gradle.plugin-publish' version '2.0.0'
38+
plugin 'shadow', 'com.gradleup.shadow' version '9.2.2'
4239

4340
// Static Analysis
4441
library 'nulls', 'org.jetbrains', 'annotations' version '26.0.2'
@@ -70,3 +67,4 @@ dependencyResolutionManagement {
7067
}
7168
}
7269
}
70+
//@formatter:on

src/main/groovy/net/minecraftforge/gradleutils/GradleUtilsExtensionForProject.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,30 @@ public sealed interface GradleUtilsExtensionForProject extends GradleUtilsExtens
3333
/// @return The property for the vendor
3434
Property<String> getVendor();
3535

36+
/// Sets the default attributes for the given manifest and attaches the given package name as the section name.
37+
///
38+
/// @param manifest The manifest to apply defaults to
39+
/// @param packageName The package name to use as the section name
3640
default void manifestDefaults(Manifest manifest, String packageName) {
3741
this.manifestDefaults(manifest, packageName, Map.of());
3842
}
3943

44+
/// Sets the default attributes for the given manifest and attaches the given package name as the section name.
45+
///
46+
/// @param manifest The manifest to apply defaults to
47+
/// @param packageName The package name to use as the section name
48+
/// @param additionalEntries A map of additional entries to add
49+
/// @apiNote GradleUtils will automatically attempt to [GradleUtilsExtension#unpack] any [values][Map#values()] in
50+
/// the maps.
4051
void manifestDefaults(Manifest manifest, String packageName, Map<? extends CharSequence, ?> additionalEntries);
4152

4253
/// Applies known defaults for Minecraft Forge's Gradle plugins.
4354
///
4455
/// - For all configurations that
4556
/// {@linkplain org.codehaus.groovy.runtime.StringGroovyMethods#containsIgnoreCase(CharSequence, CharSequence)
4657
/// contain (ignoring case)} "runtimeElements", the
47-
/// [org.gradle.api.attributes.plugin.GradlePluginApiVersion#GRADLE_PLUGIN_API_VERSION_ATTRIBUTE] attribute with
48-
/// the value of the given Gradle version.
58+
/// [org.gradle.api.attributes.plugin.GradlePluginApiVersion#GRADLE_PLUGIN_API_VERSION_ATTRIBUTE] attribute with the
59+
/// value of the given Gradle version.
4960
///
5061
/// @param configurations The configurations container to apply defaults to
5162
/// @param gradleVersion The Gradle version to target
@@ -56,8 +67,8 @@ default void manifestDefaults(Manifest manifest, String packageName) {
5667
/// - For all configurations that
5768
/// {@linkplain org.codehaus.groovy.runtime.StringGroovyMethods#containsIgnoreCase(CharSequence, CharSequence)
5869
/// contain (ignoring case)} "runtimeElements", the
59-
/// [org.gradle.api.attributes.plugin.GradlePluginApiVersion#GRADLE_PLUGIN_API_VERSION_ATTRIBUTE] attribute with
60-
/// the value of the given Gradle version.
70+
/// [org.gradle.api.attributes.plugin.GradlePluginApiVersion#GRADLE_PLUGIN_API_VERSION_ATTRIBUTE] attribute with the
71+
/// value of the given Gradle version.
6172
///
6273
/// @param configurations The configurations container to apply defaults to
6374
/// @param gradleVersion The Gradle version to target
@@ -68,8 +79,8 @@ default void manifestDefaults(Manifest manifest, String packageName) {
6879
/// - For all configurations that
6980
/// {@linkplain org.codehaus.groovy.runtime.StringGroovyMethods#containsIgnoreCase(CharSequence, CharSequence)
7081
/// contain (ignoring case)} "runtimeElements", the
71-
/// [org.gradle.api.attributes.plugin.GradlePluginApiVersion#GRADLE_PLUGIN_API_VERSION_ATTRIBUTE] attribute with
72-
/// the value of the given Gradle version.
82+
/// [org.gradle.api.attributes.plugin.GradlePluginApiVersion#GRADLE_PLUGIN_API_VERSION_ATTRIBUTE] attribute with the
83+
/// value of the given Gradle version.
7384
///
7485
/// @param configurations The configurations container to apply defaults to
7586
/// @param gradleVersion The Gradle version to target

0 commit comments

Comments
 (0)