-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Build: Add runtime dependency guard for bundled artifacts #15855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba21888
Build: Add runtime dependency guard for bundled artifacts
RussellSpitzer 156f125
Build: Exclude org.apache.iceberg modules from runtime dependency guard
RussellSpitzer 3337f5c
Build: Differentiate version changes from added/removed in dependency…
RussellSpitzer 09f7c54
Build: Exclude runtime-deps.txt from RAT license check
RussellSpitzer cca9eca
Build, CI: Add top-level checkAllRuntimeDeps task and CI job
RussellSpitzer 4759cd6
Build: Move runtime-deps script to root, warn on missing baseline, re…
RussellSpitzer 956c635
CI: Suppress compilation noise in check-runtime-deps job
RussellSpitzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,4 +66,6 @@ project(":iceberg-aws-bundle") { | |
| jar { | ||
| enabled = false | ||
| } | ||
|
|
||
| apply from: "${rootDir}/runtime-deps.gradle" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,4 +52,6 @@ project(":iceberg-azure-bundle") { | |
| jar { | ||
| enabled = false | ||
| } | ||
|
|
||
| apply from: "${rootDir}/runtime-deps.gradle" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,3 +29,4 @@ sitemap.xml | |
| .python-version | ||
| **/*_index.md | ||
| **/.venv/** | ||
| **/runtime-deps.txt | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,4 +59,6 @@ project(":iceberg-gcp-bundle") { | |
| jar { | ||
| enabled = false | ||
| } | ||
|
|
||
| apply from: "${rootDir}/runtime-deps.gradle" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| // Guards the runtime dependency surface for shadow JAR modules. | ||
| // | ||
| // Prevents accidental transitive dependency growth in shipped shadow JARs. | ||
| // Without this guard, adding a single catalog module as 'implementation' | ||
| // instead of 'compileOnly' can silently leak dozens of transitive artifacts | ||
| // into the runtime JAR, inflating its size and introducing unlicensed code. | ||
| // | ||
| // Apply this script in any project that ships a bundled artifact: Spark and | ||
| // Flink runtime shadow JARs, cloud bundles (aws, azure, gcp), and Kafka | ||
| // Connect runtime distribution. | ||
| // | ||
| // It adds two tasks: | ||
| // | ||
| // generateRuntimeDeps - resolves runtimeClasspath and writes a sorted | ||
| // baseline of group:artifact:version coordinates | ||
| // to runtime-deps.txt in the project directory. | ||
| // | ||
| // checkRuntimeDeps - compares the resolved dependencies against the | ||
| // checked-in baseline and fails with a diff if | ||
| // they don't match. Patch-level version changes are | ||
| // ignored so that routine Dependabot bumps don't | ||
| // require a baseline update. Wired into the 'check' | ||
| // lifecycle. | ||
| // | ||
| // Workflow: | ||
| // 1. ./gradlew check -- fails if deps changed | ||
| // 2. ./gradlew generateRuntimeDeps -- auto-updates all baselines | ||
| // 3. Update LICENSE and NOTICE if dependency licenses changed -- This is a Manual Step | ||
| // 4. Commit | ||
|
|
||
| def depsFile = file("${projectDir}/runtime-deps.txt") | ||
|
|
||
| def resolveRuntimeDeps = { | ||
| configurations.runtimeClasspath.resolvedConfiguration | ||
| .resolvedArtifacts | ||
| .collect { "${it.moduleVersion.id.group}:${it.moduleVersion.id.name}:${it.moduleVersion.id.version}" } | ||
| .findAll { !it.startsWith('org.apache.iceberg:') } | ||
| .toSorted() | ||
| .toUnique() | ||
| } | ||
|
|
||
| tasks.register('generateRuntimeDeps') { | ||
| group = 'verification' | ||
| description = 'Regenerate the runtime dependency baseline after intentional dependency changes' | ||
| outputs.file(depsFile) | ||
| doLast { | ||
| def deps = resolveRuntimeDeps() | ||
| depsFile.text = deps.join('\n') + '\n' | ||
| logger.lifecycle("Wrote ${deps.size()} dependencies to ${depsFile}") | ||
| logger.lifecycle("Review the diff, then update LICENSE and NOTICE if licenses changed.") | ||
| } | ||
| } | ||
|
|
||
| tasks.register('checkRuntimeDeps') { | ||
| group = 'verification' | ||
| description = 'Verify runtime dependencies match the checked-in baseline' | ||
| inputs.files(configurations.runtimeClasspath) | ||
| outputs.file(depsFile) | ||
| doLast { | ||
| if (!depsFile.exists()) { | ||
| logger.warn("WARNING: Missing ${depsFile.name} in ${projectDir}. " + | ||
| "Run: ./gradlew ${project.path}:generateRuntimeDeps") | ||
| return | ||
| } | ||
|
|
||
| def actual = resolveRuntimeDeps() | ||
| def expected = depsFile.readLines().findAll { it.trim() }.toSorted() | ||
|
|
||
| def groupArtifact = { coord -> coord.substring(0, coord.lastIndexOf(':')) } | ||
| def majorMinor = { coord -> | ||
| def ver = coord.substring(coord.lastIndexOf(':') + 1) | ||
| def parts = ver.split('\\.') | ||
| parts.length >= 2 ? "${parts[0]}.${parts[1]}" : ver | ||
| } | ||
|
|
||
| def actualByModule = actual.collectEntries { [(groupArtifact(it)): it] } | ||
| def expectedByModule = expected.collectEntries { [(groupArtifact(it)): it] } | ||
|
|
||
| def added = actualByModule.keySet() - expectedByModule.keySet() | ||
| def removed = expectedByModule.keySet() - actualByModule.keySet() | ||
| def shared = actualByModule.keySet().intersect(expectedByModule.keySet()) | ||
| def versionChanged = shared.findAll { | ||
| majorMinor(actualByModule[it]) != majorMinor(expectedByModule[it]) | ||
| } | ||
|
|
||
| if (added || removed || versionChanged) { | ||
| def msg = new StringBuilder() | ||
| msg.append("Runtime dependency baseline mismatch for ${project.name}!\n") | ||
| if (versionChanged) { | ||
| msg.append("\n Version changed (${versionChanged.size()}):\n") | ||
| versionChanged.toSorted().each { module -> | ||
| msg.append(" ~ ${expectedByModule[module]} -> ${actualByModule[module]}\n") | ||
| } | ||
| } | ||
| if (added) { | ||
| msg.append("\n Added (${added.size()}):\n") | ||
| added.toSorted().each { module -> msg.append(" + ${actualByModule[module]}\n") } | ||
| } | ||
| if (removed) { | ||
| msg.append("\n Removed (${removed.size()}):\n") | ||
| removed.toSorted().each { module -> msg.append(" - ${expectedByModule[module]}\n") } | ||
| } | ||
| msg.append("\nTo update the baseline run:\n") | ||
| msg.append(" ./gradlew ${project.path}:generateRuntimeDeps\n") | ||
| msg.append("\nThen update LICENSE and NOTICE to reflect the dependency changes.") | ||
| throw new GradleException(msg.toString()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| check.dependsOn checkRuntimeDeps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is no-op right now, right?