@@ -128,12 +128,34 @@ trait JavaModule
128
128
/** The compile-only direct dependencies of this module. */
129
129
def compileModuleDeps : Seq [JavaModule ] = Seq .empty
130
130
131
+ /** The direct and indirect dependencies of this module */
132
+ def recursiveModuleDeps : Seq [JavaModule ] = {
133
+ moduleDeps.flatMap(_.transitiveModuleDeps).distinct
134
+ }
135
+
136
+ /**
137
+ * Like `recursiveModuleDeps` but also include the module itself,
138
+ * basically the modules whose classpath are needed at runtime
139
+ */
140
+ def transitiveModuleDeps : Seq [JavaModule ] = Seq (this ) ++ recursiveModuleDeps
141
+
142
+ /**
143
+ * All direct and indirect module dependencies of this module, including
144
+ * compile-only dependencies: basically the modules whose classpath are needed
145
+ * at compile-time.
146
+ *
147
+ * Note that `compileModuleDeps` are defined to be non-transitive, so we only
148
+ * look at the direct `compileModuleDeps` when assembling this list
149
+ */
150
+ def transitiveModuleCompileModuleDeps : Seq [JavaModule ] = {
151
+ (moduleDeps ++ compileModuleDeps).flatMap(_.transitiveModuleDeps).distinct
152
+ }
153
+
131
154
/** The compile-only transitive ivy dependencies of this module and all it's upstream compile-only modules. */
132
155
def transitiveCompileIvyDeps : T [Agg [BoundDep ]] = T {
133
156
// We never include compile-only dependencies transitively, but we must include normal transitive dependencies!
134
- compileIvyDeps().map(bindDependency()) ++ T
135
- .traverse(compileModuleDeps)(_.transitiveIvyDeps)()
136
- .flatten
157
+ compileIvyDeps().map(bindDependency()) ++
158
+ T .traverse(compileModuleDeps)(_.transitiveIvyDeps)().flatten
137
159
}
138
160
139
161
/**
@@ -158,16 +180,6 @@ trait JavaModule
158
180
T .log.outputStream.println(asString)
159
181
}
160
182
161
- /** The direct and indirect dependencies of this module */
162
- def recursiveModuleDeps : Seq [JavaModule ] = {
163
- moduleDeps.flatMap(_.transitiveModuleDeps).distinct
164
- }
165
-
166
- /** Like `recursiveModuleDeps` but also include the module itself */
167
- def transitiveModuleDeps : Seq [JavaModule ] = {
168
- Seq (this ) ++ recursiveModuleDeps
169
- }
170
-
171
183
/**
172
184
* Additional jars, classfiles or resources to add to the classpath directly
173
185
* from disk rather than being downloaded from Maven Central or other package
@@ -180,28 +192,22 @@ trait JavaModule
180
192
* This is calculated from [[ivyDeps ]], [[mandatoryIvyDeps ]] and recursively from [[moduleDeps ]].
181
193
*/
182
194
def transitiveIvyDeps : T [Agg [BoundDep ]] = T {
183
- (ivyDeps() ++ mandatoryIvyDeps()).map(bindDependency()) ++ T .traverse(moduleDeps)(
184
- _.transitiveIvyDeps
185
- )().flatten
195
+ (ivyDeps() ++ mandatoryIvyDeps()).map(bindDependency()) ++
196
+ T .traverse(moduleDeps)(_.transitiveIvyDeps)().flatten
186
197
}
187
198
188
199
/**
189
200
* The upstream compilation output of all this module's upstream modules
190
201
*/
191
202
def upstreamCompileOutput : T [Seq [CompilationResult ]] = T {
192
- T .traverse((recursiveModuleDeps ++ compileModuleDeps.flatMap(
193
- _.transitiveModuleDeps
194
- )).distinct)(_.compile)
203
+ T .traverse(transitiveModuleCompileModuleDeps)(_.compile)
195
204
}
196
205
197
206
/**
198
207
* The transitive version of `localClasspath`
199
208
*/
200
209
def transitiveLocalClasspath : T [Agg [PathRef ]] = T {
201
- T .traverse(
202
- (moduleDeps ++ compileModuleDeps).flatMap(_.transitiveModuleDeps).distinct
203
- )(m => m.localClasspath)()
204
- .flatten
210
+ T .traverse(transitiveModuleCompileModuleDeps)(_.localClasspath)().flatten
205
211
}
206
212
207
213
/**
@@ -210,20 +216,16 @@ trait JavaModule
210
216
// Keep in sync with [[transitiveLocalClasspath]]
211
217
@ internal
212
218
def bspTransitiveLocalClasspath : T [Agg [UnresolvedPath ]] = T {
213
- T .traverse(
214
- (moduleDeps ++ compileModuleDeps).flatMap(_.transitiveModuleDeps).distinct
215
- )(m => m.bspLocalClasspath)()
216
- .flatten
219
+ T .traverse(transitiveModuleCompileModuleDeps)(_.bspLocalClasspath)().flatten
217
220
}
218
221
219
222
/**
220
223
* The transitive version of `compileClasspath`
221
224
*/
222
225
def transitiveCompileClasspath : T [Agg [PathRef ]] = T {
223
- T .traverse(
224
- (moduleDeps ++ compileModuleDeps).flatMap(_.transitiveModuleDeps).distinct
225
- )(m => T .task { m.compileClasspath() ++ Agg (m.compile().classes) })()
226
- .flatten
226
+ T .traverse(transitiveModuleCompileModuleDeps)(m =>
227
+ T .task { m.localCompileClasspath() ++ Agg (m.compile().classes) }
228
+ )().flatten
227
229
}
228
230
229
231
/**
@@ -232,9 +234,7 @@ trait JavaModule
232
234
// Keep in sync with [[transitiveCompileClasspath]]
233
235
@ internal
234
236
def bspTransitiveCompileClasspath : T [Agg [UnresolvedPath ]] = T {
235
- T .traverse(
236
- (moduleDeps ++ compileModuleDeps).flatMap(_.transitiveModuleDeps).distinct
237
- )(m =>
237
+ T .traverse(transitiveModuleCompileModuleDeps)(m =>
238
238
T .task {
239
239
m.bspCompileClasspath() ++ Agg (m.bspCompileClassesPath())
240
240
}
@@ -355,11 +355,11 @@ trait JavaModule
355
355
}
356
356
357
357
/**
358
- * The output classfiles/resources from this module, excluding upstream
359
- * modules and third-party dependencies
358
+ * The * output* classfiles/resources from this module, used for execution,
359
+ * excluding upstream modules and third-party dependencies
360
360
*/
361
361
def localClasspath : T [Seq [PathRef ]] = T {
362
- compileResources() ++ resources() ++ Agg (compile().classes)
362
+ localCompileClasspath().toSeq ++ resources() ++ Agg (compile().classes)
363
363
}
364
364
365
365
/**
@@ -368,9 +368,8 @@ trait JavaModule
368
368
*/
369
369
@ internal
370
370
def bspLocalClasspath : T [Agg [UnresolvedPath ]] = T {
371
- (compileResources() ++ resources()).map(p => UnresolvedPath .ResolvedPath (p.path)) ++ Agg (
372
- bspCompileClassesPath()
373
- )
371
+ (compileResources() ++ resources()).map(p => UnresolvedPath .ResolvedPath (p.path)) ++
372
+ Agg (bspCompileClassesPath())
374
373
}
375
374
376
375
/**
@@ -379,53 +378,51 @@ trait JavaModule
379
378
*/
380
379
// Keep in sync with [[bspCompileClasspath]]
381
380
def compileClasspath : T [Agg [PathRef ]] = T {
382
- transitiveCompileClasspath() ++
383
- compileResources() ++
384
- unmanagedClasspath() ++
385
- resolvedIvyDeps()
381
+ resolvedIvyDeps() ++ transitiveCompileClasspath() ++ localCompileClasspath()
382
+ }
383
+
384
+ /**
385
+ * The *input* classfiles/resources from this module, used during compilation,
386
+ * excluding upstream modules and third-party dependencies
387
+ */
388
+ def localCompileClasspath : T [Agg [PathRef ]] = T {
389
+ compileResources() ++ unmanagedClasspath()
386
390
}
387
391
388
392
/** Same as [[compileClasspath ]], but does not trigger compilation targets, if possible. */
389
393
// Keep in sync with [[compileClasspath]]
390
394
@ internal
391
395
def bspCompileClasspath : T [Agg [UnresolvedPath ]] = T {
392
396
bspTransitiveCompileClasspath() ++
393
- (compileResources() ++ unmanagedClasspath () ++ resolvedIvyDeps())
397
+ (localCompileClasspath () ++ resolvedIvyDeps())
394
398
.map(p => UnresolvedPath .ResolvedPath (p.path))
395
399
}
396
400
397
401
/**
398
402
* Resolved dependencies based on [[transitiveIvyDeps ]] and [[transitiveCompileIvyDeps ]].
399
403
*/
400
404
def resolvedIvyDeps : T [Agg [PathRef ]] = T {
401
- resolveDeps(T .task {
402
- transitiveCompileIvyDeps() ++ transitiveIvyDeps()
403
- })()
405
+ resolveDeps(T .task { transitiveCompileIvyDeps() ++ transitiveIvyDeps() })()
404
406
}
405
407
406
408
/**
407
409
* All upstream classfiles and resources necessary to build and executable
408
410
* assembly, but without this module's contribution
409
411
*/
410
412
def upstreamAssemblyClasspath : T [Agg [PathRef ]] = T {
411
- transitiveLocalClasspath() ++
412
- unmanagedClasspath() ++
413
- resolvedRunIvyDeps()
413
+ resolvedRunIvyDeps() ++ transitiveLocalClasspath()
414
414
}
415
415
416
416
def resolvedRunIvyDeps : T [Agg [PathRef ]] = T {
417
- resolveDeps(T .task {
418
- runIvyDeps().map(bindDependency()) ++ transitiveIvyDeps()
419
- })()
417
+ resolveDeps(T .task { runIvyDeps().map(bindDependency()) ++ transitiveIvyDeps() })()
420
418
}
421
419
422
420
/**
423
421
* All classfiles and resources from upstream modules and dependencies
424
422
* necessary to run this module's code after compilation
425
423
*/
426
424
def runClasspath : T [Seq [PathRef ]] = T {
427
- localClasspath() ++
428
- upstreamAssemblyClasspath()
425
+ resolvedRunIvyDeps().toSeq ++ transitiveLocalClasspath() ++ localClasspath()
429
426
}
430
427
431
428
/**
@@ -470,10 +467,7 @@ trait JavaModule
470
467
* without those from upstream modules and dependencies
471
468
*/
472
469
def jar : T [PathRef ] = T {
473
- Jvm .createJar(
474
- localClasspath().map(_.path).filter(os.exists),
475
- manifest()
476
- )
470
+ Jvm .createJar(localClasspath().map(_.path).filter(os.exists), manifest())
477
471
}
478
472
479
473
/**
0 commit comments