Skip to content

Commit 1d66533

Browse files
committed
Exclude scala-xml from transitive dependencies of partest.
As discovered here: #6 (comment) we would have two different versions of scala-xml on test classpath: 1. scala-xml classes compiled from source (we are in scala-xml project) 2. scala-xml transitive dependencies of partest Duplicated classpath entries are always dangerous. I implemented a set of exclude rules that get rid of transitive dependencies of scala-xml. This fixes the problem of JUnit using wrong version of scala-xml for testing (now there's only one choice). Also, this allowed me to to enable conflictWarning again. They are very useful to warn us against dangerous situations that almost always result in broken classpath (as we just learned).
1 parent dd1e0e4 commit 1d66533

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

build.sbt

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,34 @@ TestKeys.partestVersion := "1.0.0-RC6"
8888
// so that it can link to the compiler/lib we're using (testing)
8989
// NOTE: not sure why, but the order matters (maybe due to the binary version conflicts for xml/parser combinators pulled in for scaladoc?)
9090
libraryDependencies ++= (
91-
if (TestKeys.includeTestDependencies.value)
92-
Seq("org.scala-lang.modules" %% "scala-partest-interface" % "0.2" % "test",
93-
"org.scala-lang.modules" %% "scala-partest" % TestKeys.partestVersion.value % "test")
91+
if (TestKeys.includeTestDependencies.value) {
92+
/**
93+
* Exclude all transitive dependencies of partest that include scala-.xml.
94+
* This way we avoid having two (or more) versions of scala-xml on a classpath.
95+
* This fixes problem described here:
96+
* https://github.com/scala/scala-xml/pull/6#issuecomment-26614894
97+
*
98+
* Note that we are using ModuleID.exclude instead of more flexible ModuleID.excludeAll
99+
* (describe here: http://www.scala-sbt.org/release/docs/Detailed-Topics/Library-Management#exclude-transitive-dependencies)
100+
* because only plain excludes are incorporated in generated pom.xml. There are two ways
101+
* to address this problem:
102+
*
103+
* 1. Figure out how to depend on partest in non-transitive way: not include that dependency
104+
* in generated pom.xml for scala-xml.
105+
* 2. Declare dependencies in partest as provided so they are not includeded transitively.
106+
*
107+
*/
108+
def excludeScalaXml(dep: ModuleID): ModuleID =
109+
dep.exclude("org.scala-lang.modules", "scala-xml_2.11.0-M5").
110+
exclude("org.scala-lang.modules", "scala-xml_2.11.0-M4").
111+
exclude("org.scalacheck", "scalacheck_2.11.0-M5")
112+
Seq("org.scala-lang.modules" % "scala-partest-interface_2.11.0-M5" % "0.2" % "test",
113+
"org.scala-lang.modules" % "scala-partest_2.11.0-M5" % TestKeys.partestVersion.value % "test").
114+
map(excludeScalaXml)
115+
}
94116
else Seq.empty
95117
)
96118

97-
98-
// necessary for partest -- see comments in its build.sbt
99-
conflictWarning ~= { _.copy(failOnConflict = false) }
100-
101119
fork in Test := true
102120

103121
javaOptions in Test += "-Xmx1G"

0 commit comments

Comments
 (0)