Permalink
Browse files

First stab at custom conflict resolution strategies. Currently one ca…

…n configure them in the dependencies section of the build. It's not yet documented properly because I don't know what's going to be the final shape of DSL (guys, give feedback!).

Remaining important items:
 - decide on DSL
 - fix the error handling so that the build fails gracefully
  • Loading branch information...
1 parent d5d625f commit 7b9884158f28ce0126933588451c178fb869df31 @szczepiq szczepiq committed Sep 30, 2011
@@ -65,6 +65,7 @@ public ResolvedConfiguration resolve(ConfigurationInternal configuration) {
try {
resolveReport = ivy.resolve(moduleDescriptor, resolveOptions);
} catch (Exception e) {
+ ivyConfig.maybeTranslateIvyResolveException(e);
throw new RuntimeException(e);
}
logger.debug("Timing: Ivy resolve took {}", clock.getTime());
@@ -21,9 +21,11 @@
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.plugins.conflict.AbstractConflictManager;
import org.apache.ivy.plugins.conflict.LatestConflictManager;
+import org.apache.ivy.plugins.conflict.StrictConflictException;
import org.apache.ivy.plugins.conflict.StrictConflictManager;
import org.apache.ivy.plugins.latest.LatestRevisionStrategy;
import org.apache.ivy.plugins.matcher.ExactPatternMatcher;
+import org.gradle.api.GradleException;
import org.gradle.api.artifacts.VersionConflictStrategy;
/**
@@ -60,4 +62,13 @@ private AbstractConflictManager createIvyConflictManager() {
throw new RuntimeException("I don't know what ivy conflict manager to use for this VersionConflictStrategy: " + conflictStrategy);
}
}
+
+ //TODO SF some tests around that
+ public void maybeTranslateIvyResolveException(Exception e) {
+ if (e instanceof StrictConflictException) {
+ throw new GradleException("Your dependencies exhibit a version conflict. "
+ + "The conflict resolution strategy is set to: " + conflictStrategy
+ + ". Details: " + e.getMessage(), e);
+ }
+ }
}
@@ -17,6 +17,7 @@
import groovy.lang.Closure;
import org.gradle.api.artifacts.Dependency;
+import org.gradle.api.artifacts.VersionConflictStrategy;
import java.util.Map;
@@ -176,4 +177,20 @@
* @return The dependency.
*/
Dependency localGroovy();
+
+
+ /**
+ * Configures the version conflict strategy.
+ *
+ * <pre>
+ * dependencies {
+ * //..
+ *
+ * versionConflictStrategy = VersionConflictStrategy.STRICT
+ * }
+ * </pre>
+ *
+ * @param strategy to use
+ */
+ void setVersionConflictStrategy(VersionConflictStrategy strategy);
}
@@ -22,4 +22,5 @@
public interface ConfigurationInternal extends Configuration, DependencyMetaDataProvider {
DependencyResolutionListener getDependencyResolutionBroadcast();
VersionConflictStrategy getVersionConflictStrategy();
+ void setVersionConflictStrategy(VersionConflictStrategy strategy);
}
@@ -16,10 +16,13 @@
package org.gradle.api.internal.artifacts.dsl.dependencies
+import org.gradle.api.Action
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.artifacts.Dependency
+import org.gradle.api.artifacts.VersionConflictStrategy
import org.gradle.api.artifacts.dsl.DependencyHandler
+import org.gradle.api.internal.artifacts.configurations.ConfigurationInternal
import org.gradle.util.ConfigureUtil
import org.gradle.util.GUtil
@@ -97,4 +100,12 @@ class DefaultDependencyHandler implements DependencyHandler {
}
return null;
}
-}
+
+ void setVersionConflictStrategy(VersionConflictStrategy strategy) {
+ configurationContainer.all(new Action<Configuration>() {
+ public void execute(Configuration configuration) {
+ ((ConfigurationInternal) configuration).setVersionConflictStrategy(strategy);
+ }
+ });
+ }
+}
@@ -63,24 +63,33 @@ project(':tool') {
dependencies {
compile project(':api')
compile project(':impl')
+ versionConflictStrategy = VersionConflictStrategy.STRICT
}
- configurations.compile.versionConflictStrategy = VersionConflictStrategy.STRICT
}
"""
try {
//when
executer.usingBuildScript(buildFile).usingSettingsFile(settingsFile)
.withArguments("-s")
- .withTasks("tool:dependencies").run() //for some reason I cannot use runWithFailure
+ .withTasks("tool:dependencies").run() //cannot runWithFailure until the error reporting is fixed
//then
assert false
} catch(Exception e) {
- assert e.cause.cause.cause.message.contains('StrictConflictException') //nice, huh? :D
+ assert messages(e).contains('StrictConflictException')
}
}
+ String messages(Exception e) {
+ String out = e.toString()
+ while(e.cause) {
+ e = e.cause
+ out += "\n$e"
+ }
+ out
+ }
+
@Test
void "strict conflict resolution should pass when no conflicts"() {
TestFile repo = file("repo")
@@ -114,8 +123,8 @@ project(':tool') {
dependencies {
compile project(':api')
compile project(':impl')
+ versionConflictStrategy = VersionConflictStrategy.STRICT
}
- configurations.compile.versionConflictStrategy = VersionConflictStrategy.STRICT
}
"""

0 comments on commit 7b98841

Please sign in to comment.