Skip to content

Commit da8eec2

Browse files
authored
Merge pull request #8 from tindzk/feat/resolve-full-deps
Expose artefact version tag in TOML build file
2 parents a5fa2cc + da1e333 commit da8eec2

17 files changed

+261
-202
lines changed

Diff for: .gitignore

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
.idea/
21
.bloop/
3-
build/
42
target/
5-
project/target/
6-
test/
3+
/.idea/
4+
/build/
5+
/test/

Diff for: README.md

+20
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,26 @@ scalaDeps = [
357357
]
358358
```
359359

360+
On `scalaDeps`, you can specify a fourth parameter for the version tag. The version tag is the actual difference between a Java and Scala dependency.
361+
362+
The Scala naming conventions stipulate that a suffix be added to the artefact name. Thus, `scalaj-http` becomes [`scalaj-http_2.12`](http://central.maven.org/maven2/org/scalaj/scalaj-http_2.12/).
363+
364+
The previous example could be rewritten as:
365+
366+
```toml
367+
scalaDeps = [
368+
["org.scalaj", "scalaj-http", "2.4.1", "platformBinary"]
369+
]
370+
```
371+
372+
The default is `platformBinary` which will suit most libraries. However, some libraries target a specific compiler version or share one artefact with all platforms.
373+
374+
The available options are:
375+
376+
* `binary`: Binary Scala version (e.g. 2.12). This behaves like `full` if the Scala version is a pre-release (e.g. `2.12.8-M3`)
377+
* `full`: Full Scala version (e.g. `2.11.11`)
378+
* `platformBinary`: Platform name including the binary Scala version (`native0.3_2.11`)
379+
360380
`scalaDeps` only works with Scala artefacts. For all other artefacts, you can use `javaDeps`:
361381

362382
```toml

Diff for: src/main/scala/seed/artefact/ArtefactResolution.scala

+54-81
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,51 @@ import java.nio.file.Path
55
import seed.Cli.PackageConfig
66
import MavenCentral.{CompilerVersion, PlatformVersion}
77
import seed.cli.util.Ansi
8-
import seed.model.Artefact.PlatformSuffix
9-
import seed.model.Build.{Dep, Module}
8+
import seed.model.Build.{Dep, JavaDep, Module, ScalaDep}
109
import seed.model.Platform.{JVM, JavaScript, Native}
1110
import seed.model.{Artefact, Build, Platform, Resolution}
1211
import seed.Log
1312
import seed.config.BuildConfig
1413

1514
object ArtefactResolution {
16-
def dependencyFromDep(dep: Dep,
17-
platform: Platform,
18-
platformVersion: PlatformVersion,
19-
compilerVersion: CompilerVersion,
20-
platformSuffix: PlatformSuffix = PlatformSuffix.PlatformAndCompiler
21-
): Dep =
22-
Dep(
15+
def javaDepFromScalaDep(dep: ScalaDep,
16+
platform: Platform,
17+
platformVersion: PlatformVersion,
18+
compilerVersion: CompilerVersion
19+
): JavaDep =
20+
JavaDep(
2321
dep.organisation,
2422
MavenCentral.formatArtefactName(
25-
Artefact(dep.organisation, dep.artefact, platformSuffix), platform,
26-
platformVersion, compilerVersion
23+
dep.artefact, dep.versionTag, platform, platformVersion, compilerVersion
2724
), dep.version)
2825

29-
def dependencyFromArtefact(artefact: Artefact,
30-
version: String,
31-
platform: Platform,
32-
platformVersion: PlatformVersion,
33-
compilerVersion: CompilerVersion): Dep =
34-
Dep(
26+
def javaDepFromArtefact(artefact: Artefact,
27+
version: String,
28+
platform: Platform,
29+
platformVersion: PlatformVersion,
30+
compilerVersion: CompilerVersion
31+
): JavaDep =
32+
JavaDep(
3533
artefact.organisation,
36-
MavenCentral.formatArtefactName(
37-
artefact, platform, platformVersion, compilerVersion),
38-
version)
34+
artefact.versionTag.fold(artefact.name)(vt =>
35+
MavenCentral.formatArtefactName(artefact.name, vt, platform,
36+
platformVersion, compilerVersion)
37+
), version)
3938

40-
def jsPlatformDeps(build: Build, module: Module): Set[Dep] = {
39+
def jsPlatformDeps(build: Build, module: Module): Set[JavaDep] = {
4140
val scalaVersion = BuildConfig.scalaVersion(build.project, List(module))
4241
val scalaJsVersion = build.project.scalaJsVersion.get
4342

4443
Set(
4544
Artefact.ScalaJsCompiler,
4645
Artefact.ScalaJsLibrary
4746
).map(artefact =>
48-
dependencyFromArtefact(artefact, scalaJsVersion, JavaScript,
47+
javaDepFromArtefact(artefact, scalaJsVersion, JavaScript,
4948
scalaJsVersion, scalaVersion)
5049
)
5150
}
5251

53-
def nativePlatformDeps(build: Build, module: Module): Set[Dep] = {
52+
def nativePlatformDeps(build: Build, module: Module): Set[JavaDep] = {
5453
val scalaVersion = BuildConfig.scalaVersion(build.project, List(module))
5554
val scalaNativeVersion = build.project.scalaNativeVersion.get
5655

@@ -61,78 +60,52 @@ object ArtefactResolution {
6160
Artefact.ScalaNativeNativelib,
6261
Artefact.ScalaNativeAuxlib
6362
).map(artefact =>
64-
dependencyFromArtefact(artefact, scalaNativeVersion, Native,
63+
javaDepFromArtefact(artefact, scalaNativeVersion, Native,
6564
scalaNativeVersion, scalaVersion)
6665
)
6766
}
6867

69-
def jvmArtefacts(stack: List[Module]): Set[(Platform, Artefact.Versioned)] =
70-
stack.flatMap(_.scalaDeps).map(dep =>
71-
JVM -> Artefact.Versioned(
72-
Artefact(dep.organisation, dep.artefact, PlatformSuffix.PlatformAndCompiler),
73-
dep.version)
74-
).toSet ++
75-
stack.flatMap(_.javaDeps).map(dep =>
76-
JVM -> Artefact.Versioned(
77-
Artefact(dep.organisation, dep.artefact, PlatformSuffix.Regular), dep.version)
78-
).toSet
68+
def jvmArtefacts(stack: List[Module]): Set[(Platform, Dep)] =
69+
stack.flatMap(_.scalaDeps).map(dep => JVM -> dep).toSet ++
70+
stack.flatMap(_.javaDeps).map(dep => JVM -> dep).toSet
7971

80-
def jvmDeps(build: Build, stack: List[Module]): Set[Dep] = {
72+
def jvmDeps(build: Build, stack: List[Module]): Set[JavaDep] = {
8173
val scalaVersion = BuildConfig.scalaVersion(build.project, stack)
8274

8375
stack.flatMap(_.scalaDeps).map(dep =>
84-
dependencyFromArtefact(
85-
Artefact(dep.organisation, dep.artefact, PlatformSuffix.PlatformAndCompiler),
86-
dep.version, JVM, scalaVersion, scalaVersion)
76+
javaDepFromScalaDep(dep, JVM, scalaVersion, scalaVersion)
8777
).toSet ++
88-
stack.flatMap(_.javaDeps).map(dep =>
89-
dependencyFromArtefact(
90-
Artefact(dep.organisation, dep.artefact, PlatformSuffix.Regular),
91-
dep.version, JVM, scalaVersion, scalaVersion)
92-
).toSet
78+
stack.flatMap(_.javaDeps).toSet
9379
}
9480

95-
def jsArtefacts(stack: List[Module]): Set[(Platform, Artefact.Versioned)] =
96-
stack.flatMap(_.scalaDeps).map(dep =>
97-
JavaScript ->
98-
Artefact.Versioned(
99-
Artefact(dep.organisation, dep.artefact, PlatformSuffix.PlatformAndCompiler),
100-
dep.version)
101-
).toSet
81+
def jsArtefacts(stack: List[Module]): Set[(Platform, Dep)] =
82+
stack.flatMap(_.scalaDeps).map(dep => JavaScript -> dep).toSet
10283

103-
def jsDeps(build: Build, stack: List[Module]): Set[Dep] =
84+
def jsDeps(build: Build, stack: List[Module]): Set[JavaDep] =
10485
build.project.scalaJsVersion match {
10586
case None => Set()
10687
case Some(scalaJsVersion) =>
10788
val scalaVersion = BuildConfig.scalaVersion(build.project, stack)
10889
stack.flatMap(_.scalaDeps).map(dep =>
109-
dependencyFromArtefact(
110-
Artefact(dep.organisation, dep.artefact, PlatformSuffix.PlatformAndCompiler),
111-
dep.version, JavaScript, scalaJsVersion, scalaVersion)
90+
javaDepFromScalaDep(dep, JavaScript, scalaJsVersion, scalaVersion)
11291
).toSet
11392
}
11493

115-
def nativeArtefacts(stack: List[Module]): Set[(Platform, Artefact.Versioned)] =
116-
stack.flatMap(_.scalaDeps).map(dep =>
117-
Native -> Artefact.Versioned(
118-
Artefact(dep.organisation, dep.artefact, PlatformSuffix.PlatformAndCompiler),
119-
dep.version)
120-
).toSet
94+
def nativeArtefacts(stack: List[Module]): Set[(Platform, Dep)] =
95+
stack.flatMap(_.scalaDeps).map(dep => Native -> dep).toSet
12196

122-
def nativeDeps(build: Build, stack: List[Module]): Set[Dep] =
97+
def nativeDeps(build: Build, stack: List[Module]): Set[JavaDep] =
12398
build.project.scalaNativeVersion match {
12499
case None => Set()
125100
case Some(scalaNativeVersion) =>
126101
val scalaVersion = BuildConfig.scalaVersion(build.project, stack)
127102
stack.flatMap(_.scalaDeps).map(dep =>
128-
dependencyFromArtefact(
129-
Artefact(dep.organisation, dep.artefact, PlatformSuffix.PlatformAndCompiler),
130-
dep.version, Native, scalaNativeVersion, scalaVersion)
103+
javaDepFromScalaDep(dep, Native, scalaNativeVersion, scalaVersion)
131104
).toSet
132105
}
133106

134-
def compilerDeps(build: Build, module: Module): List[Set[Dep]] = {
135-
def f(build: Build, module: Module): Set[Dep] = {
107+
def compilerDeps(build: Build, module: Module): List[Set[JavaDep]] = {
108+
def f(build: Build, module: Module): Set[JavaDep] = {
136109
import build.project.scalaOrganisation
137110
val scalaVersion = BuildConfig.scalaVersion(build.project, List(module))
138111

@@ -141,7 +114,7 @@ object ArtefactResolution {
141114
Artefact.scalaLibrary(scalaOrganisation),
142115
Artefact.scalaReflect(scalaOrganisation)
143116
).map(artefact =>
144-
dependencyFromArtefact(artefact, scalaVersion, JVM, scalaVersion,
117+
javaDepFromArtefact(artefact, scalaVersion, JVM, scalaVersion,
145118
scalaVersion))
146119
}
147120

@@ -153,23 +126,23 @@ object ArtefactResolution {
153126
).filter(_.nonEmpty)
154127
}
155128

156-
def allCompilerDeps(build: Build): List[Set[Dep]] =
129+
def allCompilerDeps(build: Build): List[Set[JavaDep]] =
157130
build.module.values.toList.flatMap(compilerDeps(build, _)).distinct
158131

159-
def platformDeps(build: Build, module: Module): Set[Dep] =
132+
def platformDeps(build: Build, module: Module): Set[JavaDep] =
160133
module.targets.toSet[Platform].flatMap { target =>
161134
if (target == JavaScript)
162135
jsPlatformDeps(build, module.js.getOrElse(Module()))
163136
else if (target == Native) nativePlatformDeps(build,
164137
module.native.getOrElse(Module()))
165-
else Set[Dep]()
138+
else Set[JavaDep]()
166139
}
167140

168141
def libraryDeps(build: Build,
169142
module: Module,
170143
platforms: Set[Platform],
171144
parent: Module = Module()
172-
): Set[Dep] = {
145+
): Set[JavaDep] = {
173146
val targets = if (module.targets.isEmpty) parent.targets else module.targets
174147
targets.toSet[Platform].intersect(platforms).flatMap { target =>
175148
// Shared libraries
@@ -200,7 +173,7 @@ object ArtefactResolution {
200173
def libraryArtefacts(build: Build,
201174
module: Module,
202175
parent: Module = Module()
203-
): Set[(Platform, Artefact.Versioned)] =
176+
): Set[(Platform, Dep)] =
204177
module.targets.toSet[Platform].flatMap { target =>
205178
if (target == JVM) jvmArtefacts(List(module, parent))
206179
else if (target == JavaScript) jsArtefacts(List(module, parent))
@@ -215,15 +188,15 @@ object ArtefactResolution {
215188
List(native, parent.native.getOrElse(Module()), module))) ++
216189
module.test.toSet.flatMap(libraryArtefacts(build, _, module))
217190

218-
def allPlatformDeps(build: Build): Set[Dep] =
191+
def allPlatformDeps(build: Build): Set[JavaDep] =
219192
build.module.values.toSet.flatMap(platformDeps(build, _))
220193

221194
def allLibraryDeps(build: Build,
222195
platforms: Set[Platform] = Set(JVM, JavaScript, Native)
223-
): Set[Dep] =
196+
): Set[JavaDep] =
224197
build.module.values.toSet.flatMap(libraryDeps(build, _, platforms))
225198

226-
def allLibraryArtefacts(build: Build): Map[Platform, Set[Artefact.Versioned]] =
199+
def allLibraryArtefacts(build: Build): Map[Platform, Set[Dep]] =
227200
build.module.values.toSet.flatMap(libraryArtefacts(build, _))
228201
.groupBy(_._1)
229202
.mapValues(_.map(_._2))
@@ -233,9 +206,9 @@ object ArtefactResolution {
233206
scalaVersion: String,
234207
classPath: List[Path]
235208
): Resolution.ScalaCompiler = {
236-
val compilerDep = Dep(scalaOrganisation, "scala-compiler", scalaVersion)
237-
val libraryDep = Dep(scalaOrganisation, "scala-library", scalaVersion)
238-
val reflectDep = Dep(scalaOrganisation, "scala-reflect", scalaVersion)
209+
val compilerDep = JavaDep(scalaOrganisation, "scala-compiler", scalaVersion)
210+
val libraryDep = JavaDep(scalaOrganisation, "scala-library", scalaVersion)
211+
val reflectDep = JavaDep(scalaOrganisation, "scala-reflect", scalaVersion)
239212

240213
val resolution = resolutionResult.find(r =>
241214
Coursier.hasDep(r, compilerDep)).get
@@ -265,8 +238,8 @@ object ArtefactResolution {
265238
build: Build,
266239
packageConfig: PackageConfig,
267240
optionalArtefacts: Boolean,
268-
platformDeps: Set[Dep],
269-
compilerDeps: List[Set[Dep]],
241+
platformDeps: Set[JavaDep],
242+
compilerDeps: List[Set[JavaDep]],
270243
) = {
271244
val silent = packageConfig.silent || seedConfig.resolution.silent
272245
if (!silent) Coursier.initLogger()
@@ -281,7 +254,7 @@ object ArtefactResolution {
281254
build.resolvers.ivy.foreach(ivy => Log.info(" - " + Ansi.italic(ivy.url) + " (Ivy)"))
282255
build.resolvers.maven.foreach(maven => Log.info(" - " + Ansi.italic(maven) + " (Maven)"))
283256

284-
def resolve(deps: Set[Dep]) =
257+
def resolve(deps: Set[JavaDep]) =
285258
Coursier.resolveAndDownload(deps, build.resolvers, resolvedIvyPath,
286259
resolvedCachePath, optionalArtefacts)
287260

Diff for: src/main/scala/seed/artefact/Coursier.scala

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import coursier.ivy.IvyRepository
1010
import coursier.util.{Gather, Task}
1111
import coursier.{Artifact, Cache, CachePath, Dependency, Fetch, MavenRepository, Module, Resolution, TermDisplay}
1212
import seed.cli.util.Ansi
13-
import seed.model.Build.{Dep, Resolvers}
13+
import seed.model.Build.{JavaDep, Resolvers}
1414
import seed.model.Platform
1515
import seed.{Log, model}
1616

@@ -37,18 +37,18 @@ object Coursier {
3737
logger = Some(termDisplay)
3838
}
3939

40-
def hasDep(resolutionResult: Coursier.ResolutionResult, dep: Dep): Boolean =
40+
def hasDep(resolutionResult: Coursier.ResolutionResult, dep: JavaDep): Boolean =
4141
resolutionResult.resolution.dependencies.exists(d =>
4242
d.module.organization.value == dep.organisation &&
4343
d.module.name.value == dep.artefact &&
4444
d.version == dep.version)
4545

46-
def coursierDependencies(deps: Set[Dep]): Set[Dependency] =
46+
def coursierDependencies(deps: Set[JavaDep]): Set[Dependency] =
4747
deps.map(r => Dependency(Module(Organization(r.organisation), ModuleName(r.artefact)), r.version))
4848

4949
private val lock = new ReentrantLock()
5050

51-
def resolve(all: Set[Dep], resolvers: Resolvers, ivyPath: Path, cachePath: Path): Resolution =
51+
def resolve(all: Set[JavaDep], resolvers: Resolvers, ivyPath: Path, cachePath: Path): Resolution =
5252
if (all.isEmpty) Resolution.empty
5353
else {
5454
val organisations = all.map(_.organisation).toList.sorted.map(Ansi.italic).mkString(", ")
@@ -113,7 +113,7 @@ object Coursier {
113113
}
114114
}
115115

116-
def resolveAndDownload(deps: Set[Dep],
116+
def resolveAndDownload(deps: Set[JavaDep],
117117
resolvers: Resolvers,
118118
ivyPath: Path,
119119
cachePath: Path,
@@ -131,7 +131,7 @@ object Coursier {
131131
}
132132

133133
def resolveSubset(resolution: Resolution,
134-
deps: Set[Dep],
134+
deps: Set[JavaDep],
135135
optionalArtefacts: Boolean): List[(Classifier, Artefact)] = {
136136
val result =
137137
resolution
@@ -157,7 +157,7 @@ object Coursier {
157157

158158
/** Resolves requested libraries and their dependencies */
159159
def localArtefacts(result: ResolutionResult,
160-
all: Set[Dep],
160+
all: Set[JavaDep],
161161
optionalArtefacts: Boolean = false
162162
): List[model.Resolution.Artefact] =
163163
resolveSubset(result.resolution, all, optionalArtefacts)
@@ -184,8 +184,10 @@ object Coursier {
184184
platformVersion: MavenCentral.PlatformVersion,
185185
compilerVersion: MavenCentral.CompilerVersion,
186186
version: String): Option[Path] = {
187-
val name = MavenCentral.formatArtefactName(artefact, platform,
188-
platformVersion, compilerVersion)
187+
val name =
188+
artefact.versionTag.fold(artefact.name)(vt =>
189+
MavenCentral.formatArtefactName(artefact.name, vt, platform,
190+
platformVersion, compilerVersion))
189191

190192
result.resolution.dependencyArtifacts().find { case (dep, attr, art) =>
191193
dep.module.name.value == name

0 commit comments

Comments
 (0)