Add Builder class for Dependency.

Part of work on toolchain transitions, #10523.

Closes #11438.

PiperOrigin-RevId: 312304017
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java b/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java
index c34be2a..f2a7e56 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Dependency.java
@@ -20,6 +20,10 @@
 import com.google.devtools.build.lib.analysis.config.transitions.ConfigurationTransition;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.packages.AspectDescriptor;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import javax.annotation.Nullable;
@@ -39,102 +43,68 @@
  * over-approximate the providers they supply in their definitions.
  */
 public abstract class Dependency {
+  /** Builder to assist in creating dependency instances. */
+  public static class Builder {
+    private Label label;
+    private BuildConfiguration configuration;
+    private AspectCollection aspects = AspectCollection.EMPTY;
+    private List<String> transitionKeys = new ArrayList<>();
 
-  /**
-   * Creates a new {@link Dependency} with a null configuration, suitable for edges with no
-   * configuration.
-   */
-  public static Dependency withNullConfiguration(Label label) {
-    return new NullConfigurationDependency(label, ImmutableList.of());
-  }
-
-  /**
-   * Creates a new {@link Dependency} with a null configuration and transition keys, used when edges
-   * with a split transition were resolved to null configuration targets.
-   */
-  public static Dependency withNullConfigurationAndTransitionKeys(
-      Label label, ImmutableList<String> transitionKeys) {
-    return new NullConfigurationDependency(label, transitionKeys);
-  }
-
-  /**
-   * Creates a new {@link Dependency} with the given explicit configuration. Should only be used for
-   * dependency with no configuration changes.
-   *
-   * <p>The configuration must not be {@code null}.
-   *
-   * <p>A {@link Dependency} created this way will have no associated aspects.
-   */
-  public static Dependency withConfiguration(Label label, BuildConfiguration configuration) {
-    return new ExplicitConfigurationDependency(
-        label,
-        configuration,
-        AspectCollection.EMPTY,
-        ImmutableMap.<AspectDescriptor, BuildConfiguration>of(),
-        ImmutableList.of());
-  }
-
-  /**
-   * Creates a new {@link Dependency} with the given configuration and aspects. The configuration is
-   * also applied to all aspects. Should only be used for dependency with no configuration changes.
-   *
-   * <p>The configuration and aspects must not be {@code null}.
-   */
-  public static Dependency withConfigurationAndAspects(
-      Label label, BuildConfiguration configuration, AspectCollection aspects) {
-    ImmutableMap.Builder<AspectDescriptor, BuildConfiguration> aspectBuilder =
-        new ImmutableMap.Builder<>();
-    for (AspectDescriptor aspect : aspects.getAllAspects()) {
-      aspectBuilder.put(aspect, configuration);
+    public Builder setLabel(Label label) {
+      this.label = Preconditions.checkNotNull(label);
+      return this;
     }
-    return new ExplicitConfigurationDependency(
-        label, configuration, aspects, aspectBuilder.build(), ImmutableList.of());
-  }
 
-  /**
-   * Creates a new {@link Dependency} with the given configuration, aspects, and transition key. The
-   * configuration is also applied to all aspects. This should be preferred over {@link
-   * Dependency#withConfigurationAndAspects} if the {@code configuration} was derived from a {@link
-   * ConfigurationTransition}, and so there is a corresponding transition key.
-   *
-   * <p>The configuration and aspects must not be {@code null}.
-   */
-  public static Dependency withConfigurationAspectsAndTransitionKey(
-      Label label,
-      BuildConfiguration configuration,
-      AspectCollection aspects,
-      @Nullable String transitionKey) {
-    ImmutableMap.Builder<AspectDescriptor, BuildConfiguration> aspectBuilder =
-        new ImmutableMap.Builder<>();
-    for (AspectDescriptor aspect : aspects.getAllAspects()) {
-      aspectBuilder.put(aspect, configuration);
+    public Builder setConfiguration(BuildConfiguration configuration) {
+      this.configuration = configuration;
+      return this;
     }
-    return new ExplicitConfigurationDependency(
-        label,
-        configuration,
-        aspects,
-        aspectBuilder.build(),
-        transitionKey == null ? ImmutableList.of() : ImmutableList.of(transitionKey));
+
+    /** Explicitly set the configuration for this dependency to null. */
+    public Builder withNullConfiguration() {
+      return setConfiguration(null);
+    }
+
+    /** Add aspects to this Dependency. The same configuration is applied to all aspects. */
+    public Builder setAspects(AspectCollection aspects) {
+      this.aspects = aspects;
+      return this;
+    }
+
+    public Builder addTransitionKey(String key) {
+      this.transitionKeys.add(key);
+      return this;
+    }
+
+    public Builder addTransitionKeys(Collection<String> keys) {
+      this.transitionKeys = new ArrayList<>(keys);
+      return this;
+    }
+
+    /** Returns the full Dependency instance. */
+    public Dependency build() {
+      if (configuration == null) {
+        Preconditions.checkState(aspects.equals(AspectCollection.EMPTY));
+        return new NullConfigurationDependency(label, ImmutableList.copyOf(transitionKeys));
+      }
+
+      // Use the target configuration for all aspects with none of their own.
+      Map<AspectDescriptor, BuildConfiguration> aspectConfigurations = new HashMap<>();
+      for (AspectDescriptor aspect : aspects.getAllAspects()) {
+        aspectConfigurations.put(aspect, configuration);
+      }
+      return new ExplicitConfigurationDependency(
+          label,
+          configuration,
+          aspects,
+          ImmutableMap.copyOf(aspectConfigurations),
+          ImmutableList.copyOf(transitionKeys));
+    }
   }
 
-  /**
-   * Creates a new {@link Dependency} with the given configuration and aspects, suitable for storing
-   * the output of a configuration trimming step. The aspects each have their own configuration.
-   * Should only be used for dependency with no configuration changes.
-   *
-   * <p>The aspects and configurations must not be {@code null}.
-   */
-  public static Dependency withConfiguredAspects(
-      Label label,
-      BuildConfiguration configuration,
-      AspectCollection aspects,
-      Map<AspectDescriptor, BuildConfiguration> aspectConfigurations) {
-    return new ExplicitConfigurationDependency(
-        label,
-        configuration,
-        aspects,
-        ImmutableMap.copyOf(aspectConfigurations),
-        ImmutableList.of());
+  /** Returns a new {@link Builder} to create {@link Dependency} instances. */
+  public static Builder builder() {
+    return new Builder();
   }
 
   protected final Label label;
@@ -166,9 +136,7 @@
    */
   public abstract AspectCollection getAspects();
 
-  /**
-   * Returns the configuration an aspect should be evaluated with
-   */
+  /** Returns the configuration an aspect should be evaluated with. */
   public abstract BuildConfiguration getAspectConfiguration(AspectDescriptor aspect);
 
   /**
@@ -301,5 +269,4 @@
           getClass().getSimpleName(), label, configuration, aspectConfigurations);
     }
   }
-
 }
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigurationResolver.java b/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigurationResolver.java
index 2862d54..c141859 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigurationResolver.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigurationResolver.java
@@ -177,7 +177,8 @@
       // total analysis phase time.
       ConfigurationTransition transition = dep.getTransition();
       if (transition == NullTransition.INSTANCE) {
-        Dependency finalDependency = Dependency.withNullConfiguration(dep.getLabel());
+        Dependency finalDependency =
+            Dependency.builder().withNullConfiguration().setLabel(dep.getLabel()).build();
         // If the base transition is a split transition, execute the transition and store returned
         // transition keys along with the null configuration dependency, so that other code relying
         // on stored transition keys doesn't have to implement special handling logic just for this
@@ -213,8 +214,11 @@
             }
             if (!SplitTransition.equals(currentConfiguration.getOptions(), toOptions.values())) {
               finalDependency =
-                  Dependency.withNullConfigurationAndTransitionKeys(
-                      dep.getLabel(), ImmutableList.copyOf(toOptions.keySet()));
+                  Dependency.builder()
+                      .setLabel(dep.getLabel())
+                      .withNullConfiguration()
+                      .addTransitionKeys(ImmutableList.copyOf(toOptions.keySet()))
+                      .build();
             }
           }
         }
@@ -256,8 +260,11 @@
           putOnlyEntry(
               resolvedDeps,
               dependencyEdge,
-              Dependency.withConfigurationAndAspects(
-                  dep.getLabel(), ctgValue.getConfiguration(), dep.getAspects()));
+              Dependency.builder()
+                  .setLabel(dep.getLabel())
+                  .setConfiguration(ctgValue.getConfiguration())
+                  .setAspects(dep.getAspects())
+                  .build());
           continue;
         } else if (transition.isHostTransition()) {
           // The current rule's host configuration can also be used for the dep. We short-circuit
@@ -277,8 +284,11 @@
           putOnlyEntry(
               resolvedDeps,
               dependencyEdge,
-              Dependency.withConfigurationAndAspects(
-                  dep.getLabel(), hostConfiguration, dep.getAspects()));
+              Dependency.builder()
+                  .setLabel(dep.getLabel())
+                  .setConfiguration(hostConfiguration)
+                  .setAspects(dep.getAspects())
+                  .build());
           continue;
         }
       }
@@ -323,8 +333,11 @@
         putOnlyEntry(
             resolvedDeps,
             dependencyEdge,
-            Dependency.withConfigurationAspectsAndTransitionKey(
-                dep.getLabel(), ctgValue.getConfiguration(), dep.getAspects(), null));
+            Dependency.builder()
+                .setLabel(dep.getLabel())
+                .setConfiguration(ctgValue.getConfiguration())
+                .setAspects(dep.getAspects())
+                .build());
         continue;
       }
 
@@ -411,8 +424,12 @@
           }
           DependencyEdge attr = new DependencyEdge(info.first.getKey(), originalDep.getLabel());
           Dependency resolvedDep =
-              Dependency.withConfigurationAspectsAndTransitionKey(
-                  originalDep.getLabel(), trimmedConfig, originalDep.getAspects(), info.second);
+              Dependency.builder()
+                  .setLabel(originalDep.getLabel())
+                  .setConfiguration(trimmedConfig)
+                  .setAspects(originalDep.getAspects())
+                  .addTransitionKey(info.second)
+                  .build();
           Attribute attribute = attr.dependencyKind.getAttribute();
           if (attribute != null && attribute.getTransitionFactory().isSplit()) {
             resolvedDeps.put(attr, resolvedDep);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
index 56efefd..55f3bdd 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
@@ -714,7 +714,10 @@
     ImmutableList.Builder<Dependency> depsBuilder = ImmutableList.builder();
     for (Label configurabilityLabel : configLabels) {
       Dependency configurabilityDependency =
-          Dependency.withConfiguration(configurabilityLabel, ctgValue.getConfiguration());
+          Dependency.builder()
+              .setLabel(configurabilityLabel)
+              .setConfiguration(ctgValue.getConfiguration())
+              .build();
       depsBuilder.add(configurabilityDependency);
     }
 
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/DependencyKeyTest.java b/src/test/java/com/google/devtools/build/lib/analysis/DependencyKeyTest.java
index 6827537..e47551f 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/DependencyKeyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/DependencyKeyTest.java
@@ -18,8 +18,6 @@
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.testing.EqualsTester;
-import com.google.common.testing.NullPointerTester;
-import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.analysis.config.HostTransition;
 import com.google.devtools.build.lib.analysis.config.transitions.NoTransition;
 import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
@@ -67,16 +65,6 @@
   }
 
   @Test
-  public void factoriesPassNullableTester() throws Exception {
-    update();
-
-    new NullPointerTester()
-        .setDefault(Label.class, Label.parseAbsolute("//a", ImmutableMap.of()))
-        .setDefault(BuildConfiguration.class, getTargetConfiguration())
-        .testAllPublicStaticMethods(Dependency.class);
-  }
-
-  @Test
   public void equalsPassesEqualsTester() throws Exception {
     update();
 
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/DependencyTest.java b/src/test/java/com/google/devtools/build/lib/analysis/DependencyTest.java
index 83a4df7..9e0688e 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/DependencyTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/DependencyTest.java
@@ -19,7 +19,6 @@
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.testing.EqualsTester;
-import com.google.common.testing.NullPointerTester;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
 import com.google.devtools.build.lib.analysis.util.TestAspects;
@@ -39,7 +38,10 @@
   @Test
   public void withNullConfiguration_BasicAccessors() throws Exception {
     Dependency nullDep =
-        Dependency.withNullConfiguration(Label.parseAbsolute("//a", ImmutableMap.of()));
+        Dependency.builder()
+            .withNullConfiguration()
+            .setLabel(Label.parseAbsolute("//a", ImmutableMap.of()))
+            .build();
 
     assertThat(nullDep.getLabel()).isEqualTo(Label.parseAbsolute("//a", ImmutableMap.of()));
     assertThat(nullDep.getConfiguration()).isNull();
@@ -50,8 +52,10 @@
   public void withConfiguration_BasicAccessors() throws Exception {
     update();
     Dependency targetDep =
-        Dependency.withConfiguration(
-            Label.parseAbsolute("//a", ImmutableMap.of()), getTargetConfiguration());
+        Dependency.builder()
+            .setLabel(Label.parseAbsolute("//a", ImmutableMap.of()))
+            .setConfiguration(getTargetConfiguration())
+            .build();
 
     assertThat(targetDep.getLabel()).isEqualTo(Label.parseAbsolute("//a", ImmutableMap.of()));
     assertThat(targetDep.getConfiguration()).isEqualTo(getTargetConfiguration());
@@ -66,8 +70,11 @@
     AspectCollection twoAspects = AspectCollection.createForTests(
         ImmutableSet.of(simpleAspect, attributeAspect));
     Dependency targetDep =
-        Dependency.withConfigurationAndAspects(
-            Label.parseAbsolute("//a", ImmutableMap.of()), getTargetConfiguration(), twoAspects);
+        Dependency.builder()
+            .setLabel(Label.parseAbsolute("//a", ImmutableMap.of()))
+            .setConfiguration(getTargetConfiguration())
+            .setAspects(twoAspects)
+            .build();
 
     assertThat(targetDep.getLabel()).isEqualTo(Label.parseAbsolute("//a", ImmutableMap.of()));
     assertThat(targetDep.getConfiguration()).isEqualTo(getTargetConfiguration());
@@ -78,7 +85,7 @@
   }
 
   @Test
-  public void withConfigurationAndAspects_RejectsNullConfigWithNPE() throws Exception {
+  public void withConfigurationAndAspects_RejectsNullConfig() throws Exception {
     // Although the NullPointerTester should check this, this test invokes a different code path,
     // because it includes aspects (which the NPT test will not).
     AspectDescriptor simpleAspect = new AspectDescriptor(TestAspects.SIMPLE_ASPECT);
@@ -86,20 +93,23 @@
     AspectCollection twoAspects = AspectCollection.createForTests(simpleAspect, attributeAspect);
 
     assertThrows(
-        NullPointerException.class,
+        IllegalStateException.class,
         () ->
-            Dependency.withConfigurationAndAspects(
-                Label.parseAbsolute("//a", ImmutableMap.of()), null, twoAspects));
+            Dependency.builder()
+                .setLabel(Label.parseAbsolute("//a", ImmutableMap.of()))
+                .setConfiguration(null)
+                .setAspects(twoAspects)
+                .build());
   }
 
   @Test
   public void withConfigurationAndAspects_AllowsEmptyAspectSet() throws Exception {
     update();
     Dependency dep =
-        Dependency.withConfigurationAndAspects(
-            Label.parseAbsolute("//a", ImmutableMap.of()),
-            getTargetConfiguration(),
-            AspectCollection.EMPTY);
+        Dependency.builder()
+            .setLabel(Label.parseAbsolute("//a", ImmutableMap.of()))
+            .setConfiguration(getTargetConfiguration())
+            .build();
     // Here we're also checking that this doesn't throw an exception. No boom? OK. Good.
     assertThat(dep.getAspects().getAllAspects()).isEmpty();
   }
@@ -111,49 +121,33 @@
     AspectDescriptor attributeAspect = new AspectDescriptor(TestAspects.ATTRIBUTE_ASPECT);
     AspectCollection aspects =
         AspectCollection.createForTests(ImmutableSet.of(simpleAspect, attributeAspect));
-    ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectMap = ImmutableMap.of(
-        simpleAspect, getTargetConfiguration(), attributeAspect, getHostConfiguration());
     Dependency targetDep =
-        Dependency.withConfiguredAspects(
-            Label.parseAbsolute("//a", ImmutableMap.of()),
-            getTargetConfiguration(),
-            aspects,
-            twoAspectMap);
+        Dependency.builder()
+            .setLabel(Label.parseAbsolute("//a", ImmutableMap.of()))
+            .setConfiguration(getTargetConfiguration())
+            .setAspects(aspects)
+            .build();
 
     assertThat(targetDep.getLabel()).isEqualTo(Label.parseAbsolute("//a", ImmutableMap.of()));
     assertThat(targetDep.getConfiguration()).isEqualTo(getTargetConfiguration());
     assertThat(targetDep.getAspects().getAllAspects())
         .containsExactly(simpleAspect, attributeAspect);
-    assertThat(targetDep.getAspectConfiguration(simpleAspect)).isEqualTo(getTargetConfiguration());
-    assertThat(targetDep.getAspectConfiguration(attributeAspect))
-        .isEqualTo(getHostConfiguration());
   }
 
-
   @Test
   public void withConfiguredAspects_AllowsEmptyAspectMap() throws Exception {
     update();
     Dependency dep =
-        Dependency.withConfiguredAspects(
-            Label.parseAbsolute("//a", ImmutableMap.of()),
-            getTargetConfiguration(),
-            AspectCollection.EMPTY,
-            ImmutableMap.<AspectDescriptor, BuildConfiguration>of());
+        Dependency.builder()
+            .setLabel(Label.parseAbsolute("//a", ImmutableMap.of()))
+            .setConfiguration(getTargetConfiguration())
+            .setAspects(AspectCollection.EMPTY)
+            .build();
     // Here we're also checking that this doesn't throw an exception. No boom? OK. Good.
     assertThat(dep.getAspects().getAllAspects()).isEmpty();
   }
 
   @Test
-  public void factoriesPassNullableTester() throws Exception {
-    update();
-
-    new NullPointerTester()
-        .setDefault(Label.class, Label.parseAbsolute("//a", ImmutableMap.of()))
-        .setDefault(BuildConfiguration.class, getTargetConfiguration())
-        .testAllPublicStaticMethods(Dependency.class);
-  }
-
-  @Test
   public void equalsPassesEqualsTester() throws Exception {
     update();
 
@@ -176,104 +170,206 @@
         AspectCollection.createForTests(attributeAspect, errorAspect);
     AspectCollection noAspects = AspectCollection.EMPTY;
 
-    ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectsHostMap =
-        ImmutableMap.of(simpleAspect, host, attributeAspect, host);
-    ImmutableMap<AspectDescriptor, BuildConfiguration> twoAspectsTargetMap =
-        ImmutableMap.of(simpleAspect, target, attributeAspect, target);
-    ImmutableMap<AspectDescriptor, BuildConfiguration> differentAspectsHostMap =
-        ImmutableMap.of(attributeAspect, host, errorAspect, host);
-    ImmutableMap<AspectDescriptor, BuildConfiguration> differentAspectsTargetMap =
-        ImmutableMap.of(attributeAspect, target, errorAspect, target);
-    ImmutableMap<AspectDescriptor, BuildConfiguration> noAspectsMap =
-        ImmutableMap.<AspectDescriptor, BuildConfiguration>of();
-
     new EqualsTester()
         .addEqualityGroup(
             // base set: //a, host configuration, normal aspect set
-            Dependency.withConfigurationAndAspects(a, host, twoAspects),
-            Dependency.withConfigurationAndAspects(aExplicit, host, twoAspects),
-            Dependency.withConfigurationAndAspects(a, host, inverseAspects),
-            Dependency.withConfigurationAndAspects(aExplicit, host, inverseAspects),
-            Dependency.withConfiguredAspects(a, host, twoAspects, twoAspectsHostMap),
-            Dependency.withConfiguredAspects(aExplicit, host, twoAspects, twoAspectsHostMap))
+            Dependency.builder().setLabel(a).setConfiguration(host).setAspects(twoAspects).build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(host)
+                .setAspects(twoAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(a)
+                .setConfiguration(host)
+                .setAspects(inverseAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(host)
+                .setAspects(inverseAspects)
+                .build(),
+            Dependency.builder().setLabel(a).setConfiguration(host).setAspects(twoAspects).build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(host)
+                .setAspects(twoAspects)
+                .build())
         .addEqualityGroup(
             // base set but with label //b
-            Dependency.withConfigurationAndAspects(b, host, twoAspects),
-            Dependency.withConfigurationAndAspects(b, host, inverseAspects),
-            Dependency.withConfiguredAspects(b, host, twoAspects, twoAspectsHostMap))
+            Dependency.builder().setLabel(b).setConfiguration(host).setAspects(twoAspects).build(),
+            Dependency.builder()
+                .setLabel(b)
+                .setConfiguration(host)
+                .setAspects(inverseAspects)
+                .build(),
+            Dependency.builder().setLabel(b).setConfiguration(host).setAspects(twoAspects).build())
         .addEqualityGroup(
             // base set but with target configuration
-            Dependency.withConfigurationAndAspects(a, target, twoAspects),
-            Dependency.withConfigurationAndAspects(aExplicit, target, twoAspects),
-            Dependency.withConfigurationAndAspects(a, target, inverseAspects),
-            Dependency.withConfigurationAndAspects(aExplicit, target, inverseAspects),
-            Dependency.withConfiguredAspects(a, target, twoAspects, twoAspectsTargetMap),
-            Dependency.withConfiguredAspects(aExplicit, target, twoAspects, twoAspectsTargetMap))
+            Dependency.builder()
+                .setLabel(a)
+                .setConfiguration(target)
+                .setAspects(twoAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(target)
+                .setAspects(twoAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(a)
+                .setConfiguration(target)
+                .setAspects(inverseAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(target)
+                .setAspects(inverseAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(a)
+                .setConfiguration(target)
+                .setAspects(twoAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(target)
+                .setAspects(twoAspects)
+                .build())
         .addEqualityGroup(
             // base set but with null configuration
-            Dependency.withNullConfiguration(a),
-            Dependency.withNullConfiguration(aExplicit))
+            Dependency.builder().withNullConfiguration().setLabel(a).build(),
+            Dependency.builder().withNullConfiguration().setLabel(aExplicit).build())
         .addEqualityGroup(
             // base set but with different aspects
-            Dependency.withConfigurationAndAspects(a, host, differentAspects),
-            Dependency.withConfigurationAndAspects(aExplicit, host, differentAspects),
-            Dependency.withConfiguredAspects(
-                a, host, differentAspects, differentAspectsHostMap),
-            Dependency.withConfiguredAspects(
-                aExplicit, host, differentAspects, differentAspectsHostMap))
+            Dependency.builder()
+                .setLabel(a)
+                .setConfiguration(host)
+                .setAspects(differentAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(host)
+                .setAspects(differentAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(a)
+                .setConfiguration(host)
+                .setAspects(differentAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(host)
+                .setAspects(differentAspects)
+                .build())
         .addEqualityGroup(
             // base set but with label //b and target configuration
-            Dependency.withConfigurationAndAspects(b, target, twoAspects),
-            Dependency.withConfigurationAndAspects(b, target, inverseAspects),
-            Dependency.withConfiguredAspects(b, target,
-                twoAspects, twoAspectsTargetMap))
+            Dependency.builder()
+                .setLabel(b)
+                .setConfiguration(target)
+                .setAspects(twoAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(b)
+                .setConfiguration(target)
+                .setAspects(inverseAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(b)
+                .setConfiguration(target)
+                .setAspects(twoAspects)
+                .build())
         .addEqualityGroup(
             // base set but with label //b and null configuration
-            Dependency.withNullConfiguration(b))
+            Dependency.builder().withNullConfiguration().setLabel(b).build())
         .addEqualityGroup(
             // base set but with label //b and different aspects
-            Dependency.withConfigurationAndAspects(b, host, differentAspects),
-            Dependency.withConfiguredAspects(
-                b, host, differentAspects, differentAspectsHostMap))
+            Dependency.builder()
+                .setLabel(b)
+                .setConfiguration(host)
+                .setAspects(differentAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(b)
+                .setConfiguration(host)
+                .setAspects(differentAspects)
+                .build())
         .addEqualityGroup(
             // base set but with target configuration and different aspects
-            Dependency.withConfigurationAndAspects(a, target, differentAspects),
-            Dependency.withConfigurationAndAspects(aExplicit, target, differentAspects),
-            Dependency.withConfiguredAspects(
-                a, target, differentAspects, differentAspectsTargetMap),
-            Dependency.withConfiguredAspects(
-                aExplicit, target, differentAspects, differentAspectsTargetMap))
+            Dependency.builder()
+                .setLabel(a)
+                .setConfiguration(target)
+                .setAspects(differentAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(target)
+                .setAspects(differentAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(a)
+                .setConfiguration(target)
+                .setAspects(differentAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(target)
+                .setAspects(differentAspects)
+                .build())
         .addEqualityGroup(
             // inverse of base set: //b, target configuration, different aspects
-            Dependency.withConfigurationAndAspects(b, target, differentAspects),
-            Dependency.withConfiguredAspects(
-                b, target, differentAspects, differentAspectsTargetMap))
+            Dependency.builder()
+                .setLabel(b)
+                .setConfiguration(target)
+                .setAspects(differentAspects)
+                .build(),
+            Dependency.builder()
+                .setLabel(b)
+                .setConfiguration(target)
+                .setAspects(differentAspects)
+                .build())
         .addEqualityGroup(
             // base set but with no aspects
-            Dependency.withConfiguration(a, host),
-            Dependency.withConfiguration(aExplicit, host),
-            Dependency.withConfigurationAndAspects(a, host, noAspects),
-            Dependency.withConfigurationAndAspects(aExplicit, host, noAspects),
-            Dependency.withConfiguredAspects(a, host, noAspects, noAspectsMap),
-            Dependency.withConfiguredAspects(aExplicit, host, noAspects, noAspectsMap))
+            Dependency.builder().setLabel(a).setConfiguration(host).build(),
+            Dependency.builder().setLabel(aExplicit).setConfiguration(host).build(),
+            Dependency.builder().setLabel(a).setConfiguration(host).setAspects(noAspects).build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(host)
+                .setAspects(noAspects)
+                .build(),
+            Dependency.builder().setLabel(a).setConfiguration(host).setAspects(noAspects).build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(host)
+                .setAspects(noAspects)
+                .build())
         .addEqualityGroup(
             // base set but with label //b and no aspects
-            Dependency.withConfiguration(b, host),
-            Dependency.withConfigurationAndAspects(b, host, noAspects),
-            Dependency.withConfiguredAspects(b, host, noAspects, noAspectsMap))
+            Dependency.builder().setLabel(b).setConfiguration(host).build(),
+            Dependency.builder().setLabel(b).setConfiguration(host).setAspects(noAspects).build(),
+            Dependency.builder().setLabel(b).setConfiguration(host).setAspects(noAspects).build())
         .addEqualityGroup(
             // base set but with target configuration and no aspects
-            Dependency.withConfiguration(a, target),
-            Dependency.withConfiguration(aExplicit, target),
-            Dependency.withConfigurationAndAspects(a, target, noAspects),
-            Dependency.withConfigurationAndAspects(aExplicit, target, noAspects),
-            Dependency.withConfiguredAspects(a, target, noAspects, noAspectsMap),
-            Dependency.withConfiguredAspects(aExplicit, target, noAspects, noAspectsMap))
+            Dependency.builder().setLabel(a).setConfiguration(target).build(),
+            Dependency.builder().setLabel(aExplicit).setConfiguration(target).build(),
+            Dependency.builder().setLabel(a).setConfiguration(target).setAspects(noAspects).build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(target)
+                .setAspects(noAspects)
+                .build(),
+            Dependency.builder().setLabel(a).setConfiguration(target).setAspects(noAspects).build(),
+            Dependency.builder()
+                .setLabel(aExplicit)
+                .setConfiguration(target)
+                .setAspects(noAspects)
+                .build())
         .addEqualityGroup(
             // inverse of base set: //b, target configuration, no aspects
-            Dependency.withConfiguration(b, target),
-            Dependency.withConfigurationAndAspects(b, target, noAspects),
-            Dependency.withConfiguredAspects(b, target, noAspects, noAspectsMap))
+            Dependency.builder().setLabel(b).setConfiguration(target).build(),
+            Dependency.builder().setLabel(b).setConfiguration(target).setAspects(noAspects).build(),
+            Dependency.builder().setLabel(b).setConfiguration(target).setAspects(noAspects).build())
         .testEquals();
   }
 }
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java
index d6d58a6..ae07bbf 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java
@@ -363,8 +363,14 @@
     // We don't care what order split deps are listed, but it must be deterministic.
     assertThat(
             ConfigurationResolver.SPLIT_DEP_ORDERING.compare(
-                Dependency.withConfiguration(dep1.getLabel(), getConfiguration(dep1)),
-                Dependency.withConfiguration(dep2.getLabel(), getConfiguration(dep2))))
+                Dependency.builder()
+                    .setLabel(dep1.getLabel())
+                    .setConfiguration(getConfiguration(dep1))
+                    .build(),
+                Dependency.builder()
+                    .setLabel(dep2.getLabel())
+                    .setConfiguration(getConfiguration(dep2))
+                    .build()))
         .isLessThan(0);
   }