Skip to content

Commit

Permalink
Fix the ability of the build script to use PR builds in installers
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Dec 25, 2024
1 parent 2002c21 commit 0e2745d
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.file.Directory;
import org.gradle.api.file.RegularFile;
import org.gradle.api.internal.GradleInternal;
import org.gradle.api.plugins.BasePluginExtension;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
Expand Down Expand Up @@ -271,6 +272,7 @@ public void apply(Project project) {
genProductionPatches.flatMap(GenerateSourcePatches::getPatchesFolder)
);

var installerRepositoryUrls = getInstallerRepositoryUrls(project);
// Launcher profile = the version.json file used by the Minecraft launcher.
var createLauncherProfile = tasks.register("createLauncherProfile", CreateLauncherProfile.class, task -> {
task.setGroup(INTERNAL_GROUP);
Expand All @@ -279,17 +281,7 @@ public void apply(Project project) {
task.getNeoForgeVersion().set(neoForgeVersion);
task.getRawNeoFormVersion().set(rawNeoFormVersion);
task.setLibraries(configurations.launcherProfileClasspath);
task.getRepositoryURLs().set(project.provider(() -> {
List<URI> repos = new ArrayList<>();
for (var repo : project.getRepositories().withType(MavenArtifactRepository.class)) {
var uri = repo.getUrl();
if (!uri.toString().endsWith("/")) {
uri = URI.create(uri + "/");
}
repos.add(uri);
}
return repos;
}));
task.getRepositoryURLs().set(installerRepositoryUrls);
// ${version_name}.jar will be filled out by the launcher. It corresponds to the raw SRG Minecraft client jar.
task.getIgnoreList().addAll("client-extra", "${version_name}.jar");
task.setModules(configurations.modulePath);
Expand All @@ -308,17 +300,7 @@ public void apply(Project project) {
task.addLibraries(configurations.launcherProfileClasspath);
// We need the NeoForm zip for the SRG mappings.
task.addLibraries(configurations.neoFormDataOnly);
task.getRepositoryURLs().set(project.provider(() -> {
List<URI> repos = new ArrayList<>();
for (var repo : project.getRepositories().withType(MavenArtifactRepository.class)) {
var uri = repo.getUrl();
if (!uri.toString().endsWith("/")) {
uri = URI.create(uri + "/");
}
repos.add(uri);
}
return repos;
}));
task.getRepositoryURLs().set(installerRepositoryUrls);
task.getUniversalJar().set(universalJar.flatMap(AbstractArchiveTask::getArchiveFile));
task.getInstallerProfile().set(neoDevBuildDir.map(dir -> dir.file("installer-profile.json")));

Expand Down Expand Up @@ -467,6 +449,29 @@ public void apply(Project project) {
setupProductionServerTest(project, installerJar);
}

/**
* Get the list of Maven repositories that may contain artifacts for the installer.
*/
private static Provider<List<URI>> getInstallerRepositoryUrls(Project project) {
return project.provider(() -> {
List<URI> repos = new ArrayList<>();
var repositories = project.getRepositories();
if (repositories.isEmpty()) {
// If no project repos are defined, check dependency management on the settings plugin,
// which sadly is inaccessible without internals: https://github.com/gradle/gradle/issues/27260
repositories = ((GradleInternal) project.getGradle()).getSettings().getDependencyResolutionManagement().getRepositories();
}
for (var repo : repositories.withType(MavenArtifactRepository.class)) {
var uri = repo.getUrl();
if (!uri.toString().endsWith("/")) {
uri = URI.create(uri + "/");
}
repos.add(uri);
}
return repos;
});
}

private static TaskProvider<TransformSources> configureAccessTransformer(
Project project,
TaskProvider<CreateMinecraftArtifacts> createSourceArtifacts,
Expand Down

0 comments on commit 0e2745d

Please sign in to comment.