diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java index 7f2bb95362..ba8fe25bc8 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java @@ -70,6 +70,8 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest { private boolean ignoreInvalidArtifactDescriptor = true; + private boolean ignoreTransitiveRepositories; + private List proxies; private List servers; @@ -180,6 +182,7 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest { copy.setCacheTransferError(original.isCacheTransferError()); copy.setIgnoreMissingArtifactDescriptor(original.isIgnoreMissingArtifactDescriptor()); copy.setIgnoreInvalidArtifactDescriptor(original.isIgnoreInvalidArtifactDescriptor()); + copy.setIgnoreTransitiveRepositories(original.isIgnoreTransitiveRepositories()); copy.setProxies(original.getProxies()); copy.setServers(original.getServers()); copy.setMirrors(original.getMirrors()); @@ -1056,12 +1059,23 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest { return ignoreInvalidArtifactDescriptor; } + @Override + public boolean isIgnoreTransitiveRepositories() { + return ignoreTransitiveRepositories; + } + @Override public MavenExecutionRequest setIgnoreInvalidArtifactDescriptor(boolean ignoreInvalid) { this.ignoreInvalidArtifactDescriptor = ignoreInvalid; return this; } + @Override + public MavenExecutionRequest setIgnoreTransitiveRepositories(boolean ignoreTransitiveRepositories) { + this.ignoreTransitiveRepositories = ignoreTransitiveRepositories; + return this; + } + @Override public boolean isUseLegacyLocalRepository() { return this.useLegacyLocalRepositoryManager; diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java index c5bcb6a7a7..1904dff7a6 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java @@ -305,6 +305,16 @@ public interface MavenExecutionRequest { */ MavenExecutionRequest setIgnoreInvalidArtifactDescriptor(boolean ignoreInvalid); + /** + * @since 4.0.0 + */ + boolean isIgnoreTransitiveRepositories(); + + /** + * @since 4.0.0 + */ + MavenExecutionRequest setIgnoreTransitiveRepositories(boolean ignoreTransitiveRepositories); + // Profiles List getProfiles(); diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index a3e718f08b..8fcf89d66e 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -372,6 +372,7 @@ public class DefaultRepositorySystemSessionFactory { session.setUserProperties(request.getUserProperties()); session.setSystemProperties(request.getSystemProperties()); session.setConfigProperties(configProps); + session.setIgnoreArtifactDescriptorRepositories(request.isIgnoreTransitiveRepositories()); session.setTransferListener(request.getTransferListener()); diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java index 3b04b1922b..baf1c2127c 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java @@ -121,6 +121,8 @@ public class CLIManager { public static final String STRICT_ARTIFACT_DESCRIPTOR_POLICY = "sadp"; + public static final String IGNORE_TRANSITIVE_REPOSITORIES = "itr"; + /** This option is deprecated and may be repurposed as Java debug in a future version. * Use {@code -X/--verbose} instead. */ @Deprecated @@ -323,6 +325,10 @@ public class CLIManager { .hasArg() .desc("Defines 'strict' artifact descriptor policy. Supported values are 'true', 'false' (default).") .build()); + options.addOption(Option.builder(IGNORE_TRANSITIVE_REPOSITORIES) + .longOpt("ignore-transitive-repositories") + .desc("If set, Maven will ignore remote repositories introduced by transitive dependencies.") + .build()); // Adding this back to make Maven fail if used options.addOption(Option.builder("llr") diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 422fe9c2ff..98bd4092d4 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -1304,6 +1304,8 @@ public class MavenCli { request.setIgnoreMissingArtifactDescriptor(true); request.setIgnoreInvalidArtifactDescriptor(true); } + enableOnPresentOption( + commandLine, CLIManager.IGNORE_TRANSITIVE_REPOSITORIES, request::setIgnoreTransitiveRepositories); performProjectActivation(commandLine, request.getProjectActivation()); performProfileActivation(commandLine, request.getProfileActivation());