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 @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gradle.api.InvalidUserCodeException;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
Expand All @@ -20,8 +21,16 @@ private void configureProject(Project project) {
// Inject Maven Central/local so the indexer (and plugins like protobuf that
// resolve their own artifacts) can resolve dependencies even when the build
// being indexed doesn't declare any repositories of its own.
project.getRepositories().add(project.getRepositories().mavenCentral());
project.getRepositories().add(project.getRepositories().mavenLocal());
try {
project.getRepositories().add(project.getRepositories().mavenCentral());
project.getRepositories().add(project.getRepositories().mavenLocal());
} catch (InvalidUserCodeException exc) {
// FAIL_ON_PROJECT_REPOS forbids project repositories; they are declared
// in settings instead, so the injection isn't needed (issue #847).
project
.getLogger()
.info("scip-java: not injecting Maven Central/local repositories: " + exc.getMessage());
}

Map<String, Object> extraProperties =
project.getExtensions().getExtraProperties().getProperties();
Expand Down
6 changes: 6 additions & 0 deletions scip-java/src/test/kotlin/tests/GradleBuildToolTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class GradleBuildToolTest : BuildToolHarness() {
)
)
add(checkGradleBuild("basic", "gradle/basic", expectedScipFiles = 2))
// Regression test: FAIL_ON_PROJECT_REPOS rejects project-level
// repositories, so the plugin must not inject Maven Central/local.
// https://github.com/scip-code/scip-java/issues/847
add(
checkGradleBuild("centralized-repos", "gradle/centralized-repos", expectedScipFiles = 1)
)
add(
checkGradleBuild(
"toolchains",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
plugins {
id 'java'
}
dependencies {
implementation 'com.google.guava:guava:31.1-jre'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
}
}
rootProject.name = 'centralized-repos'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import com.google.common.collect.ImmutableList;

public class Example {
public static void main(String[] args) {
System.out.println(ImmutableList.of("a", "b"));
}
}
Loading