Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imperative Configuration V2 #200

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ please refer to the changelog, which can be found on the [project page](https://
The breaking changes in this major version should not affect most projects.
Nonetheless, every single breaking change is documented here, along with a suggested fix.

- Modding now needs to be enabled before dependencies are made available, and the NeoForge/NeoForm versions will
be fixed at the point in time when modding is enabled. Setting `neoForge.version` or `neoForge.neoFormVersion` will
enable modding when those properties are set. For more advanced use cases, the `neoForge.enable { ... }` block can
be used, i.e. to not enable modding for the `main` source set. You can only enable modding once for one version
of NeoForge/NeoForm per project.
- Changes to access transformer and interface injection data publishing.
- `accessTransformers.publish` and `interfaceInjectionData.publish` syntax was changed.
- `accessTransformers.published` and `interfaceInjectionData.published` were removed.
Expand Down
26 changes: 19 additions & 7 deletions LEGACY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ plugins {
id 'net.neoforged.moddev.legacyforge' version '2.0.28-beta'
}

neoForge {
legacyForge {
// Develop against MinecraftForge version 47.3.0 for 1.20.1 (the versions can be found at https://files.minecraftforge.net/)
version = "1.20.1-47.3.0"
forgeVersion = "1.20.1-47.3.0"

// Validate AT files and raise errors when they have invalid targets
// This option is false by default, but turning it on is recommended
Expand Down Expand Up @@ -91,6 +91,18 @@ obfuscation {
}
```

## Vanilla Mode

You can get dependencies for Vanilla Minecraft added to your project by using the `mcpVersion` property instead of
setting the `forgeVersion` property.

```groovy
legacyForge {
// This adds Minecraft 1.20.1 as a dependency to the main source set.
mcpVersion = "1.20.1"
}
```

## Mixins

You need to create so-called "refmaps" for Mixin, which convert the names you used to declare injection points and reference other parts of Minecraft code to the names used at runtime (SRG).
Expand Down Expand Up @@ -126,10 +138,10 @@ jar {
}
```

## Effects of applying the legacy plugin
When applied, the legacy plugin will change the base NeoForm and NeoForge artifact coordinates of the `neoForge` extension to
`de.oceanlabs.mcp:mcp_config` and `net.minecraftforge:forge`.
It will also trigger the creation of various intermediary (SRG) to named (official) mapping files used by various parts of the toolchain, such as
mod reobfuscation and runtime naming services.
## Effects of enabling legacy forge modding

Enabling modding in the legacyForge extension triggers the creation of various intermediary (SRG) to named (official) mapping files used by various parts of the toolchain, such as
mod reobfuscation and runtime naming services.

Reobfuscation to the intermediary mappings will automatically be configured for the `jar` task, the non-obfuscated jar will have a `-dev` classifier
and will not be published in favour of the reobfuscated variant.
4 changes: 2 additions & 2 deletions legacytest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ java {
}
}

neoForge {
neoFormVersion = '1.19.2'
legacyForge {
mcpVersion = '1.19.2'
}

publishing {
Expand Down
4 changes: 2 additions & 2 deletions legacytest/forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ dependencies {
modImplementation('curse.maven:applied-energistics-2-223794:5641282')
}

neoForge {
version = '1.20.1-47.3.0'
legacyForge {
version = '1.20.1-47.3.12'
runs {
client {
client()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.neoforged.moddevgradle.legacyforge.dsl;

import net.neoforged.moddevgradle.dsl.DataFileCollection;
import net.neoforged.moddevgradle.dsl.ModDevExtension;
import net.neoforged.moddevgradle.legacyforge.internal.LegacyForgeModDevPlugin;
import org.gradle.api.Action;
import org.gradle.api.Project;

import javax.inject.Inject;

/**
* This is the top-level {@code legacyForge} extension, used to configure the moddev plugin.
*/
public abstract class LegacyForgeExtension extends ModDevExtension {
private final Project project;

@Inject
public LegacyForgeExtension(Project project,
DataFileCollection accessTransformers,
DataFileCollection interfaceInjectionData) {
super(project, accessTransformers, interfaceInjectionData);
this.project = project;
}

/**
* Enables modding for the main source-set using the given Forge version.
* <p>
* Shorthand for:
* <code>
* enable { forgeVersion = '...' }
* </code>
*/
public void setVersion(String version) {
enable(settings -> {
settings.setForgeVersion(version);
});
}

/**
* Enables modding for the main source-set in Vanilla-mode.
* <p>
* Shorthand for:
* <code>
* enable { mcpVersion = '...' }
* </code>
*/
public void setMcpVersion(String version) {
enable(settings -> {
settings.setMcpVersion(version);
});
}

public void enable(Action<LegacyForgeModdingSettings> customizer) {
var plugin = project.getPlugins().getPlugin(LegacyForgeModDevPlugin.class);

var settings = project.getObjects().newInstance(LegacyForgeModdingSettings.class);
customizer.execute(settings);

plugin.enable(project, settings, this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package net.neoforged.moddevgradle.legacyforge.dsl;

import net.neoforged.moddevgradle.internal.utils.ExtensionUtils;
import org.gradle.api.Project;
import org.gradle.api.tasks.SourceSet;
import org.jetbrains.annotations.Nullable;

import javax.inject.Inject;
import java.util.HashSet;
import java.util.Set;

public abstract class LegacyForgeModdingSettings {
@Nullable
private String neoForgeVersion;

@Nullable
private String forgeVersion;
shartte marked this conversation as resolved.
Show resolved Hide resolved

@Nullable
private String mcpVersion;

private Set<SourceSet> enabledSourceSets = new HashSet<>();

@Inject
public LegacyForgeModdingSettings(Project project) {
// By default, enable modding deps only for the main source set
var sourceSets = ExtensionUtils.getSourceSets(project);
var mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
enabledSourceSets.add(mainSourceSet);
}

public @Nullable String getNeoForgeVersion() {
return neoForgeVersion;
}

public @Nullable String getForgeVersion() {
return forgeVersion;
}

public @Nullable String getMcpVersion() {
return mcpVersion;
}

/**
* NeoForge version number. You have to set either this, {@link #setForgeVersion} or {@link #setMcpVersion}.
* Only NeoForge for Minecraft 1.20.1 is supported when using this plugin.
*/
public void setNeoForgeVersion(String version) {
this.neoForgeVersion = version;
}

/**
* Minecraft Forge version. You have to set either this, {@link #setNeoForgeVersion} or {@link #setMcpVersion}.
*/
public void setForgeVersion(String version) {
this.forgeVersion = version;
}

/**
* You can set this property to a version of <a href="https://maven.neoforged.net/#/releases/de/oceanlabs/mcp/mcp">MCP</a>
* to either override the version used in the version of Forge you set, or to compile against
* Vanilla artifacts that have no Forge code added.
*/
public void setMcpVersion(String version) {
this.mcpVersion = version;
}

/**
* Contains the list of source sets for which access to Minecraft classes should be configured.
* Defaults to the main source set, but can also be set to an empty list.
*/

/**
* Contains the list of source sets for which access to Minecraft classes should be configured.
* Defaults to the main source set, but can also be set to an empty list.
*/
public Set<SourceSet> getEnabledSourceSets() {
return enabledSourceSets;
}

public void setEnabledSourceSets(Set<SourceSet> enabledSourceSets) {
this.enabledSourceSets = enabledSourceSets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import net.neoforged.moddevgradle.legacyforge.tasks.RemapOperation;
import org.apache.commons.lang3.StringUtils;
import org.gradle.api.Action;
import org.gradle.api.InvalidUserCodeException;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.gradle.api.artifacts.FileCollectionDependency;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.component.AdhocComponentWithVariants;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet;
Expand All @@ -23,41 +24,53 @@
import javax.inject.Inject;
import java.util.List;

public abstract class Obfuscation {
public abstract class ObfuscationExtension {
private final Project project;
private final Provider<RegularFile> officialToSrg;
private final Provider<RegularFile> mappingsCsv;
private final Configuration autoRenamingToolRuntime;
private final Configuration installerToolsRuntime;
private final FileCollection extraMixinMappings;

@Inject
public Obfuscation(Project project,
Provider<RegularFile> officialToSrg,
Provider<RegularFile> mappingsCsv,
Configuration autoRenamingToolRuntime,
Configuration installerToolsRuntime,
FileCollection extraMixinMappings) {
public ObfuscationExtension(Project project,
Configuration autoRenamingToolRuntime,
Configuration installerToolsRuntime,
FileCollection extraMixinMappings) {
this.project = project;
this.officialToSrg = officialToSrg;
this.mappingsCsv = mappingsCsv;
this.autoRenamingToolRuntime = autoRenamingToolRuntime;
this.installerToolsRuntime = installerToolsRuntime;
this.extraMixinMappings = extraMixinMappings;
}

private <T> Provider<T> assertConfigured(Provider<T> provider) {
return provider.orElse(project.provider(() -> {
throw new InvalidUserCodeException("Please enable modding by setting legacyForge.version or calling legacyForge.enable()");
}));
}

/**
* Format is TSRG.
*/
@ApiStatus.Internal
public abstract RegularFileProperty getNamedToSrgMappings();

/**
* Format is a ZIP file containing CSV files with mapping data.
*/
@ApiStatus.Internal
public abstract RegularFileProperty getSrgToNamedMappings();

@ApiStatus.Internal
public void configureNamedToSrgOperation(RemapOperation operation) {
operation.getToolType().set(RemapOperation.ToolType.ART);
operation.getToolClasspath().from(autoRenamingToolRuntime);
operation.getMappings().from(officialToSrg);
operation.getMappings().from(assertConfigured(getNamedToSrgMappings()));
}

@ApiStatus.Internal
public void configureSrgToNamedOperation(RemapOperation operation) {
operation.getToolType().set(RemapOperation.ToolType.INSTALLER_TOOLS);
operation.getToolClasspath().from(installerToolsRuntime);
operation.getMappings().from(mappingsCsv);
operation.getMappings().from(assertConfigured(getSrgToNamedMappings()));
}

/**
Expand All @@ -68,7 +81,8 @@ public void configureSrgToNamedOperation(RemapOperation operation) {
* @return a provider of the created task
*/
public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchiveTask> jar, SourceSet sourceSet) {
return reobfuscate(jar, sourceSet, ignored -> {});
return reobfuscate(jar, sourceSet, ignored -> {
});
}

/**
Expand All @@ -82,7 +96,6 @@ public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchive
public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchiveTask> jar,
SourceSet sourceSet,
Action<RemapJar> configuration) {

var reobf = project.getTasks().register("reobf" + StringUtils.capitalize(jar.getName()), RemapJar.class, task -> {
task.getInput().set(jar.flatMap(AbstractArchiveTask::getArchiveFile));
task.getDestinationDirectory().convention(task.getProject().getLayout().getBuildDirectory().dir("libs"));
Expand Down
Loading
Loading