Merge remote-tracking branch 'FabricMC/dev/0.13' into dev/0.13.0

This commit is contained in:
shedaniel
2022-08-11 02:26:29 +08:00
4 changed files with 68 additions and 18 deletions

View File

@@ -28,6 +28,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ModuleDependency;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.LoomRepositoryPlugin;
@@ -60,6 +62,16 @@ public class MinecraftLibraryProvider {
assert provideClient || provideServer;
}
private void addDependency(String configuration, Object dependency) {
Dependency created = project.getDependencies().add(configuration, dependency);
// The launcher doesn't download transitive deps, so neither will we.
// This will also prevent a LaunchWrapper library dependency from pulling in outdated ASM jars.
if (created instanceof ModuleDependency md) {
md.setTransitive(false);
}
}
public void provide() {
if (provideClient) {
// Modern 1.19 version put the natives on the classpath.
@@ -116,17 +128,17 @@ public class MinecraftLibraryProvider {
if (runtimeOnlyLog4j && name.startsWith("org.apache.logging.log4j")) {
// Make log4j a runtime only dep to force slf4j.
project.getDependencies().add(Constants.Configurations.MINECRAFT_RUNTIME_DEPENDENCIES, name);
addDependency(Constants.Configurations.MINECRAFT_RUNTIME_DEPENDENCIES, name);
continue;
}
if (classpathArmNatives && name.startsWith("org.lwjgl:")
&& (name.endsWith("natives-windows") || name.endsWith("natives-linux"))) {
// Add windows and Linux arm64 natives for modern classpath native MC versions.
project.getDependencies().add(Constants.Configurations.MINECRAFT_DEPENDENCIES, name + "-arm64");
addDependency(Constants.Configurations.MINECRAFT_DEPENDENCIES, name + "-arm64");
}
project.getDependencies().add(Constants.Configurations.MINECRAFT_DEPENDENCIES, name);
addDependency(Constants.Configurations.MINECRAFT_DEPENDENCIES, name);
}
if (library.hasNativesForOS()) {
@@ -140,11 +152,11 @@ public class MinecraftLibraryProvider {
for (BundleMetadata.Entry library : serverBundleMetadata.libraries()) {
if (runtimeOnlyLog4j && library.name().startsWith("org.apache.logging.log4j")) {
// Make log4j a runtime only dep to force slf4j.
project.getDependencies().add(Constants.Configurations.MINECRAFT_RUNTIME_DEPENDENCIES, library.name());
addDependency(Constants.Configurations.MINECRAFT_RUNTIME_DEPENDENCIES, library.name());
continue;
}
project.getDependencies().add(Constants.Configurations.MINECRAFT_SERVER_DEPENDENCIES, library.name());
addDependency(Constants.Configurations.MINECRAFT_SERVER_DEPENDENCIES, library.name());
}
}
}
@@ -177,6 +189,6 @@ public class MinecraftLibraryProvider {
}
project.getLogger().debug("Add native dependency '{}'", dependencyNotation);
project.getDependencies().add(Constants.Configurations.MINECRAFT_NATIVES, dependencyNotation);
addDependency(Constants.Configurations.MINECRAFT_NATIVES, dependencyNotation);
}
}

View File

@@ -56,15 +56,28 @@ public abstract class AbstractRunTask extends JavaExec {
this.config = configProvider.apply(getProject());
setClasspath(config.sourceSet.getRuntimeClasspath().filter(File::exists).filter(new LibraryFilter()));
// Pass an empty classpath to the super JavaExec.
super.setClasspath(getProject().files());
args(config.programArgs);
getMainClass().set(config.mainClass);
}
private boolean canUseArgFile() {
// @-files were added for java (not javac) in Java 9, see https://bugs.openjdk.org/browse/JDK-8027634
return getJavaVersion().isJava9Compatible();
}
@Override
public void exec() {
if (canUseArgFile()) {
getProject().getLogger().debug("Using arg file for {}", getName());
// We're using an arg file, pass an empty classpath to the super JavaExec.
super.setClasspath(getProject().files());
} else {
getProject().getLogger().debug("Using bare classpath for {}", getName());
// The classpath is passed normally, so pass the full classpath to the super JavaExec.
super.setClasspath(classpath);
}
setWorkingDir(new File(getProject().getProjectDir(), config.runDir));
environment(config.environmentVariables);
@@ -85,16 +98,18 @@ public abstract class AbstractRunTask extends JavaExec {
final List<String> superArgs = super.getJvmArgs();
final List<String> args = new ArrayList<>();
final String content = "-classpath\n" + this.classpath.getFiles().stream()
.map(File::getAbsolutePath)
.collect(Collectors.joining(System.getProperty("path.separator")));
if (canUseArgFile()) {
final String content = "-classpath\n" + this.classpath.getFiles().stream()
.map(File::getAbsolutePath)
.collect(Collectors.joining(System.getProperty("path.separator")));
try {
final Path argsFile = Files.createTempFile("loom-classpath", ".args");
Files.writeString(argsFile, content, StandardCharsets.UTF_8);
args.add("@" + argsFile.toAbsolutePath());
} catch (IOException e) {
throw new UncheckedIOException("Failed to create classpath file", e);
try {
final Path argsFile = Files.createTempFile("loom-classpath", ".args");
Files.writeString(argsFile, content, StandardCharsets.UTF_8);
args.add("@" + argsFile.toAbsolutePath());
} catch (IOException e) {
throw new UncheckedIOException("Failed to create classpath file", e);
}
}
if (superArgs != null) {