Skip to content

Commit

Permalink
Do not use internals
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Dec 25, 2024
1 parent 35dd971 commit c9f6ca2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
25 changes: 13 additions & 12 deletions buildSrc/src/main/java/net/neoforged/neodev/NeoDevPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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 All @@ -38,6 +37,7 @@
import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -455,19 +455,20 @@ public void apply(Project project) {
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 + "/");
var projectRepos = project.getRepositories();
if (!projectRepos.isEmpty()) {
for (var repo : projectRepos.withType(MavenArtifactRepository.class)) {
repos.add(repo.getUrl());
}
repos.add(uri);
} else {
// If no project repos are defined, use the repository list we exposed in settings.gradle via an extension
// See the end of settings.gradle for details
Collections.addAll(repos, (URI[]) project.getGradle().getExtensions().getByName("repositoryBaseUrls"));
}

// Ensure all base urls end with a slash
repos.replaceAll(uri -> uri.toString().endsWith("/") ? uri : URI.create(uri + "/"));

return repos;
});
}
Expand Down
5 changes: 5 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ include ':coremods'
// Ensure a unique artifact id within JIJ that does not conflict with net.neoforged:coremods, which is
// another external dependency.
project(":coremods").name = "neoforge-coremods"

// Expose the repository base URLs to projects to be able to access them
// See this Gradle issue for tracking a more permanent solution:
// https://github.com/gradle/gradle/issues/27260
gradle.extensions.add("repositoryBaseUrls", dependencyResolutionManagement.repositories.findAll { it instanceof MavenArtifactRepository }.collect { it.url }.toArray(URI[]::new))

0 comments on commit c9f6ca2

Please sign in to comment.