|
1 | 1 | # Guava: Google Core Libraries for Java
|
2 | 2 |
|
3 | 3 | [](https://github.com/google/guava/releases/latest)
|
4 |
| -[](https://travis-ci.org/google/guava) |
| 4 | +[](https://github.com/google/guava/actions) |
5 | 5 |
|
6 |
| -Guava is a set of core libraries that includes new collection types (such as |
7 |
| -multimap and multiset), immutable collections, a graph library, functional |
8 |
| -types, an in-memory cache, and APIs/utilities for concurrency, I/O, hashing, |
9 |
| -primitives, reflection, string processing, and much more! |
| 6 | +Guava 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 |
| 8 | +utilities for concurrency, I/O, hashing, caching, primitives, strings, and more! It |
| 9 | +is widely used on most Java projects within Google, and widely used by many |
| 10 | +other companies as well. |
10 | 11 |
|
11 |
| -Guava comes in two flavors. |
| 12 | +Guava comes in two flavors: |
12 | 13 |
|
13 | 14 | * The JRE flavor requires JDK 1.8 or higher.
|
14 |
| -* If you need support for JDK 1.7 or Android, use the Android flavor. You can |
15 |
| - find the Android Guava source in the [`android` directory]. |
| 15 | +* If you need support for Android, use the Android flavor. You can find the |
| 16 | + Android Guava source in the [`android` directory]. |
16 | 17 |
|
17 | 18 | [`android` directory]: https://github.com/google/guava/tree/master/android
|
18 | 19 |
|
19 | 20 | ## Adding Guava to your build
|
20 | 21 |
|
21 |
| -Guava's Maven group ID is `com.google.guava` and its artifact ID is `guava`. |
| 22 | +Guava's Maven group ID is `com.google.guava`, and its artifact ID is `guava`. |
22 | 23 | Guava provides two different "flavors": one for use on a (Java 8+) JRE and one
|
23 |
| -for use on Android or Java 7 or by any library that wants to be compatible with |
24 |
| -either of those. These flavors are specified in the Maven version field as |
25 |
| -either `25.1-jre` or `25.1-android`. For more about depending on |
26 |
| -Guava, see [using Guava in your build]. |
| 24 | +for use on Android or by any library that wants to be compatible with Android. |
| 25 | +These flavors are specified in the Maven version field as either `31.0.1-jre` or |
| 26 | +`31.0.1-android`. For more about depending on Guava, see |
| 27 | +[using Guava in your build]. |
27 | 28 |
|
28 | 29 | To add a dependency on Guava using Maven, use the following:
|
29 | 30 |
|
30 | 31 | ```xml
|
31 | 32 | <dependency>
|
32 | 33 | <groupId>com.google.guava</groupId>
|
33 | 34 | <artifactId>guava</artifactId>
|
34 |
| - <version>25.1-jre</version> |
| 35 | + <version>31.0.1-jre</version> |
35 | 36 | <!-- or, for Android: -->
|
36 |
| - <version>25.1-android</version> |
| 37 | + <version>31.0.1-android</version> |
37 | 38 | </dependency>
|
38 | 39 | ```
|
39 | 40 |
|
40 | 41 | To add a dependency using Gradle:
|
41 | 42 |
|
42 |
| -``` |
| 43 | +```gradle |
43 | 44 | dependencies {
|
44 |
| - compile 'com.google.guava:guava:25.1-jre' |
45 |
| - // or, for Android: |
46 |
| - api 'com.google.guava:guava:25.1-android' |
| 45 | + // Pick one: |
| 46 | +
|
| 47 | + // 1. Use Guava in your implementation only: |
| 48 | + implementation("com.google.guava:guava:31.0.1-jre") |
| 49 | +
|
| 50 | + // 2. Use Guava types in your public API: |
| 51 | + api("com.google.guava:guava:31.0.1-jre") |
| 52 | +
|
| 53 | + // 3. Android - Use Guava in your implementation only: |
| 54 | + implementation("com.google.guava:guava:31.0.1-android") |
| 55 | +
|
| 56 | + // 4. Android - Use Guava types in your public API: |
| 57 | + api("com.google.guava:guava:31.0.1-android") |
47 | 58 | }
|
48 | 59 | ```
|
49 | 60 |
|
50 |
| -## Snapshots |
| 61 | +For more information on when to use `api` and when to use `implementation`, |
| 62 | +consult the |
| 63 | +[Gradle documentation on API and implementation separation](https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation). |
| 64 | + |
| 65 | +## Snapshots and Documentation |
51 | 66 |
|
52 | 67 | Snapshots of Guava built from the `master` branch are available through Maven
|
53 | 68 | using version `HEAD-jre-SNAPSHOT`, or `HEAD-android-SNAPSHOT` for the Android
|
54 | 69 | flavor.
|
55 | 70 |
|
56 |
| -- Snapshot API Docs: [guava][guava-snapshot-api-docs] |
57 |
| -- Snapshot API Diffs: [guava][guava-snapshot-api-diffs] |
| 71 | +- Snapshot API Docs: [guava][guava-snapshot-api-docs] |
| 72 | +- Snapshot API Diffs: [guava][guava-snapshot-api-diffs] |
58 | 73 |
|
59 | 74 | ## Learn about Guava
|
60 | 75 |
|
61 |
| -- Our users' guide, [Guava Explained] |
62 |
| -- [A nice collection](http://www.tfnico.com/presentations/google-guava) of other helpful links |
| 76 | +- Our users' guide, [Guava Explained] |
| 77 | +- [A nice collection](http://www.tfnico.com/presentations/google-guava) of |
| 78 | + other helpful links |
63 | 79 |
|
64 | 80 | ## Links
|
65 | 81 |
|
66 |
| -- [GitHub project](https://github.com/google/guava) |
67 |
| -- [Issue tracker: Report a defect or feature request](https://github.com/google/guava/issues/new) |
68 |
| -- [StackOverflow: Ask "how-to" and "why-didn't-it-work" questions](https://stackoverflow.com/questions/ask?tags=guava+java) |
69 |
| -- [guava-discuss: For open-ended questions and discussion](http://groups.google.com/group/guava-discuss) |
| 82 | +- [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) |
70 | 87 |
|
71 | 88 | ## IMPORTANT WARNINGS
|
72 | 89 |
|
73 |
| -1. APIs marked with the `@Beta` annotation at the class or method level |
74 |
| -are subject to change. They can be modified in any way, or even |
75 |
| -removed, at any time. If your code is a library itself (i.e. it is |
76 |
| -used on the CLASSPATH of users outside your own control), you should |
77 |
| -not use beta APIs, unless you [repackage] them. **If your |
78 |
| -code is a library, we strongly recommend using the [Guava Beta Checker] to |
79 |
| -ensure that you do not use any `@Beta` APIs!** |
80 |
| - |
81 |
| -2. APIs without `@Beta` will remain binary-compatible for the indefinite |
82 |
| -future. (Previously, we sometimes removed such APIs after a deprecation period. |
83 |
| -The last release to remove non-`@Beta` APIs was Guava 21.0.) Even `@Deprecated` |
84 |
| -APIs will remain (again, unless they are `@Beta`). We have no plans to start |
85 |
| -removing things again, but officially, we're leaving our options open in case |
86 |
| -of surprises (like, say, a serious security problem). |
87 |
| - |
88 |
| -3. Serialized forms of ALL objects are subject to change unless noted |
89 |
| -otherwise. Do not persist these and assume they can be read by a |
90 |
| -future version of the library. |
91 |
| - |
92 |
| -4. Our classes are not designed to protect against a malicious caller. |
93 |
| -You should not use them for communication between trusted and |
94 |
| -untrusted code. |
95 |
| - |
96 |
| -5. For the mainline flavor, we unit-test the libraries using only OpenJDK 1.8 on |
97 |
| -Linux. Some features, especially in `com.google.common.io`, may not work |
98 |
| -correctly in other environments. For the Android flavor, our unit tests run on |
99 |
| -API level 15 (Ice Cream Sandwich). |
100 |
| - |
101 |
| -[guava-snapshot-api-docs]: https://google.github.io/guava/releases/snapshot-jre/api/docs/ |
102 |
| -[guava-snapshot-api-diffs]: https://google.github.io/guava/releases/snapshot-jre/api/diffs/ |
| 90 | +1. 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 |
| 92 | + 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 |
| 94 | + [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!** |
| 96 | + |
| 97 | +2. APIs without `@Beta` will remain binary-compatible for the indefinite |
| 98 | + 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). |
| 103 | + |
| 104 | +3. 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. |
| 108 | + |
| 109 | +4. Serialized forms of ALL objects are subject to change unless noted |
| 110 | + otherwise. Do not persist these and assume they can be read by a future |
| 111 | + version of the library. |
| 112 | + |
| 113 | +5. Our classes are not designed to protect against a malicious caller. You |
| 114 | + should not use them for communication between trusted and untrusted code. |
| 115 | + |
| 116 | +6. 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). |
| 120 | + |
| 121 | +[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/ |
103 | 123 | [Guava Explained]: https://github.com/google/guava/wiki/Home
|
104 | 124 | [Guava Beta Checker]: https://github.com/google/guava-beta-checker
|
105 | 125 |
|
106 | 126 | <!-- References -->
|
107 | 127 |
|
108 | 128 | [using Guava in your build]: https://github.com/google/guava/wiki/UseGuavaInYourBuild
|
109 | 129 | [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
|
110 |
| - |
| 130 | +[guava-deps]: https://github.com/google/guava/wiki/UseGuavaInYourBuild#what-about-guavas-own-dependencies |
0 commit comments