-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
Use api instead of compile for Android #3154
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
The direct analogous is |
I signed it! |
CLAs look good, thanks! |
@JakeWharton I thought it was the other way round? Isn't |
@JakeWharton Wait, I'm challenging myself now. I realise that I'm not 100% clear on the difference between |
No. Compile transitively exposes the dependency on the classpath of
downstream modules which is the same as api. Implementation hides the
dependency. Of course Gradle doesn't enforce or validate any of this so
it's a giant footgun unless you know what you're doing.
…On Wed, May 23, 2018 at 5:06 PM Jonathan Bluett-Duncan < ***@***.***> wrote:
@JakeWharton <https://github.com/JakeWharton> I thought it was the other
way round? Isn't implementation the same as compile, with api being the
optimisation? :/
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3154 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEQr2oPYUNU7S_Elfe1CRqzOecLqzks5t1c9OgaJpZM4ULLig>
.
|
|
(Found https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation to back up Jake.) |
Hmm, so should we change the JRE one to |
I believe 'api' only exists for JRE projects if you're using the
'java-library' plugin. If you're using the regular 'java' plugin you only
get 'compile' and 'implementation' (the idea being you're a leaf node and
don't have anywhere to expose dependencies to).
…On Wed, May 23, 2018 at 5:21 PM Chris Povirk ***@***.***> wrote:
Hmm, so should we change the JRE one to api, as well? It sounds like
compile may be deprecated.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3154 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEdtfVy2mpf-Lvk32inHC4veUluBBks5t1dLdgaJpZM4ULLig>
.
|
@cpovirk |
Huh. So is the idea that Android projects are more likely to use the java-library plugin? If anything, I might have naively guessed they were less likely :) Is it just that the default Android build setup suggests java-library or something? |
Android projects use neither. API and implementation are available for all
Android plugins for about a year now. The reason these PRs are sweeping the
web is that they now wan when you use compile.
…On Wed, May 23, 2018, 5:25 PM Chris Povirk ***@***.***> wrote:
Huh. So is the idea that Android projects are more likely to use the
java-library plugin? If anything, I might have naively guessed they were
*less* likely :) Is it just that the default Android build setup suggests
java-library or something?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3154 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEcpsROIWL_DcsNPdWgCua0QkTdbQks5t1dO6gaJpZM4ULLig>
.
|
Ah! Thanks. |
Hmm. It sounds to me that |
Your understanding is correct because you understand the implications.
Anyone who needs to look at the README to figure out how to add Guava
beyond maybe just copy/pasting the coordinates will not have that
understanding.
…On Wed, May 23, 2018 at 5:35 PM Jonathan Bluett-Duncan < ***@***.***> wrote:
Hmm. It sounds to me that implementation is the most sensible default,
and api should be used only if the java-library plugin is imported *and*
the given project wants to expose Guava types to its users. Is my
understanding correct @JakeWharton <https://github.com/JakeWharton>?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3154 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEQZJ1WltcLH-FZJ78-iTVPVWmCWeks5t1dYogaJpZM4ULLig>
.
|
@JakeWharton Cool! So you're suggesting |
(Even for people who don't expose Guava in their APIs, I'd be a little nervous about excluding transitive dependencies from the classpath, given problems with static analyzers and perhaps annotation processors discussed in #2824 and #2721. (There could also be problems if people use Guava annotations but don't consider that "exposing an API," but that seems less likely.) I suppose that those problems are relatively unlikely to affect people, though.) |
Anyway, I do like the idea of suggesting the thing that is more likely to work (even if it's slower in some cases -- and I suspect only marginally so, since Guava isn't going to be changing between one build and the next). It is a little sad that this exports Guava to downstream targets, but that seems like the lesser evil (and no worse than what people see today). One final thought: We could decide to give instructions for each of...
...where the Java 7 instructions look like the current Android instructions and the Android instructions look like your new ones. But I'm not sure that's worth the potential confusion. |
Fixes #3154 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=197947742
Fixes #3154 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=197947742
@cpovirk I think it's worth at least changing the remaining |
@jbduncan, @JakeWharton said above:
So I worry that Does Gradle warn about |
@cpovirk Good point about @JakeWharton's comment! Gradle does warn about Taking all this into consideration, I think the best advice to give Gradle users is something like the following:
But having said this, the example advice I give above is quite verbose. I wonder if there's a better way of presenting it to Gradle&Guava users... |
No description provided.