Skip to content

Commit ce78fc6

Browse files
jjohannesGoogle Java Core Libraries
authored andcommitted
Publish Gradle Module Metadata with Variants.
To be conservative, this commit does not removes most annotation artifacts from Gradle's runtime classpath, only j2objc-annotations. The other artifacts contain at least some annotations with RUNTIME visibility (IIRC). (Even this change could theoretically affect users who assume that they can read CLASS-retention annotations (of which j2objc-annotations has some) from bytecode and find them in the runtime classpath. But that seems unlikely, especially for j2objc annotations.) We may consider being more aggressive in the future. For now, this particular commit addresses #2824 for Gradle users just a tiny bit, and it helps with the problem that prompted #6567. Fixes #3683 RELNOTES=Added [Gradle Module Metadata](https://docs.gradle.org/current/userguide/publishing_gradle_module_metadata.html). If you use Gradle 6 or higher, Gradle can automatically intelligently resolve conflicts between `guava-android` and `guava-jre`, among [other benefits](#3683). PiperOrigin-RevId: 544108700
1 parent c5255f1 commit ce78fc6

File tree

16 files changed

+1044
-2
lines changed

16 files changed

+1044
-2
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ jobs:
5555
if: ${{ failure() }}
5656
shell: bash
5757
run: ./util/print_surefire_reports.sh
58+
- name: 'Integration Test'
59+
if: matrix.java == 11
60+
shell: bash
61+
run: util/gradle_integration_tests.sh
5862

5963
publish_snapshot:
6064
name: 'Publish snapshot'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: "Validate Gradle Wrapper"
2+
on: [push, pull_request]
3+
4+
jobs:
5+
validation:
6+
name: "Validation"
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: gradle/wrapper-validation-action@v1

android/guava/pom.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
<!-- do_not_remove: published-with-gradle-metadata -->
45
<modelVersion>4.0.0</modelVersion>
56
<parent>
67
<groupId>com.google.guava</groupId>
@@ -209,6 +210,50 @@
209210
</execution>
210211
</executions>
211212
</plugin>
213+
<plugin>
214+
<artifactId>maven-resources-plugin</artifactId>
215+
<executions>
216+
<execution>
217+
<id>gradle-module-metadata</id>
218+
<phase>compile</phase>
219+
<goals>
220+
<goal>copy-resources</goal>
221+
</goals>
222+
<configuration>
223+
<outputDirectory>target/publish</outputDirectory>
224+
<resources>
225+
<resource>
226+
<directory>../../guava</directory>
227+
<includes>
228+
<include>module.json</include>
229+
</includes>
230+
<filtering>true</filtering>
231+
</resource>
232+
</resources>
233+
</configuration>
234+
</execution>
235+
</executions>
236+
</plugin>
237+
<plugin>
238+
<groupId>org.codehaus.mojo</groupId>
239+
<artifactId>build-helper-maven-plugin</artifactId>
240+
<executions>
241+
<execution>
242+
<id>attach-gradle-module-metadata</id>
243+
<goals>
244+
<goal>attach-artifact</goal>
245+
</goals>
246+
<configuration>
247+
<artifacts>
248+
<artifact>
249+
<file>target/publish/module.json</file>
250+
<type>module</type>
251+
</artifact>
252+
</artifacts>
253+
</configuration>
254+
</execution>
255+
</executions>
256+
</plugin>
212257
</plugins>
213258
</build>
214259
<profiles>

android/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<project.build.outputTimestamp>1980-02-01T00:00:00Z</project.build.outputTimestamp>
2424
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2525
<test.add.opens></test.add.opens>
26+
<module.status>integration</module.status>
27+
<variant.jvmEnvironment>android</variant.jvmEnvironment>
28+
<otherVariant.version>HEAD-jre-SNAPSHOT</otherVariant.version>
29+
<otherVariant.jvmEnvironment>standard-jvm</otherVariant.jvmEnvironment>
2630
</properties>
2731
<issueManagement>
2832
<system>GitHub Issues</system>
@@ -262,6 +266,15 @@
262266
<artifactId>maven-enforcer-plugin</artifactId>
263267
<version>3.0.0-M3</version>
264268
</plugin>
269+
<plugin>
270+
<artifactId>maven-resources-plugin</artifactId>
271+
<version>3.3.1</version>
272+
</plugin>
273+
<plugin>
274+
<groupId>org.codehaus.mojo</groupId>
275+
<artifactId>build-helper-maven-plugin</artifactId>
276+
<version>3.4.0</version>
277+
</plugin>
265278
</plugins>
266279
</pluginManagement>
267280
</build>

guava/module.json

Lines changed: 287 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,287 @@
1+
{
2+
"formatVersion": "1.1",
3+
"component": {
4+
"group": "${pom.groupId}",
5+
"module": "${pom.artifactId}",
6+
"version": "${pom.version}",
7+
"attributes": {
8+
"org.gradle.status": "${module.status}"
9+
}
10+
},
11+
"createdBy": {
12+
"maven": {
13+
"version": "${maven.version}",
14+
"buildId": "${maven.build.version}"
15+
}
16+
},
17+
"variants": [
18+
{
19+
"name": "${variant.jvmEnvironment}ApiElements",
20+
"attributes": {
21+
"org.gradle.category": "library",
22+
"org.gradle.dependency.bundling": "external",
23+
"org.gradle.jvm.version": "8",
24+
"org.gradle.jvm.environment": "${variant.jvmEnvironment}",
25+
"org.gradle.libraryelements": "jar",
26+
"org.gradle.usage": "java-api"
27+
},
28+
"dependencies": [
29+
{
30+
"group": "com.google.guava",
31+
"module": "guava-parent",
32+
"version": {
33+
"requires": "${pom.version}"
34+
},
35+
"attributes": {
36+
"org.gradle.category": "platform"
37+
}
38+
},
39+
{
40+
"group": "com.google.guava",
41+
"module": "failureaccess",
42+
"version": {
43+
"requires": "1.0.1"
44+
}
45+
},
46+
{
47+
"group": "com.google.code.findbugs",
48+
"module": "jsr305"
49+
},
50+
{
51+
"group": "org.checkerframework",
52+
"module": "checker-qual"
53+
},
54+
{
55+
"group": "com.google.errorprone",
56+
"module": "error_prone_annotations"
57+
},
58+
{
59+
"group": "com.google.j2objc",
60+
"module": "j2objc-annotations"
61+
}
62+
],
63+
"files": [
64+
{
65+
"name": "${project.build.finalName}.jar",
66+
"url": "${project.build.finalName}.jar"
67+
}
68+
],
69+
"capabilities": [
70+
{
71+
"group": "com.google.guava",
72+
"name": "guava",
73+
"version": "${pom.version}"
74+
},
75+
{
76+
"group": "com.google.collections",
77+
"name": "google-collections",
78+
"version": "${pom.version}"
79+
},
80+
{
81+
"group": "com.google.guava",
82+
"name": "listenablefuture",
83+
"version": "1.0"
84+
}
85+
]
86+
},
87+
{
88+
"name": "${variant.jvmEnvironment}RuntimeElements",
89+
"attributes": {
90+
"org.gradle.category": "library",
91+
"org.gradle.dependency.bundling": "external",
92+
"org.gradle.jvm.version": "8",
93+
"org.gradle.jvm.environment": "${variant.jvmEnvironment}",
94+
"org.gradle.libraryelements": "jar",
95+
"org.gradle.usage": "java-runtime"
96+
},
97+
"dependencies": [
98+
{
99+
"group": "com.google.guava",
100+
"module": "guava-parent",
101+
"version": {
102+
"requires": "${pom.version}"
103+
},
104+
"attributes": {
105+
"org.gradle.category": "platform"
106+
}
107+
},
108+
{
109+
"group": "com.google.guava",
110+
"module": "failureaccess",
111+
"version": {
112+
"requires": "1.0.1"
113+
}
114+
},
115+
{
116+
"group": "com.google.code.findbugs",
117+
"module": "jsr305"
118+
},
119+
{
120+
"group": "org.checkerframework",
121+
"module": "checker-qual"
122+
},
123+
{
124+
"group": "com.google.errorprone",
125+
"module": "error_prone_annotations"
126+
}
127+
],
128+
"files": [
129+
{
130+
"name": "${project.build.finalName}.jar",
131+
"url": "${project.build.finalName}.jar"
132+
}
133+
],
134+
"capabilities": [
135+
{
136+
"group": "com.google.guava",
137+
"name": "guava",
138+
"version": "${pom.version}"
139+
},
140+
{
141+
"group": "com.google.collections",
142+
"name": "google-collections",
143+
"version": "${pom.version}"
144+
},
145+
{
146+
"group": "com.google.guava",
147+
"name": "listenablefuture",
148+
"version": "1.0"
149+
}
150+
]
151+
},
152+
{
153+
"name": "${otherVariant.jvmEnvironment}ApiElements",
154+
"attributes": {
155+
"org.gradle.category": "library",
156+
"org.gradle.dependency.bundling": "external",
157+
"org.gradle.jvm.version": "8",
158+
"org.gradle.jvm.environment": "${otherVariant.jvmEnvironment}",
159+
"org.gradle.libraryelements": "jar",
160+
"org.gradle.usage": "java-api"
161+
},
162+
"dependencies": [
163+
{
164+
"group": "com.google.guava",
165+
"module": "guava-parent",
166+
"version": {
167+
"requires": "${otherVariant.version}"
168+
},
169+
"attributes": {
170+
"org.gradle.category": "platform"
171+
}
172+
},
173+
{
174+
"group": "com.google.guava",
175+
"module": "failureaccess",
176+
"version": {
177+
"requires": "1.0.1"
178+
}
179+
},
180+
{
181+
"group": "com.google.code.findbugs",
182+
"module": "jsr305"
183+
},
184+
{
185+
"group": "org.checkerframework",
186+
"module": "checker-qual"
187+
},
188+
{
189+
"group": "com.google.errorprone",
190+
"module": "error_prone_annotations"
191+
},
192+
{
193+
"group": "com.google.j2objc",
194+
"module": "j2objc-annotations"
195+
}
196+
],
197+
"files": [
198+
{
199+
"name": "${pom.artifactId}-${otherVariant.version}.jar",
200+
"url": "../${otherVariant.version}/${pom.artifactId}-${otherVariant.version}.jar"
201+
}
202+
],
203+
"capabilities": [
204+
{
205+
"group": "com.google.guava",
206+
"name": "guava",
207+
"version": "${pom.version}"
208+
},
209+
{
210+
"group": "com.google.collections",
211+
"name": "google-collections",
212+
"version": "${pom.version}"
213+
},
214+
{
215+
"group": "com.google.guava",
216+
"name": "listenablefuture",
217+
"version": "1.0"
218+
}
219+
]
220+
},
221+
{
222+
"name": "${otherVariant.jvmEnvironment}RuntimeElements",
223+
"attributes": {
224+
"org.gradle.category": "library",
225+
"org.gradle.dependency.bundling": "external",
226+
"org.gradle.jvm.version": "8",
227+
"org.gradle.jvm.environment": "${otherVariant.jvmEnvironment}",
228+
"org.gradle.libraryelements": "jar",
229+
"org.gradle.usage": "java-runtime"
230+
},
231+
"dependencies": [
232+
{
233+
"group": "com.google.guava",
234+
"module": "guava-parent",
235+
"version": {
236+
"requires": "${otherVariant.version}"
237+
},
238+
"attributes": {
239+
"org.gradle.category": "platform"
240+
}
241+
},
242+
{
243+
"group": "com.google.guava",
244+
"module": "failureaccess",
245+
"version": {
246+
"requires": "1.0.1"
247+
}
248+
},
249+
{
250+
"group": "com.google.code.findbugs",
251+
"module": "jsr305"
252+
},
253+
{
254+
"group": "org.checkerframework",
255+
"module": "checker-qual"
256+
},
257+
{
258+
"group": "com.google.errorprone",
259+
"module": "error_prone_annotations"
260+
}
261+
],
262+
"files": [
263+
{
264+
"name": "${pom.artifactId}-${otherVariant.version}.jar",
265+
"url": "../${otherVariant.version}/${pom.artifactId}-${otherVariant.version}.jar"
266+
}
267+
],
268+
"capabilities": [
269+
{
270+
"group": "com.google.guava",
271+
"name": "guava",
272+
"version": "${pom.version}"
273+
},
274+
{
275+
"group": "com.google.collections",
276+
"name": "google-collections",
277+
"version": "${pom.version}"
278+
},
279+
{
280+
"group": "com.google.guava",
281+
"name": "listenablefuture",
282+
"version": "1.0"
283+
}
284+
]
285+
}
286+
]
287+
}

0 commit comments

Comments
 (0)