Skip to content

Commit

Permalink
Publish Gradle Module Metadata with Variants.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jjohannes authored and Google Java Core Libraries committed Jun 28, 2023
1 parent c5255f1 commit ce78fc6
Show file tree
Hide file tree
Showing 16 changed files with 1,044 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ jobs:
if: ${{ failure() }}
shell: bash
run: ./util/print_surefire_reports.sh
- name: 'Integration Test'
if: matrix.java == 11
shell: bash
run: util/gradle_integration_tests.sh

publish_snapshot:
name: 'Publish snapshot'
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "Validate Gradle Wrapper"
on: [push, pull_request]

jobs:
validation:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
45 changes: 45 additions & 0 deletions android/guava/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google.guava</groupId>
Expand Down Expand Up @@ -209,6 +210,50 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>gradle-module-metadata</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/publish</outputDirectory>
<resources>
<resource>
<directory>../../guava</directory>
<includes>
<include>module.json</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-gradle-module-metadata</id>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>target/publish/module.json</file>
<type>module</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
13 changes: 13 additions & 0 deletions android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<project.build.outputTimestamp>1980-02-01T00:00:00Z</project.build.outputTimestamp>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<test.add.opens></test.add.opens>
<module.status>integration</module.status>
<variant.jvmEnvironment>android</variant.jvmEnvironment>
<otherVariant.version>HEAD-jre-SNAPSHOT</otherVariant.version>
<otherVariant.jvmEnvironment>standard-jvm</otherVariant.jvmEnvironment>
</properties>
<issueManagement>
<system>GitHub Issues</system>
Expand Down Expand Up @@ -262,6 +266,15 @@
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
287 changes: 287 additions & 0 deletions guava/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
{
"formatVersion": "1.1",
"component": {
"group": "${pom.groupId}",
"module": "${pom.artifactId}",
"version": "${pom.version}",
"attributes": {
"org.gradle.status": "${module.status}"
}
},
"createdBy": {
"maven": {
"version": "${maven.version}",
"buildId": "${maven.build.version}"
}
},
"variants": [
{
"name": "${variant.jvmEnvironment}ApiElements",
"attributes": {
"org.gradle.category": "library",
"org.gradle.dependency.bundling": "external",
"org.gradle.jvm.version": "8",
"org.gradle.jvm.environment": "${variant.jvmEnvironment}",
"org.gradle.libraryelements": "jar",
"org.gradle.usage": "java-api"
},
"dependencies": [
{
"group": "com.google.guava",
"module": "guava-parent",
"version": {
"requires": "${pom.version}"
},
"attributes": {
"org.gradle.category": "platform"
}
},
{
"group": "com.google.guava",
"module": "failureaccess",
"version": {
"requires": "1.0.1"
}
},
{
"group": "com.google.code.findbugs",
"module": "jsr305"
},
{
"group": "org.checkerframework",
"module": "checker-qual"
},
{
"group": "com.google.errorprone",
"module": "error_prone_annotations"
},
{
"group": "com.google.j2objc",
"module": "j2objc-annotations"
}
],
"files": [
{
"name": "${project.build.finalName}.jar",
"url": "${project.build.finalName}.jar"
}
],
"capabilities": [
{
"group": "com.google.guava",
"name": "guava",
"version": "${pom.version}"
},
{
"group": "com.google.collections",
"name": "google-collections",
"version": "${pom.version}"
},
{
"group": "com.google.guava",
"name": "listenablefuture",
"version": "1.0"
}
]
},
{
"name": "${variant.jvmEnvironment}RuntimeElements",
"attributes": {
"org.gradle.category": "library",
"org.gradle.dependency.bundling": "external",
"org.gradle.jvm.version": "8",
"org.gradle.jvm.environment": "${variant.jvmEnvironment}",
"org.gradle.libraryelements": "jar",
"org.gradle.usage": "java-runtime"
},
"dependencies": [
{
"group": "com.google.guava",
"module": "guava-parent",
"version": {
"requires": "${pom.version}"
},
"attributes": {
"org.gradle.category": "platform"
}
},
{
"group": "com.google.guava",
"module": "failureaccess",
"version": {
"requires": "1.0.1"
}
},
{
"group": "com.google.code.findbugs",
"module": "jsr305"
},
{
"group": "org.checkerframework",
"module": "checker-qual"
},
{
"group": "com.google.errorprone",
"module": "error_prone_annotations"
}
],
"files": [
{
"name": "${project.build.finalName}.jar",
"url": "${project.build.finalName}.jar"
}
],
"capabilities": [
{
"group": "com.google.guava",
"name": "guava",
"version": "${pom.version}"
},
{
"group": "com.google.collections",
"name": "google-collections",
"version": "${pom.version}"
},
{
"group": "com.google.guava",
"name": "listenablefuture",
"version": "1.0"
}
]
},
{
"name": "${otherVariant.jvmEnvironment}ApiElements",
"attributes": {
"org.gradle.category": "library",
"org.gradle.dependency.bundling": "external",
"org.gradle.jvm.version": "8",
"org.gradle.jvm.environment": "${otherVariant.jvmEnvironment}",
"org.gradle.libraryelements": "jar",
"org.gradle.usage": "java-api"
},
"dependencies": [
{
"group": "com.google.guava",
"module": "guava-parent",
"version": {
"requires": "${otherVariant.version}"
},
"attributes": {
"org.gradle.category": "platform"
}
},
{
"group": "com.google.guava",
"module": "failureaccess",
"version": {
"requires": "1.0.1"
}
},
{
"group": "com.google.code.findbugs",
"module": "jsr305"
},
{
"group": "org.checkerframework",
"module": "checker-qual"
},
{
"group": "com.google.errorprone",
"module": "error_prone_annotations"
},
{
"group": "com.google.j2objc",
"module": "j2objc-annotations"
}
],
"files": [
{
"name": "${pom.artifactId}-${otherVariant.version}.jar",
"url": "../${otherVariant.version}/${pom.artifactId}-${otherVariant.version}.jar"
}
],
"capabilities": [
{
"group": "com.google.guava",
"name": "guava",
"version": "${pom.version}"
},
{
"group": "com.google.collections",
"name": "google-collections",
"version": "${pom.version}"
},
{
"group": "com.google.guava",
"name": "listenablefuture",
"version": "1.0"
}
]
},
{
"name": "${otherVariant.jvmEnvironment}RuntimeElements",
"attributes": {
"org.gradle.category": "library",
"org.gradle.dependency.bundling": "external",
"org.gradle.jvm.version": "8",
"org.gradle.jvm.environment": "${otherVariant.jvmEnvironment}",
"org.gradle.libraryelements": "jar",
"org.gradle.usage": "java-runtime"
},
"dependencies": [
{
"group": "com.google.guava",
"module": "guava-parent",
"version": {
"requires": "${otherVariant.version}"
},
"attributes": {
"org.gradle.category": "platform"
}
},
{
"group": "com.google.guava",
"module": "failureaccess",
"version": {
"requires": "1.0.1"
}
},
{
"group": "com.google.code.findbugs",
"module": "jsr305"
},
{
"group": "org.checkerframework",
"module": "checker-qual"
},
{
"group": "com.google.errorprone",
"module": "error_prone_annotations"
}
],
"files": [
{
"name": "${pom.artifactId}-${otherVariant.version}.jar",
"url": "../${otherVariant.version}/${pom.artifactId}-${otherVariant.version}.jar"
}
],
"capabilities": [
{
"group": "com.google.guava",
"name": "guava",
"version": "${pom.version}"
},
{
"group": "com.google.collections",
"name": "google-collections",
"version": "${pom.version}"
},
{
"group": "com.google.guava",
"name": "listenablefuture",
"version": "1.0"
}
]
}
]
}
Loading

0 comments on commit ce78fc6

Please sign in to comment.