Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public abstract class LegacyForgeModdingSettings {

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

private boolean obfuscateJar = true;

@Inject
public LegacyForgeModdingSettings(Project project) {
// By default, enable modding deps only for the main source set
Expand Down Expand Up @@ -64,11 +66,6 @@ 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.
Expand All @@ -80,4 +77,15 @@ public Set<SourceSet> getEnabledSourceSets() {
public void setEnabledSourceSets(Set<SourceSet> enabledSourceSets) {
this.enabledSourceSets = enabledSourceSets;
}

/**
* {@return true if default reobfuscation task should be created}
*/
public boolean isObfuscateJar() {
return obfuscateJar;
}

public void setObfuscateJar(boolean obfuscateJar) {
this.obfuscateJar = obfuscateJar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,13 @@ public void enable(Project project, LegacyForgeModdingSettings settings, LegacyF
run.getProgramArguments().addAll(mixin.getConfigs().map(cfgs -> cfgs.stream().flatMap(config -> Stream.of("--mixin.config", config)).toList()));
});

var reobfJar = obf.reobfuscate(
project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class),
project.getExtensions().getByType(SourceSetContainer.class).getByName(SourceSet.MAIN_SOURCE_SET_NAME));
if (settings.isObfuscateJar()) {
var reobfJar = obf.reobfuscate(
project.getTasks().named(JavaPlugin.JAR_TASK_NAME, Jar.class),
project.getExtensions().getByType(SourceSetContainer.class).getByName(SourceSet.MAIN_SOURCE_SET_NAME));

project.getTasks().named("assemble", assemble -> assemble.dependsOn(reobfJar));
project.getTasks().named("assemble", assemble -> assemble.dependsOn(reobfJar));
}

// Forge expects the mapping csv files on the root classpath
artifacts.runtimeDependencies()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Set;
Expand Down Expand Up @@ -113,6 +114,16 @@ void testAddModdingDependenciesTo() {
assertContainsModdingRuntimeDependencies(testSourceSet.getRuntimeClasspathConfigurationName());
}

@Test
void testEnableWithoutReobfTask() {
extension.enable(settings -> {
settings.setForgeVersion(VERSION);
settings.setObfuscateJar(false);
});

assertNull(project.getTasks().findByName("reobfJar"));
}

private void assertDoesNotContainModdingDependencies(String configurationName) {
assertThatDependencies(configurationName).doesNotContain(MODDING_COMPILE_DEPENDENCIES);
assertThatDependencies(configurationName).doesNotContain(MODDING_RUNTIME_ONLY_DEPENDENCIES);
Expand Down
Loading