blob: d5bcf555e731d2a5d0bb793a31b0247f354714a3 [file] [log] [blame] [view]
cgdeckerf40d6872016-12-28 11:24:17 -08001# Guava: Google Core Libraries for Java
kevinb@google.com95e8bd22010-04-09 17:02:12 +00002
cgdeckerfffd6a32018-05-25 12:32:08 -07003[![Latest release](https://img.shields.io/github/release/google/guava.svg)](https://github.com/google/guava/releases/latest)
Colin Decker2cc42ec2021-03-16 09:43:15 -07004[![Build Status](https://github.com/google/guava/workflows/CI/badge.svg?branch=master)](https://github.com/google/guava/actions)
Jochen Schalanda124e5732014-11-05 12:32:03 -08005
cpovirk9be29902020-02-12 08:18:00 -08006Guava is a set of core Java libraries from Google that includes new collection types
7(such as multimap and multiset), immutable collections, a graph library, and
8utilities for concurrency, I/O, hashing, caching, primitives, strings, and more! It
9is widely used on most Java projects within Google, and widely used by many
10other companies as well.
vijaykakadiya65c42d92015-01-21 11:51:28 -080011
dpb4d0e0af2017-05-23 08:14:38 -070012Guava comes in two flavors.
13
dpbfb763ee2017-10-02 12:51:35 -070014* The JRE flavor requires JDK 1.8 or higher.
dpb4d0e0af2017-05-23 08:14:38 -070015* If you need support for JDK 1.7 or Android, use the Android flavor. You can
16 find the Android Guava source in the [`android` directory].
17
18[`android` directory]: https://github.com/google/guava/tree/master/android
kevinb@google.com95e8bd22010-04-09 17:02:12 +000019
cgdeckerfffd6a32018-05-25 12:32:08 -070020## Adding Guava to your build
cgdeckera91e6f22015-07-15 11:43:30 -070021
Rohit Potdukhe7afcafb2020-04-21 12:29:15 -070022Guava's Maven group ID is `com.google.guava`, and its artifact ID is `guava`.
cgdeckerfffd6a32018-05-25 12:32:08 -070023Guava provides two different "flavors": one for use on a (Java 8+) JRE and one
24for use on Android or Java 7 or by any library that wants to be compatible with
25either of those. These flavors are specified in the Maven version field as
cpovirkfd945ba2021-09-27 11:43:17 -070026either `31.0.1-jre` or `31.0.1-android`. For more about depending on Guava, see
cpovirkab5b0fa2019-10-25 12:36:53 -070027[using Guava in your build].
cgdeckera91e6f22015-07-15 11:43:30 -070028
29To add a dependency on Guava using Maven, use the following:
30
31```xml
32<dependency>
33 <groupId>com.google.guava</groupId>
34 <artifactId>guava</artifactId>
cpovirkfd945ba2021-09-27 11:43:17 -070035 <version>31.0.1-jre</version>
dpb4d0e0af2017-05-23 08:14:38 -070036 <!-- or, for Android: -->
cpovirkfd945ba2021-09-27 11:43:17 -070037 <version>31.0.1-android</version>
cgdeckera91e6f22015-07-15 11:43:30 -070038</dependency>
39```
40
seabass54dc1b02015-09-21 10:09:38 -070041To add a dependency using Gradle:
42
Elias Ojala4675e302018-08-13 09:06:28 -070043```gradle
seabass54dc1b02015-09-21 10:09:38 -070044dependencies {
Jendrik Johannes3d33cd42019-10-25 12:25:57 -070045 // Pick one:
46
47 // 1. Use Guava in your implementation only:
cpovirkfd945ba2021-09-27 11:43:17 -070048 implementation("com.google.guava:guava:31.0.1-jre")
Jendrik Johannes3d33cd42019-10-25 12:25:57 -070049
50 // 2. Use Guava types in your public API:
cpovirkfd945ba2021-09-27 11:43:17 -070051 api("com.google.guava:guava:31.0.1-jre")
Jendrik Johannes3d33cd42019-10-25 12:25:57 -070052
53 // 3. Android - Use Guava in your implementation only:
cpovirkfd945ba2021-09-27 11:43:17 -070054 implementation("com.google.guava:guava:31.0.1-android")
Jendrik Johannes3d33cd42019-10-25 12:25:57 -070055
56 // 4. Android - Use Guava types in your public API:
cpovirkfd945ba2021-09-27 11:43:17 -070057 api("com.google.guava:guava:31.0.1-android")
seabass54dc1b02015-09-21 10:09:38 -070058}
59```
dpb4d0e0af2017-05-23 08:14:38 -070060
Jendrik Johannes3d33cd42019-10-25 12:25:57 -070061For more information on when to use `api` and when to use `implementation`,
62consult the
63[Gradle documentation on API and implementation separation](https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation).
64
cpovirk9be29902020-02-12 08:18:00 -080065## Snapshots and Documentation
cgdeckera91e6f22015-07-15 11:43:30 -070066
67Snapshots of Guava built from the `master` branch are available through Maven
cgdecker11d36832017-10-03 14:26:37 -070068using version `HEAD-jre-SNAPSHOT`, or `HEAD-android-SNAPSHOT` for the Android
dpb4d0e0af2017-05-23 08:14:38 -070069flavor.
cgdeckera91e6f22015-07-15 11:43:30 -070070
Jendrik Johannes3d33cd42019-10-25 12:25:57 -070071- Snapshot API Docs: [guava][guava-snapshot-api-docs]
72- Snapshot API Diffs: [guava][guava-snapshot-api-diffs]
cgdeckera91e6f22015-07-15 11:43:30 -070073
cgdeckerf40d6872016-12-28 11:24:17 -080074## Learn about Guava
vijaykakadiya65c42d92015-01-21 11:51:28 -080075
Jendrik Johannes3d33cd42019-10-25 12:25:57 -070076- Our users' guide, [Guava Explained]
cpovirkab5b0fa2019-10-25 12:36:53 -070077- [A nice collection](http://www.tfnico.com/presentations/google-guava) of
78 other helpful links
vijaykakadiya65c42d92015-01-21 11:51:28 -080079
cgdeckerf40d6872016-12-28 11:24:17 -080080## Links
kevinb@google.com95e8bd22010-04-09 17:02:12 +000081
Jendrik Johannes3d33cd42019-10-25 12:25:57 -070082- [GitHub project](https://github.com/google/guava)
83- [Issue tracker: Report a defect or feature request](https://github.com/google/guava/issues/new)
84- [StackOverflow: Ask "how-to" and "why-didn't-it-work" questions](https://stackoverflow.com/questions/ask?tags=guava+java)
85- [guava-announce: Announcements of releases and upcoming significant changes](http://groups.google.com/group/guava-announce)
86- [guava-discuss: For open-ended questions and discussion](http://groups.google.com/group/guava-discuss)
kevinb@google.com95e8bd22010-04-09 17:02:12 +000087
cgdeckerf40d6872016-12-28 11:24:17 -080088## IMPORTANT WARNINGS
kevinb@google.com95e8bd22010-04-09 17:02:12 +000089
cpovirkab5b0fa2019-10-25 12:36:53 -0700901. APIs marked with the `@Beta` annotation at the class or method level are
91 subject to change. They can be modified in any way, or even removed, at any
Rohit Potdukhe7afcafb2020-04-21 12:29:15 -070092 time. If your code is a library itself (i.e., it is used on the CLASSPATH of
93 users outside your own control), you should not use beta APIs unless you
cpovirkab5b0fa2019-10-25 12:36:53 -070094 [repackage] them. **If your code is a library, we strongly recommend using
95 the [Guava Beta Checker] to ensure that you do not use any `@Beta` APIs!**
kevinb@google.com95e8bd22010-04-09 17:02:12 +000096
Jendrik Johannes3d33cd42019-10-25 12:25:57 -0700972. APIs without `@Beta` will remain binary-compatible for the indefinite
cpovirkab5b0fa2019-10-25 12:36:53 -070098 future. (Previously, we sometimes removed such APIs after a deprecation
99 period. The last release to remove non-`@Beta` APIs was Guava 21.0.) Even
100 `@Deprecated` APIs will remain (again, unless they are `@Beta`). We have no
101 plans to start removing things again, but officially, we're leaving our
102 options open in case of surprises (like, say, a serious security problem).
guava.mirrorbot@gmail.com509fe0a2010-12-06 18:31:42 +0000103
cpovirk9dfb1112021-03-23 09:20:07 -07001043. Guava has one dependency that is needed for linkage at runtime:
105 `com.google.guava:failureaccess:1.0.1`. It also has
106 [some annotation-only dependencies][guava-deps], which we discuss in more
107 detail at that link.
cgdecker292118d2018-10-18 13:32:32 -0700108
Jendrik Johannes3d33cd42019-10-25 12:25:57 -07001094. Serialized forms of ALL objects are subject to change unless noted
cpovirkab5b0fa2019-10-25 12:36:53 -0700110 otherwise. Do not persist these and assume they can be read by a future
111 version of the library.
kevinb@google.com95e8bd22010-04-09 17:02:12 +0000112
cpovirkab5b0fa2019-10-25 12:36:53 -07001135. Our classes are not designed to protect against a malicious caller. You
114 should not use them for communication between trusted and untrusted code.
fry@google.com3fbaf562011-01-27 19:37:40 +0000115
cpovirkd7f214d2021-03-19 09:36:35 -07001166. For the mainline flavor, we test the libraries using only OpenJDK 8 and
117 OpenJDK 11 on Linux. Some features, especially in `com.google.common.io`,
118 may not work correctly in other environments. For the Android flavor, our
119 unit tests also run on API level 15 (Ice Cream Sandwich).
dpb4d0e0af2017-05-23 08:14:38 -0700120
cpovirkd9348502020-01-24 09:12:39 -0800121[guava-snapshot-api-docs]: https://guava.dev/releases/snapshot-jre/api/docs/
122[guava-snapshot-api-diffs]: https://guava.dev/releases/snapshot-jre/api/diffs/
cgdeckera91e6f22015-07-15 11:43:30 -0700123[Guava Explained]: https://github.com/google/guava/wiki/Home
cgdecker079db392017-12-21 10:29:46 -0800124[Guava Beta Checker]: https://github.com/google/guava-beta-checker
cpovirk08983fb2017-12-08 08:16:19 -0800125
126<!-- References -->
127
cgdeckerfffd6a32018-05-25 12:32:08 -0700128[using Guava in your build]: https://github.com/google/guava/wiki/UseGuavaInYourBuild
cpovirkcabe9702017-12-21 14:44:51 -0800129[repackage]: https://github.com/google/guava/wiki/UseGuavaInYourBuild#what-if-i-want-to-use-beta-apis-from-a-library-that-people-use-as-a-dependency
cpovirk9dfb1112021-03-23 09:20:07 -0700130[guava-deps]: https://github.com/google/guava/wiki/UseGuavaInYourBuild#what-about-guavas-own-dependencies