37
37
import java .io .File ;
38
38
import java .net .URI ;
39
39
import java .util .ArrayList ;
40
+ import java .util .Collections ;
40
41
import java .util .List ;
41
42
import java .util .Map ;
42
43
import java .util .function .Consumer ;
@@ -271,6 +272,7 @@ public void apply(Project project) {
271
272
genProductionPatches .flatMap (GenerateSourcePatches ::getPatchesFolder )
272
273
);
273
274
275
+ var installerRepositoryUrls = getInstallerRepositoryUrls (project );
274
276
// Launcher profile = the version.json file used by the Minecraft launcher.
275
277
var createLauncherProfile = tasks .register ("createLauncherProfile" , CreateLauncherProfile .class , task -> {
276
278
task .setGroup (INTERNAL_GROUP );
@@ -279,17 +281,7 @@ public void apply(Project project) {
279
281
task .getNeoForgeVersion ().set (neoForgeVersion );
280
282
task .getRawNeoFormVersion ().set (rawNeoFormVersion );
281
283
task .setLibraries (configurations .launcherProfileClasspath );
282
- task .getRepositoryURLs ().set (project .provider (() -> {
283
- List <URI > repos = new ArrayList <>();
284
- for (var repo : project .getRepositories ().withType (MavenArtifactRepository .class )) {
285
- var uri = repo .getUrl ();
286
- if (!uri .toString ().endsWith ("/" )) {
287
- uri = URI .create (uri + "/" );
288
- }
289
- repos .add (uri );
290
- }
291
- return repos ;
292
- }));
284
+ task .getRepositoryURLs ().set (installerRepositoryUrls );
293
285
// ${version_name}.jar will be filled out by the launcher. It corresponds to the raw SRG Minecraft client jar.
294
286
task .getIgnoreList ().addAll ("client-extra" , "${version_name}.jar" );
295
287
task .setModules (configurations .modulePath );
@@ -308,17 +300,7 @@ public void apply(Project project) {
308
300
task .addLibraries (configurations .launcherProfileClasspath );
309
301
// We need the NeoForm zip for the SRG mappings.
310
302
task .addLibraries (configurations .neoFormDataOnly );
311
- task .getRepositoryURLs ().set (project .provider (() -> {
312
- List <URI > repos = new ArrayList <>();
313
- for (var repo : project .getRepositories ().withType (MavenArtifactRepository .class )) {
314
- var uri = repo .getUrl ();
315
- if (!uri .toString ().endsWith ("/" )) {
316
- uri = URI .create (uri + "/" );
317
- }
318
- repos .add (uri );
319
- }
320
- return repos ;
321
- }));
303
+ task .getRepositoryURLs ().set (installerRepositoryUrls );
322
304
task .getUniversalJar ().set (universalJar .flatMap (AbstractArchiveTask ::getArchiveFile ));
323
305
task .getInstallerProfile ().set (neoDevBuildDir .map (dir -> dir .file ("installer-profile.json" )));
324
306
@@ -467,6 +449,30 @@ public void apply(Project project) {
467
449
setupProductionServerTest (project , installerJar );
468
450
}
469
451
452
+ /**
453
+ * Get the list of Maven repositories that may contain artifacts for the installer.
454
+ */
455
+ private static Provider <List <URI >> getInstallerRepositoryUrls (Project project ) {
456
+ return project .provider (() -> {
457
+ List <URI > repos = new ArrayList <>();
458
+ var projectRepos = project .getRepositories ();
459
+ if (!projectRepos .isEmpty ()) {
460
+ for (var repo : projectRepos .withType (MavenArtifactRepository .class )) {
461
+ repos .add (repo .getUrl ());
462
+ }
463
+ } else {
464
+ // If no project repos are defined, use the repository list we exposed in settings.gradle via an extension
465
+ // See the end of settings.gradle for details
466
+ Collections .addAll (repos , (URI []) project .getGradle ().getExtensions ().getByName ("repositoryBaseUrls" ));
467
+ }
468
+
469
+ // Ensure all base urls end with a slash
470
+ repos .replaceAll (uri -> uri .toString ().endsWith ("/" ) ? uri : URI .create (uri + "/" ));
471
+
472
+ return repos ;
473
+ });
474
+ }
475
+
470
476
private static TaskProvider <TransformSources > configureAccessTransformer (
471
477
Project project ,
472
478
TaskProvider <CreateMinecraftArtifacts > createSourceArtifacts ,
0 commit comments