diff --git a/integration/feature/bom/resources/build.mill b/integration/feature/bom/resources/build.mill index 756b23ecbf2..ba95fce3c43 100644 --- a/integration/feature/bom/resources/build.mill +++ b/integration/feature/bom/resources/build.mill @@ -79,3 +79,12 @@ object depMgmt extends JavaModule with TestPublishModule { ivy"com.google.protobuf:protobuf-java:4.28.3" ) } + +object `version-placeholder` extends JavaModule with TestPublishModule { + def ivyDeps = Agg( + ivy"com.google.protobuf:protobuf-java:_" + ) + override def dependencyManagement = Agg( + ivy"com.google.protobuf:protobuf-java:4.28.3" + ) +} diff --git a/integration/feature/bom/src/BomTests.scala b/integration/feature/bom/src/BomTests.scala index 4db14b14862..1fc81ed5c9d 100644 --- a/integration/feature/bom/src/BomTests.scala +++ b/integration/feature/bom/src/BomTests.scala @@ -144,10 +144,7 @@ object BomTests extends UtestIntegrationTestSuite { test("placeholder") - integrationTest { implicit tester => import tester._ - compileClasspathContains("version-placeholder", expectedProtobufJarName) - - val resolvedCp = publishLocalAndResolve("version-placeholder") - assert(resolvedCp.map(_.last).contains(expectedProtobufJarName)) + isInClassPath("version-placeholder", expectedProtobufJarName) } test("override") - integrationTest { implicit tester => diff --git a/scalalib/src/mill/scalalib/JavaModule.scala b/scalalib/src/mill/scalalib/JavaModule.scala index 049e2755780..0fe0f993505 100644 --- a/scalalib/src/mill/scalalib/JavaModule.scala +++ b/scalalib/src/mill/scalalib/JavaModule.scala @@ -154,8 +154,25 @@ trait JavaModule val depMgmt = dependencyManagementDict() if (depMgmt.isEmpty) depsWithBoms - else - depsWithBoms.map(dep => dep.copy(dep = dep.dep.withOverrides(dep.dep.overrides ++ depMgmt))) + else { + lazy val depMgmtMap = depMgmt.toMap + depsWithBoms.map { dep => + val versionOverride = + if (dep.dep.version == "_") { + val key = DependencyManagement.Key( + dep.dep.module.organization, dep.dep.module.name, coursier.core.Type.jar, dep.dep.publication.classifier + ) + // FIXME Exclusions should be added too + depMgmtMap.get(key).map(_.version) + } + else None + dep.copy( + dep = dep.dep + .withOverrides(dep.dep.overrides ++ depMgmt) + .withVersion(versionOverride.getOrElse(dep.dep.version)) + ) + } + } } /**