Skip to content

Commit 42d0d8f

Browse files
authored
Remove dependence on at-gradle among other things (#1022)
- Remove top-level `WithAccessTransformers` subtypes - Generalize implementation of the plugin entry - This will likely be a class generated by ASM in a future Gradle plugin that allows us to re-use this for all of our Gradle plugins. - Move Attributes to ForgeGradleExtension - Declare extensions' public type on creation, not via interface - Bake in support for multiple AT configs
1 parent e571bb5 commit 42d0d8f

28 files changed

+383
-664
lines changed

build.gradle

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ dependencies {
6060
// GradleUtils Shared Base
6161
implementation libs.gradleutils.shared
6262

63-
// AccessTransformers
64-
compileOnlyApi libs.accesstransformers.gradle
65-
6663
// Utils
6764
implementation libs.maven.artifact
6865
implementation libs.bundles.utils
@@ -100,8 +97,8 @@ tasks.named('shadowJar', ShadowJar) {
10097
}
10198
}
10299

103-
tasks.withType(Javadoc).configureEach {
104-
javadocTool = javaToolchains.javadocToolFor { languageVersion = JavaLanguageVersion.of(24) }
100+
tasks.named('javadoc', Javadoc) {
101+
javadocTool = javaToolchains.javadocToolFor { languageVersion = JavaLanguageVersion.of(25) }
105102
}
106103

107104
changelog {

runtime-environment-check/src/main/java/net/minecraftforge/gradle/internal/ForgeGradlePluginEntry.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ abstract class ForgeGradlePluginEntry implements Plugin<PluginAware> {
2121
private static final GradleVersion CURRENT_GRADLE = GradleVersion.current();
2222
private static final GradleVersion MINIMUM_GRADLE = GradleVersion.version("9.3.0-rc-1");
2323

24+
private static final String PLUGIN_DISPLAY_NAME = "ForgeGradle";
25+
private static final String PLUGIN_VERSION = "7";
26+
private static final String PLUGIN_CLASS = "net.minecraftforge.gradle.internal.ForgeGradlePlugin";
27+
2428
@Inject
2529
public ForgeGradlePluginEntry() { }
2630

2731
@Override
2832
public void apply(PluginAware target) {
2933
if (CURRENT_GRADLE.compareTo(MINIMUM_GRADLE) < 0) {
3034
String message = String.format(
31-
"ForgeGradle 7 requires %s or later to run. You are currently using %s.",
35+
"%s %s requires %s or later to run. You are currently using %s.",
36+
PLUGIN_DISPLAY_NAME,
37+
PLUGIN_VERSION,
3238
MINIMUM_GRADLE,
3339
CURRENT_GRADLE
3440
);
@@ -37,9 +43,9 @@ public void apply(PluginAware target) {
3743
}
3844

3945
try {
40-
target.getPluginManager().apply(Class.forName("net.minecraftforge.gradle.internal.ForgeGradlePlugin"));
46+
target.getPluginManager().apply(Class.forName(PLUGIN_CLASS));
4147
} catch (ClassNotFoundException e) {
42-
throw new RuntimeException("Failed to find the ForgeGradle entry-point.", e);
48+
throw new RuntimeException(String.format("Failed to find the %s entry-point.", PLUGIN_DISPLAY_NAME), e);
4349
}
4450
}
4551
}

settings.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ gradle.beforeProject { Project project ->
2424

2525
//@formatter:off
2626
dependencyResolutionManagement.versionCatalogs.register('libs') {
27-
version 'gradleutils', '3.3.40'
27+
version 'gradleutils', '3.3.42'
2828

2929
plugin 'licenser', 'net.minecraftforge.licenser' version '1.2.0' // https://plugins.gradle.org/plugin/net.minecraftforge.licenser
3030
plugin 'gradleutils', 'net.minecraftforge.gradleutils' versionRef 'gradleutils'
@@ -45,10 +45,6 @@ dependencyResolutionManagement.versionCatalogs.register('libs') {
4545
// GradleUtils Shared Base
4646
library 'gradleutils-shared', 'net.minecraftforge', 'gradleutils-shared' versionRef 'gradleutils'
4747

48-
// AccessTransformers Gradle Plugin
49-
// https://plugins.gradle.org/plugin/net.minecraftforge.accesstransformers
50-
library 'accesstransformers-gradle', 'net.minecraftforge.accesstransformers', 'net.minecraftforge.accesstransformers.gradle.plugin' version '5.0.1'
51-
5248
// Artifact Versioning
5349
library 'maven-artifact', 'org.apache.maven', 'maven-artifact' version '3.9.11'
5450

src/main/java/net/minecraftforge/gradle/ClosureOwner.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,4 @@ public interface ClosureOwner {
1818
///
1919
/// @see ClosureOwner
2020
interface MinecraftDependency extends ClosureOwner, net.minecraftforge.gradle.MinecraftDependency, ExternalModuleDependency { }
21-
22-
/// A closure owner that delegates to [net.minecraftforge.gradle.MinecraftDependencyWithAccessTransformers] and
23-
/// [ExternalModuleDependency].
24-
///
25-
/// @see ClosureOwner
26-
interface MinecraftDependencyWithAccessTransformers extends ClosureOwner, net.minecraftforge.gradle.MinecraftDependencyWithAccessTransformers, ExternalModuleDependency { }
2721
}

src/main/java/net/minecraftforge/gradle/ForgeGradleExtension.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import groovy.lang.Closure;
88
import org.gradle.api.Action;
99
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
10+
import org.gradle.api.attributes.Attribute;
1011

1112
/// The ForgeGradle extension contains a handful of helpers that are not directly related to development involving
1213
/// Minecraft.
@@ -44,4 +45,48 @@ public interface ForgeGradleExtension {
4445
* @return The closure
4546
*/
4647
Action<MavenArtifactRepository> getMinecraftLibsMaven();
48+
49+
/**
50+
* The attributes object for easy reference.
51+
* <pre><code>
52+
* dependencies {
53+
* implementation 'com.example:example:1.0' {
54+
* attributes.attribute(fg.attributes.os, 'windows')
55+
* }
56+
* }
57+
* </code></pre>
58+
*
59+
* @return The attributes object
60+
* @see Attributes
61+
*/
62+
Attributes getAttributes();
63+
64+
/// This interface contains the attributes used by the [Minecraft][MinecraftExtension] extension for resolving the
65+
/// Minecraft and deobfuscated dependencies.
66+
///
67+
/// @see ForgeGradleExtension#getAttributes()
68+
interface Attributes {
69+
/// The operating system of the project's host.
70+
///
71+
/// This is used to filter natives from the Minecraft repo.
72+
///
73+
/// @return The operating system attribute
74+
Attribute<String> getOs();
75+
76+
/// The requested mappings channel of the project.
77+
///
78+
/// This is determined using [MinecraftMappings#getChannel()] via [MinecraftMappingsContainer#getMappings()]
79+
///
80+
/// @return The mappings channel attribute
81+
/// @see #getMappingsVersion()
82+
Attribute<String> getMappingsChannel();
83+
84+
/// The requested mappings version of the project.
85+
///
86+
/// This is determined using [MinecraftMappings#getVersion()] via [MinecraftMappingsContainer#getMappings()]
87+
///
88+
/// @return The mappings channel version
89+
/// @see #getMappingsChannel()
90+
Attribute<String> getMappingsVersion();
91+
}
4792
}

src/main/java/net/minecraftforge/gradle/MinecraftDependencyWithAccessTransformers.java renamed to src/main/java/net/minecraftforge/gradle/MinecraftAccessTransformersContainer.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44
*/
55
package net.minecraftforge.gradle;
66

7+
import org.gradle.api.file.ConfigurableFileCollection;
78
import org.gradle.api.file.RegularFileProperty;
89

9-
/// An extension of [MinecraftDependency] that contains additional convenience methods for working with
10-
/// AccessTransformers.
11-
///
12-
/// @see MinecraftDependency
13-
public interface MinecraftDependencyWithAccessTransformers extends MinecraftDependency {
10+
public interface MinecraftAccessTransformersContainer {
1411
/// The default path, from the source set's [resources][org.gradle.api.tasks.SourceSet#getResources()], for the
1512
/// AccessTransformers config to be located in.
1613
String DEFAULT_PATH = "META-INF/accesstransformer.cfg";
1714

1815
/// Gets the AccessTransformer configuration to use.
1916
///
2017
/// @return The property for the configuration file to use
21-
RegularFileProperty getAccessTransformer();
18+
ConfigurableFileCollection getAccessTransformer();
2219

2320
/// Sets the path, relative to this dependency's [org.gradle.api.tasks.SourceSet#getResources()], to the
2421
/// AccessTransformers config file to use.
@@ -35,8 +32,7 @@ public interface MinecraftDependencyWithAccessTransformers extends MinecraftDepe
3532
/// file is in a strict location.
3633
void setAccessTransformer(String accessTransformer);
3734

38-
/// Sets if this dependency should use AccessTransformers. The default value depends on the state of
39-
/// [MinecraftExtensionForProjectWithAccessTransformers#getAccessTransformers()].
35+
/// Sets if this dependency should use AccessTransformers.
4036
///
4137
/// If `true`, this calls [#setAccessTransformer(String)] using [#DEFAULT_PATH] as the path. If `false`, this will
4238
/// force this dependency to *not use* AccessTransformers, even if the convention is set to do so from the Minecraft

src/main/java/net/minecraftforge/gradle/MinecraftDependency.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/// The Minecraft dependency contains information essential for how the
1616
/// {@linkplain MinecraftExtensionForProject minecraft extension} processes Minecraft dependencies.
17-
public interface MinecraftDependency extends MinecraftMappingsContainer {
17+
public interface MinecraftDependency extends MinecraftMappingsContainer, MinecraftAccessTransformersContainer {
1818
/// The collection of Slime Launcher options with which to create the launcher tasks.
1919
///
2020
/// @return The collection of run task options

src/main/java/net/minecraftforge/gradle/MinecraftExtension.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.gradle.api.Action;
99
import org.gradle.api.artifacts.dsl.RepositoryHandler;
1010
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
11-
import org.gradle.api.attributes.Attribute;
1211

1312
/// The main extension for ForgeGradle, where the Minecraft dependency resolution takes place.
1413
///
@@ -56,48 +55,4 @@ default MavenArtifactRepository mavenizer(RepositoryHandler repositories) {
5655
repositories.addFirst(mavenizer);
5756
return mavenizer;
5857
}
59-
60-
/**
61-
* The attributes object for easy reference.
62-
* <pre><code>
63-
* dependencies {
64-
* implementation 'com.example:example:1.0' {
65-
* attributes.attribute(minecraft.attributes.os, 'windows')
66-
* }
67-
* }
68-
* </code></pre>
69-
*
70-
* @return The attributes object
71-
* @see Attributes
72-
*/
73-
Attributes getAttributes();
74-
75-
/// This interface contains the attributes used by the [Minecraft][MinecraftExtension] extension for resolving the
76-
/// Minecraft and deobfuscated dependencies.
77-
///
78-
/// @see MinecraftExtension#getAttributes()
79-
interface Attributes {
80-
/// The operating system of the project's host.
81-
///
82-
/// This is used to filter natives from the Minecraft repo.
83-
///
84-
/// @return The operating system attribute
85-
Attribute<String> getOs();
86-
87-
/// The requested mappings channel of the project.
88-
///
89-
/// This is determined using [MinecraftMappings#getChannel()] via [#getMappings()]
90-
///
91-
/// @return The mappings channel attribute
92-
/// @see #getMappingsVersion()
93-
Attribute<String> getMappingsChannel();
94-
95-
/// The requested mappings version of the project.
96-
///
97-
/// This is determined using [MinecraftMappings#getVersion()] via [#getMappings()]
98-
///
99-
/// @return The mappings channel version
100-
/// @see #getMappingsChannel()
101-
Attribute<String> getMappingsVersion();
102-
}
10358
}

src/main/java/net/minecraftforge/gradle/MinecraftExtensionForProject.java

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import groovy.lang.DelegatesTo;
99
import groovy.transform.stc.ClosureParams;
1010
import groovy.transform.stc.FromString;
11+
import groovy.transform.stc.SimpleType;
1112
import net.minecraftforge.gradleutils.shared.Closures;
1213
import org.gradle.api.Action;
1314
import org.gradle.api.NamedDomainObjectContainer;
@@ -16,32 +17,8 @@
1617
/// [Project][org.gradle.api.Project]-specific additions for the Minecraft extension. These will be accessible from the
1718
/// `minecraft` DSL object within your project's buildscript.
1819
///
19-
/// @param <T> The type of closure owner used for [#dependency]
2020
/// @see MinecraftExtension
21-
public interface MinecraftExtensionForProject<T extends ClosureOwner> extends MinecraftExtension {
22-
/// The collection of Slime Launcher options with which to create the launcher tasks.
23-
///
24-
/// @return The collection of run task options
25-
NamedDomainObjectContainer<? extends SlimeLauncherOptions> getRuns();
26-
27-
/// Configures the Slime Launcher options for this project, which will be used to create the launcher tasks.
28-
///
29-
/// @param closure The configuring closure
30-
default void runs(
31-
@DelegatesTo(NamedDomainObjectContainer.class)
32-
@ClosureParams(value = FromString.class, options = "org.gradle.api.NamedDomainObjectContainer<net.minecraftforge.gradle.SlimeLauncherOptions>")
33-
Closure<?> closure
34-
) {
35-
this.getRuns().configure(closure);
36-
}
37-
38-
/// Configures the Slime Launcher options for this project, which will be used to create the launcher tasks.
39-
///
40-
/// @param action The configuring action
41-
default void runs(Action<? super NamedDomainObjectContainer<? extends SlimeLauncherOptions>> action) {
42-
this.runs(Closures.action(this, action));
43-
}
44-
21+
public interface MinecraftExtensionForProject extends MinecraftExtension, MinecraftDependency {
4522
/// Creates (or marks if existing) the given dependency as a Minecraft dependency and configures it with the given
4623
/// closure.
4724
///
@@ -53,7 +30,7 @@ default void runs(Action<? super NamedDomainObjectContainer<? extends SlimeLaunc
5330
ExternalModuleDependency dependency(
5431
Object value,
5532
@DelegatesTo(ExternalModuleDependency.class)
56-
@ClosureParams(value = FromString.class, options = "T")
33+
@ClosureParams(value = SimpleType.class, options = "net.minecraftforge.gradle.ClosureOwner.MinecraftDependency")
5734
Closure<?> closure
5835
);
5936

@@ -65,7 +42,7 @@ ExternalModuleDependency dependency(
6542
/// @return The dependency
6643
/// @see <a href="https://docs.gradle.org/current/userguide/declaring_dependencies.html">Declaring Dependencies
6744
/// in Gradle</a>
68-
default ExternalModuleDependency dependency(Object value, Action<? super T> action) {
45+
default ExternalModuleDependency dependency(Object value, Action<? super ClosureOwner.MinecraftDependency> action) {
6946
return this.dependency(value, Closures.action(this, action));
7047
}
7148

src/main/java/net/minecraftforge/gradle/MinecraftExtensionForProjectWithAccessTransformers.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)