-
Notifications
You must be signed in to change notification settings - Fork 935
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load global plugins in their own class loader and replace the base lo…
…ader with that. Fixes #272. Also, replace the base classpath with the global classpath.
- Loading branch information
Showing
8 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# tests that a source file in $sbt.global.base/plugins/ is available to the build definition in project/ | ||
|
||
# dummy to ensure project gets loaded | ||
> name |
21 changes: 21 additions & 0 deletions
21
sbt/src/sbt-test/project/global-plugin/changes/Build.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import sbt._ | ||
import sbt.Keys._ | ||
|
||
object MyBuild extends Build { | ||
lazy val mySettings = Defaults.defaultSettings ++ Seq( | ||
name := "my-test-proj", | ||
organization := "com.example", | ||
check <<= update map checkVersion, | ||
version := "0.1.0-SNAPSHOT") | ||
|
||
lazy val proj = Project("my-test-proj", file("."), settings = mySettings) | ||
|
||
lazy val check = taskKey[Unit]("Verifies that the junit dependency has the older version (4.5)") | ||
|
||
def checkVersion(report: UpdateReport) { | ||
for(mod <- report.allModules) { | ||
if(mod.name == "junit") assert(mod.revision == "4.5", s"JUnit version (${mod.revision}) was not overridden") | ||
} | ||
} | ||
} | ||
|
3 changes: 3 additions & 0 deletions
3
sbt/src/sbt-test/project/global-plugin/changes/global-plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// use a small java library instead of a plugin to avoid incompatibilities when upgrading | ||
// use an old version to check that it will override a newer version in a build definition | ||
libraryDependencies += "junit" % "junit" % "4.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// the version should be overridden by the global plugin | ||
libraryDependencies += "junit" % "junit" % "4.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
# tests that a source file in $sbt.global.base/plugins/ is available to the build definition in project/ | ||
$ copy-file changes/Build.scala project/Build.scala | ||
> reload | ||
|
||
# dummy to ensure project gets loaded | ||
> name | ||
# ensure that a new global dependency gets picked up | ||
$ copy-file changes/global-plugins.sbt global/plugins/plugins.sbt | ||
> reload | ||
|
||
# check that the class can be loaded | ||
> eval Class.forName("org.junit.Test") | ||
|
||
# check that it is on the classpath | ||
> eval (x => ()) : (org.junit.Test => Unit) | ||
|
||
# ensure that the global plugin version overrides the local version | ||
$ copy-file changes/plugins.sbt project/plugins.sbt | ||
> reload | ||
> check |
8cb7e23
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this behaviour is not what we want. Regarding the scripted test, I think we always want to pick the newer version from (global plugin, project's build). That should be done automatically by Ivy when it resolves the build, because the GP is added as a source dependency of any build. But for that to work, we have to not include GP's classpath & classloader when constructing a build's classpath & classloader.
With this change in place, adding the GP's classpath onto
config.classpath
, it means that, if a build redefines a dependency of GP, that build ends up with two versions of the same dep on the CP (and the same goes if the dependency is declared only in the GP, but is dynamic). Clearly not what we want.8cb7e23
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree. This is where having full classpath separation would, indeed, be nice. I think this related to the issues you see with global plugins today. If you wanted to take a crack at fixing that please let me know, with the caveat that it would need to go in "early" in a sbt release cycle so we can fully vet it.