Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java_library should allow java_toolchain to be specified per-target #8735

Closed
shs96c opened this issue Jun 27, 2019 · 5 comments
Closed

java_library should allow java_toolchain to be specified per-target #8735

shs96c opened this issue Jun 27, 2019 · 5 comments
Labels
team-Rules-Java Issues for Java rules untriaged

Comments

@shs96c
Copy link
Contributor

shs96c commented Jun 27, 2019

Description of the problem / feature request:

When compiling a complex codebase, it is sometimes useful to have multiple java toolchains in play at the same time. Take, for example, the case where you're building a multi-release jar, and so want most classes to target Java 8. However, you also want to offer features to Java 11 developers. The simplest way to do this would be something like:

java_toolchain(
  name = "java-8",
  source_version = "8",
  target_version = "8",
  ...
)

java_toolchain(
  name = "java-11",
  source_version = "11",
  target_version = "11",
  ...
)

java_library(
  name = "in-all-jars",
  # Ideally this would be set as a default, but added for clarity
  toolchain = ":java-8",
  ...
)

java_library(
  name = "new-java-only",
  toolchain = ":java-11",
  ...
)

Feature requests: what underlying problem are you trying to solve with this feature?

The ability to cleanly mix different versions of Java without accidentally depending on classes from later releases in code targeting earlier releases.

What's the output of bazel info release?

release 0.26.1

Have you found anything relevant by searching the web?

It may be possible to emulate much of the desired behaviour using the javacopts parameter of java_library, but that's a gross and ugly hack, and we should not stand for it.

Buck had a (poorly documented, hard to find) feature where it could set the bootclasspath depending on the selected target version of the java library being compiled. You can see a reference to it here

@shs96c shs96c changed the title java_library should allow java_toolchain to be specified java_library should allow java_toolchain to be specified per-target Jun 27, 2019
@dslomov dslomov added team-Rules-Java Issues for Java rules untriaged labels Jun 27, 2019
@iirina
Copy link
Contributor

iirina commented Jul 3, 2019

@shs96c Thanks for the report! We are currently migrating the Java rules to platforms & toolchains (#6521).

There are plans to enable out of the box support for building different targets with different toolchains in the same build (see #6519 and Configurability 2019 Roadmap - flagless multiplatform builds).

There is another way to accomplish this by implementing a configuration transition manually. See more at User-defined Transitions.

I'll close this as duplicate of #6519. Let me know if there is anything I can help with at the moment.

@Globegitter
Copy link

#7572 is also very much related and I suppose possibly so a duplicate of #6519 then.

@smparkes
Copy link
Contributor

@iirina, with respect to

There is another way to accomplish this by implementing a configuration transition manually. See more at User-defined Transitions.
Transitions are only available on the rule level, correct? So this would require a new rule instead of a rule attribute?

@dsilvasc
Copy link

There are plans to enable out of the box support for building different targets with different toolchains in the same build (see #6519 and Configurability 2019 Roadmap - flagless multiplatform builds).

Were those plans canceled? That item is listed in the 2019 roadmap as not started and not listed in the 2020 roadmap.

@vincyyou
Copy link

6519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-Java Issues for Java rules untriaged
Projects
None yet
Development

No branches or pull requests

7 participants