Skip to content

Commit 4d93800

Browse files
authored
ci: split enforcer into fast PR metadata check and release banDuplicateClasses check (#14142)
## Summary Separates the Maven Enforcer configuration into two distinct executions: 1. **`enforce` (Fast Metadata Checks)**: Checks `requireUpperBoundDeps`, `requireMavenVersion`, and `requireJavaVersion`. Runs on every PR directly in memory (~15s) without needing a full-repo build. 2. **`enforce-banned-duplicate-classes` (Bytecode Scanner)**: Checks `banDuplicateClasses`. Runs only on Release-Please (non-SNAPSHOT) PRs after compiling and installing all module JARs to disk. --- ### Key Changes * **`java-shared-config/pom.xml`**: * Separated `<id>enforce</id>` into fast metadata rules (`requireUpperBoundDeps`, `requireMavenVersion: [3.8.0,)`, `requireJavaVersion: [1.8,)`). * Added `<id>enforce-banned-duplicate-classes</id>` execution containing the `<banDuplicateClasses>` rule. * **`.github/workflows/ci.yaml`**: * `enforcer` job: Runs on every PR using `mvn -B -ntp enforcer:enforce@enforce -T 1C` (executes in ~15 seconds across all modules without pre-installing JARs). * `ban-duplicate-classes` job: Runs on Release-Please PRs (`release-please--branches--main` non-SNAPSHOT) with the full `JOB_TYPE: install` step followed by `mvn -B -ntp enforcer:enforce@enforce-banned-duplicate-classes -T 1C`. * **`grpc-gcp-java`**: * Updated parent POM to inherit the local `google-cloud-shared-config:1.21.0-SNAPSHOT` parent via relative path and Release-Please tracking comment (`<!-- {x-version-update:google-cloud-shared-config:current} -->`), directly inheriting the split enforcer configuration. * **`google-auth-library-java`**: * Added temporary enforcer configuration overrides with `<rules combine.self="override">` to prevent running the old `banDuplicateClasses` rule inherited from the remote `google-cloud-shared-config:1.17.0` release artifact. * *Note*: These overrides are temporary until the new version of `google-cloud-shared-config` is published to Maven Central, at which point the parent version will be bumped and the overrides removed. * **`java-samples`**: * Added `<enforcer.skip>true</enforcer.skip>` to sample parent POM. --- ### Benefits * **Fast PR Turnaround**: Developers get immediate feedback on dependency convergence (`requireUpperBoundDeps`) and tool versions in ~15 seconds rather than waiting 20+ minutes. * **Full Classpath Safety**: Releases remain protected against duplicate class conflicts (JAR hell) via `banDuplicateClasses` before publishing.
1 parent ac4a49a commit 4d93800

6 files changed

Lines changed: 126 additions & 5 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,30 @@ jobs:
413413
java-version: 11
414414
cache: maven
415415
- run: java -version
416+
- run: mvn -B -ntp enforcer:enforce@enforce -T 1C
417+
ban-duplicate-classes:
418+
needs: bulk-filter
419+
if: |
420+
needs.bulk-filter.outputs.runnable == 'true' &&
421+
github.head_ref == 'release-please--branches--main' &&
422+
!endsWith(github.event.pull_request.title, 'SNAPSHOT')
423+
runs-on: ubuntu-latest
424+
steps:
425+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
426+
with:
427+
persist-credentials: false
428+
- uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1
429+
with:
430+
distribution: temurin
431+
java-version: 11
432+
cache: maven
433+
- run: java -version
416434
- name: Install Maven modules to local Maven repository
417435
run: .kokoro/build.sh
418436
env:
419437
JOB_TYPE: install
420438
- run: java -version
421-
- run: mvn -B -ntp enforcer:enforce@enforce -T 1C
439+
- run: mvn -B -ntp enforcer:enforce@enforce-banned-duplicate-classes -T 1C
422440
gapic-libraries-bom:
423441
needs: bulk-filter
424442
if: ${{ needs.bulk-filter.outputs.runnable == 'true' }}

google-auth-library-java/bom/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,51 @@
4242
</dependency>
4343
</dependencies>
4444
</dependencyManagement>
45+
46+
<build>
47+
<plugins>
48+
<!-- Temporary enforcer configuration override until a new version of google-cloud-shared-config is released to Maven Central.
49+
Because this module inherits a released version of google-cloud-shared-config from Central (which includes banDuplicateClasses in its default enforce execution),
50+
we override the enforce execution here to avoid running banDuplicateClasses on standard PRs where intra-repo SNAPSHOT JARs are unbuilt.
51+
Remove this override once the parent version is bumped to the newly released google-cloud-shared-config. -->
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-enforcer-plugin</artifactId>
55+
<executions>
56+
<execution>
57+
<id>enforce</id>
58+
<configuration>
59+
<rules combine.self="override">
60+
<requireMavenVersion>
61+
<version>[3.8.0,)</version>
62+
</requireMavenVersion>
63+
<requireJavaVersion>
64+
<version>[1.8,)</version>
65+
</requireJavaVersion>
66+
<requireUpperBoundDeps/>
67+
</rules>
68+
</configuration>
69+
</execution>
70+
<execution>
71+
<id>enforce-banned-duplicate-classes</id>
72+
<goals>
73+
<goal>enforce</goal>
74+
</goals>
75+
<configuration>
76+
<rules>
77+
<banDuplicateClasses>
78+
<scopes>
79+
<scope>compile</scope>
80+
<scope>provided</scope>
81+
</scopes>
82+
<findAllDuplicates>true</findAllDuplicates>
83+
<ignoreWhenIdentical>true</ignoreWhenIdentical>
84+
</banDuplicateClasses>
85+
</rules>
86+
</configuration>
87+
</execution>
88+
</executions>
89+
</plugin>
90+
</plugins>
91+
</build>
4592
</project>

google-auth-library-java/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,48 @@
278278
</plugins>
279279
</pluginManagement>
280280
<plugins>
281+
<!-- Temporary enforcer configuration override until a new version of google-cloud-shared-config is released to Maven Central.
282+
Because this module inherits a released version of google-cloud-shared-config from Central (which includes banDuplicateClasses in its default enforce execution),
283+
we override the enforce execution here to avoid running banDuplicateClasses on standard PRs where intra-repo SNAPSHOT JARs are unbuilt.
284+
Remove this override once the parent version is bumped to the newly released google-cloud-shared-config. -->
285+
<plugin>
286+
<groupId>org.apache.maven.plugins</groupId>
287+
<artifactId>maven-enforcer-plugin</artifactId>
288+
<executions>
289+
<execution>
290+
<id>enforce</id>
291+
<configuration>
292+
<rules combine.self="override">
293+
<requireMavenVersion>
294+
<version>[3.8.0,)</version>
295+
</requireMavenVersion>
296+
<requireJavaVersion>
297+
<version>[1.8,)</version>
298+
</requireJavaVersion>
299+
<requireUpperBoundDeps/>
300+
</rules>
301+
</configuration>
302+
</execution>
303+
<execution>
304+
<id>enforce-banned-duplicate-classes</id>
305+
<goals>
306+
<goal>enforce</goal>
307+
</goals>
308+
<configuration>
309+
<rules>
310+
<banDuplicateClasses>
311+
<scopes>
312+
<scope>compile</scope>
313+
<scope>provided</scope>
314+
</scopes>
315+
<findAllDuplicates>true</findAllDuplicates>
316+
<ignoreWhenIdentical>true</ignoreWhenIdentical>
317+
</banDuplicateClasses>
318+
</rules>
319+
</configuration>
320+
</execution>
321+
</executions>
322+
</plugin>
281323
<plugin>
282324
<artifactId>maven-compiler-plugin</artifactId>
283325
<version>3.14.0</version>

grpc-gcp-java/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
first-party-dependencies, which is imported by google-cloud-shared-dependencies;
1212
importing shared dependency management from grpc-gcp would create a dependency
1313
management cycle. -->
14-
<version>1.17.0</version>
15-
<relativePath/>
14+
<version>1.21.0-SNAPSHOT</version><!-- {x-version-update:google-cloud-shared-config:current} -->
15+
<relativePath>../java-shared-config/java-shared-config/pom.xml</relativePath>
1616
</parent>
1717

1818
<groupId>com.google.cloud</groupId>

java-samples/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<relativePath>../google-cloud-jar-parent/pom.xml</relativePath>
1818
</parent>
1919

20+
<properties>
21+
<enforcer.skip>true</enforcer.skip>
22+
</properties>
23+
2024
<modules>
2125
<module>native-image-sample</module>
2226
</modules>

java-shared-config/java-shared-config/pom.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,22 @@
248248
<configuration>
249249
<rules>
250250
<requireMavenVersion>
251-
<version>[3.0,)</version>
251+
<version>[3.8.0,)</version>
252252
</requireMavenVersion>
253253
<requireJavaVersion>
254-
<version>[1.7,)</version>
254+
<version>[1.8,)</version>
255255
</requireJavaVersion>
256256
<requireUpperBoundDeps/>
257+
</rules>
258+
</configuration>
259+
</execution>
260+
<execution>
261+
<id>enforce-banned-duplicate-classes</id>
262+
<goals>
263+
<goal>enforce</goal>
264+
</goals>
265+
<configuration>
266+
<rules>
257267
<banDuplicateClasses>
258268
<scopes>
259269
<scope>compile</scope>

0 commit comments

Comments
 (0)