-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BOM / dependency management support (#3924)
This PR adds support for user-specified BOMs and dependency management in Mill. BOM support allows users to pass the coordinates of an existing Maven "Bill of Material" (BOM), such as [this one](https://repo1.maven.org/maven2/io/quarkus/quarkus-bom/3.17.0/quarkus-bom-3.17.0.pom), that contains versions of dependencies, meant to override those pulled during dependency resolution. (They can also add exclusions to dependencies.) ```scala def bomDeps = Agg( ivy"io.quarkus:quarkus-bom:3.17.0" ) ``` It also allows users to specify the coordinates of a parent POM, which are taken into account just like a BOM: ```scala def parentDep = ivy"org.apache.spark::spark-parent:3.5.3" ``` (in line with `PublishModule#pomParentProject` that's been added recently) It allows users to specify "dependency management", which act like the dependencies listed in a BOM: versions in dependency management override those pulled transitively during dependency resolution, and exclusions in its dependencies are added to the same dependencies during dependency resolution. ```scala def dependencyManagement = Agg( ivy"com.google.protobuf:protobuf-java:4.28.3", ivy"org.java-websocket:Java-WebSocket:_" // placeholder version - this one only adds exclusions, no version override .exclude(("org.slf4j", "slf4j-api")) ) ``` BOM and dependency management also allow for "placeholder" versions: users can use `_` as version in their `ivyDeps`, and the version of that dependency will be picked either in dependency management or in BOMs: ```scala def bomDeps = Agg( ivy"com.google.cloud:libraries-bom:26.50.0" ) def ivyDeps = Agg( ivy"com.google.protobuf:protobuf-java:_" ) ``` A tricky aspect of that PR is that details about BOMs and dependency management have to be passed around via several paths: - in the current module: BOMs and dependency management have to be taken into account during dependency resolution of the module they're added to - via `moduleDeps`: BOMs and dependency management of module dependencies have to be applied to the dependencies of the module they come from - ~to transitive modules pulled via `moduleDeps`: BOMs and dependency management of a module dependency have to be applied to the dependencies of modules they pull transitively (if A depends on B and B depends on C, from A, the BOMs and dep mgmt of B apply to C's dependencies too)~ (worked out-of-the-box with the previous point, via `transitiveIvyDeps`) - via `ivy.xml`: when publishing to Ivy repositories (like during `pubishLocal`), BOMs and dep mgmt details need to be written in the `ivy.xml` file, so that they're taken into account when resolving that module from the Ivy repo - via POM files: when publishing to Maven repositories, BOMs and dep mgmt details need to be written to POMs, so that they're taken into account when resolving that module from the Maven repo Fixes #1975
- Loading branch information
1 parent
50deaaa
commit 60e6ce2
Showing
16 changed files
with
988 additions
and
42 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
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
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
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
25 changes: 25 additions & 0 deletions
25
example/fundamentals/library-deps/bom-1-external-bom/build.mill
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,25 @@ | ||
// Pass an external BOM to a `JavaModule` / `ScalaModule` / `KotlinModule` with `bomDeps`, like | ||
|
||
//// SNIPPET:BUILD1 | ||
package build | ||
import mill._, javalib._ | ||
|
||
object foo extends JavaModule { | ||
def bomDeps = Agg( | ||
ivy"com.google.cloud:libraries-bom:26.50.0" | ||
) | ||
def ivyDeps = Agg( | ||
ivy"io.grpc:grpc-protobuf" | ||
) | ||
} | ||
|
||
// The version of grpc-protobuf (`io.grpc:grpc-protobuf`) isn't written down here, so the version | ||
// from the BOM, `1.67.1` is used. | ||
// | ||
// Also, by default, grpc-protobuf `1.67.1` pulls version `3.25.3` of protobuf-java (`com.google.protobuf:protobuf-java`) . | ||
// But the BOM specifies another version for that dependency, `4.28.3`, so | ||
// protobuf-java `4.28.3` ends up being pulled here. | ||
// | ||
// Several BOMs can be passed to `bomDeps`. If several specify a version for a dependency, | ||
// the version from the first one in the `bomDeps` list is used. If several specify exclusions | ||
// for a dependency, all exclusions are added to that dependency. |
54 changes: 54 additions & 0 deletions
54
example/fundamentals/library-deps/bom-2-dependency-management/build.mill
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,54 @@ | ||
// Pass dependencies to `depManagement` in a `JavaModule` / `ScalaModule` / `KotlinModule`, like | ||
|
||
//// SNIPPET:BUILD1 | ||
package build | ||
import mill._, javalib._ | ||
|
||
object foo extends JavaModule { | ||
def depManagement = Agg( | ||
ivy"com.google.protobuf:protobuf-java:4.28.3", | ||
ivy"io.grpc:grpc-protobuf:1.67.1" | ||
) | ||
def ivyDeps = Agg( | ||
ivy"io.grpc:grpc-protobuf" | ||
) | ||
} | ||
|
||
// The version of grpc-protobuf (`io.grpc:grpc-protobuf`) isn't written down here, so the version | ||
// found in `depManagement`, `1.67.1` is used. | ||
// | ||
// Also, by default, grpc-protobuf `1.67.1` pulls version `3.25.3` of protobuf-java (`com.google.protobuf:protobuf-java`) . | ||
// But `depManagement` specifies another version for that dependency, `4.28.3`, so | ||
// protobuf-java `4.28.3` ends up being pulled here. | ||
|
||
// One can also add exclusions via dependency management, like | ||
|
||
object bar extends JavaModule { | ||
def depManagement = Agg( | ||
ivy"io.grpc:grpc-protobuf:1.67.1" | ||
.exclude(("com.google.protobuf", "protobuf-java")) | ||
) | ||
def ivyDeps = Agg( | ||
ivy"io.grpc:grpc-protobuf" | ||
) | ||
} | ||
|
||
// Here, grpc-protobuf has an empty version in `ivyDeps`, so the one in `depManagement`, | ||
// `1.67.1`, is used. Also, `com.google.protobuf:protobuf-java` is excluded from grpc-protobuf | ||
// in `depManagement`, so it ends up being excluded from it in `ivyDeps` too. | ||
|
||
// If one wants to add exclusions via `depManagement`, specifying a version is optional, | ||
// like | ||
|
||
object baz extends JavaModule { | ||
def depManagement = Agg( | ||
ivy"io.grpc:grpc-protobuf" | ||
.exclude(("com.google.protobuf", "protobuf-java")) | ||
) | ||
def ivyDeps = Agg( | ||
ivy"io.grpc:grpc-protobuf:1.67.1" | ||
) | ||
} | ||
|
||
// Here, given that grpc-protobuf is fetched during dependency resolution, | ||
// `com.google.protobuf:protobuf-java` is excluded from it because of the dependency management. |
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
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
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
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
Oops, something went wrong.