diff --git a/scalalib/src/mill/scalalib/AssemblyModule.scala b/scalalib/src/mill/scalalib/AssemblyModule.scala index 7ba19d81a54..6cddd9fb240 100644 --- a/scalalib/src/mill/scalalib/AssemblyModule.scala +++ b/scalalib/src/mill/scalalib/AssemblyModule.scala @@ -63,15 +63,44 @@ trait AssemblyModule extends mill.Module { private[mill] def assemblyRules0: Seq[Assembly.Rule] = Assembly.defaultRules + /** + * Upstream classfiles and resources from third-party libraries + * necessary to build an executable assembly + */ + def upstreamIvyAssemblyClasspath: T[Agg[PathRef]] = Agg.empty[PathRef] + + /** + * Upstream classfiles and resources from locally-built modules + * necessary to build an executable assembly, but without this module's contribution + */ + def upstreamLocalAssemblyClasspath: T[Agg[PathRef]] = upstreamAssemblyClasspath() + def upstreamAssemblyClasspath: T[Agg[PathRef]] def localClasspath: T[Seq[PathRef]] + /** + * Build the assembly for third-party dependencies separate from the current + * classpath + * + * This should allow much faster assembly creation in the common case where + * third-party dependencies do not change + */ + def resolvedIvyAssembly: T[Assembly] = Task { + Assembly.create( + destJar = Task.dest / "out.jar", + inputPaths = upstreamIvyAssemblyClasspath().map(_.path), + manifest = manifest(), + assemblyRules = assemblyRules + ) + } + private[mill] def upstreamAssembly2_0: T[Assembly] = Task { Assembly.create( destJar = Task.dest / "out.jar", - inputPaths = upstreamAssemblyClasspath().map(_.path), + inputPaths = upstreamLocalAssemblyClasspath().map(_.path), manifest = manifest(), + base = Some(resolvedIvyAssembly().pathRef.path), assemblyRules = assemblyRules ) } @@ -112,7 +141,7 @@ trait AssemblyModule extends mill.Module { val problematicEntryCount = 65535 if ( prependScript.isDefined && - (upstream.addedEntries + created.addedEntries) > problematicEntryCount + (resolvedIvyAssembly().addedEntries + upstream.addedEntries + created.addedEntries) > problematicEntryCount ) { Result.Failure( s"""The created assembly jar contains more than ${problematicEntryCount} ZIP entries. diff --git a/scalalib/src/mill/scalalib/JavaModule.scala b/scalalib/src/mill/scalalib/JavaModule.scala index aaff671bb89..441f335ec84 100644 --- a/scalalib/src/mill/scalalib/JavaModule.scala +++ b/scalalib/src/mill/scalalib/JavaModule.scala @@ -1015,6 +1015,14 @@ trait JavaModule ) } + def upstreamIvyAssemblyClasspath: T[Agg[PathRef]] = Task { + resolvedRunIvyDeps() + } + + def upstreamLocalAssemblyClasspath: T[Agg[PathRef]] = Task { + transitiveLocalClasspath() + } + /** * All upstream classfiles and resources necessary to build and executable * assembly, but without this module's contribution