Skip to content

Feature Request: constraints support #1222

@plobsing

Description

@plobsing

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions