Skip to content

Commit a8ce9fa

Browse files
committed
Add withAddedResolvers to DependencyResolutionInterface
1 parent 689f347 commit a8ce9fa

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

core/src/main/scala/sbt/librarymanagement/DependencyResolution.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ class DependencyResolution private[sbt] (lmEngine: DependencyResolutionInterface
198198
}
199199
}
200200

201+
/**
202+
* Returns a new copy of DependencyResolutionInterface which contains the added resolvers.
203+
* Useful for when you have resolvers that are outside the context of an sbt scope/project
204+
* (i.e. a standalone setting)
205+
*
206+
* @param resolvers The resolvers to add
207+
* @param log The logger
208+
* @return A copy of DependencyResolutionInterface which contains the added resolvers
209+
*/
210+
def withAddedResolvers(resolvers: Seq[Resolver], log: Logger): DependencyResolutionInterface =
211+
lmEngine.withAddedResolvers(resolvers, log)
212+
201213
protected def directDependenciesNames(module: ModuleDescriptor): String =
202214
(module.directDependencies map { case mID: ModuleID =>
203215
import mID._

core/src/main/scala/sbt/librarymanagement/LibraryManagementInterface.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ trait DependencyResolutionInterface {
3232
uwconfig: UnresolvedWarningConfiguration,
3333
log: Logger
3434
): Either[UnresolvedWarning, UpdateReport]
35+
36+
/**
37+
* Returns a new copy of DependencyResolutionInterface which contains the added resolvers.
38+
* Useful for when you have resolvers that are outside the context of an sbt scope/project
39+
* (i.e. a standalone setting)
40+
* @param resolvers The resolvers to add
41+
* @param log The logger
42+
* @return A copy of DependencyResolutionInterface which contains the added resolvers
43+
*/
44+
def withAddedResolvers(resolvers: Seq[Resolver], log: Logger): DependencyResolutionInterface
3545
}
3646

3747
/**

ivy/src/main/scala/sbt/librarymanagement/ivy/IvyDependencyResolution.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ class IvyDependencyResolution private[sbt] (val ivySbt: IvySbt)
2121
): Either[UnresolvedWarning, UpdateReport] =
2222
IvyActions.updateEither(toModule(module), configuration, uwconfig, log)
2323

24+
override def withAddedResolvers(
25+
resolvers: Seq[Resolver],
26+
log: Logger
27+
): IvyDependencyResolution = {
28+
val newConfiguration = ivySbt.configuration match {
29+
case configuration: ExternalIvyConfiguration =>
30+
configuration.withExtraResolvers(configuration.extraResolvers ++ resolvers)
31+
case configuration: InlineIvyConfiguration =>
32+
configuration.withResolvers(configuration.resolvers ++ resolvers)
33+
}
34+
new IvyDependencyResolution(new IvySbt(newConfiguration))
35+
}
36+
2437
private[sbt] def toModule(module: ModuleDescriptor): Module =
2538
module match {
2639
case m: Module @unchecked => m

0 commit comments

Comments
 (0)