[MNG-7980] CLI switch to ignore transitive repositories. (#1354)

If set, Maven will ignore all remote repositories introduced by
transitive dependencies POM.

---

https://issues.apache.org/jira/browse/MNG-7980
This commit is contained in:
Tamas Cservenak 2023-12-20 14:03:57 +01:00 committed by GitHub
parent 00d243a92e
commit 732e3649e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 0 deletions

View File

@ -70,6 +70,8 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest {
private boolean ignoreInvalidArtifactDescriptor = true;
private boolean ignoreTransitiveRepositories;
private List<Proxy> proxies;
private List<Server> 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;

View File

@ -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<Profile> getProfiles();

View File

@ -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());

View File

@ -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")

View File

@ -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());