rules_jvm_external icon indicating copy to clipboard operation
rules_jvm_external copied to clipboard

Feature Request: constraints support

Open plobsing opened this issue 1 year ago • 1 comments

Using multiple maven_install declarations for isolated artifact version trees is awesome; it makes some hard things a lot easier. But there's a catch: the setup is not protected from mixing artifacts across different artifact trees. Users need to be diligent in ensuring that only one deps tree is in the transitive dependencies of a java_binary, or it is possible that incompatibly-versioned libraries may get used together.

One way this problem could be avoided is if the jvm_import targets declared by rules_jvm_external could have platform constraints attached. I think it would be sufficient to have one constraint spec for an entire maven_install repo; I don't think it'd need to be more granular. Going back to the README's example, that might look something like:

  maven_install(
      name = "server_app",
      artifacts = [
          "com.google.guava:guava:27.0-jre",
      ],
      repositories = [
          "https://repo1.maven.org/maven2",
      ],
+     targets_compatible_with = ["@platforms//os:linux"],
  )
  
  maven_install(
      name = "android_app",
      artifacts = [
          "com.google.guava:guava:27.0-android",
      ],
      repositories = [
          "https://repo1.maven.org/maven2",
      ],
+     targets_compatible_with = ["@platforms//os:android"],
  )

And then callers could be certain that they only used dependencies from @android_app when building for Android and only used dependencies from @server_app when building for the server.

plobsing avatar Aug 27 '24 06:08 plobsing

Thanks, this is a very reasonable idea, and I like that it builds on top of existing mechanisms. Happy to take PRs for this.

Related: https://github.com/bazelbuild/bazel-worker-api/issues/7

jin avatar Dec 11 '24 11:12 jin