-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Tidy up core's build file #4207
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
feefa29
Tidy up core's build file
bsideup 957ee90
Merge branch 'master' into cleanup_build_file
bsideup 74a63ab
post-merge fixes
bsideup 19c0c37
Extract shading config
bsideup a6ca10f
fix modules
bsideup d1cb430
fix tests
bsideup 020c68b
Merge branch 'master' into cleanup_build_file
bsideup de4a9ef
fix merge conflicts, simplify shading.gradle
bsideup e43b584
cleanup
bsideup a0462df
Workaround BOM dependency
bsideup 8d1576f
Use `resolvedConfiguration`
bsideup 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 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 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 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,61 @@ | ||
import java.util.jar.JarFile | ||
|
||
apply plugin: 'com.github.johnrengelman.shadow' | ||
|
||
configurations { | ||
shaded | ||
[apiElements, implementation, compileOnly, testCompile]*.extendsFrom shaded | ||
} | ||
configurations.api.canBeResolved = true | ||
|
||
shadowJar { | ||
configurations = [project.configurations.shaded] | ||
archiveClassifier.set(null) | ||
|
||
mergeServiceFiles() | ||
} | ||
|
||
project.afterEvaluate { | ||
def apiDependencies = project.configurations.api.resolvedConfiguration.resolvedArtifacts*.moduleVersion*.id | ||
def apiFiles = project.configurations.api.resolvedConfiguration.files | ||
|
||
// Exclude `api` dependencies, to prevent them being included into the final JAR | ||
shadowJar.dependencies { | ||
for (id in apiDependencies) { | ||
exclude(dependency("${id.group}:${id.name}")) | ||
} | ||
} | ||
|
||
// Inherit dependencies' relocators | ||
shadowJar.relocators = configurations.api.dependencies.withType(ProjectDependency).collectMany { | ||
return it.dependencyProject.tasks.findByName("shadowJar")?.relocators ?: [] | ||
} | ||
|
||
// See https://github.com/johnrengelman/shadow/blob/5.0.0/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ConfigureShadowRelocation.groovy | ||
Set<String> packages = [] | ||
// Always read from core's configurations | ||
for (configuration in tasks.shadowJar.configurations) { | ||
for (jar in configuration.resolvedConfiguration.files) { | ||
if (apiFiles.contains(jar)) { | ||
continue | ||
} | ||
|
||
try (def jf = new JarFile(jar)) { | ||
for (entry in jf.entries()) { | ||
def name = entry.name | ||
if (name.endsWith(".class")) { | ||
def index = name.lastIndexOf('/') | ||
if (index != -1) { | ||
packages.add(name.substring(0, index)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
for (pkg in packages) { | ||
pkg = pkg.replaceAll('/', '.') | ||
|
||
tasks.shadowJar.relocate(pkg, "org.testcontainers.shaded.${pkg}") | ||
} | ||
} |
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.
shouldn't be that with
Only
suffix? As *Classpath configurations are intended to be resolvable, but not consumablehttps://discuss.gradle.org/t/what-is-a-configuration-which-cant-be-directly-resolved/30721
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.
It was
testCompileClasspath
before, so I suggest we address it separately, as this PR is something massive already :)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.
okay, didn't notice it was moved
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.
I will try to polish this PR and reduce the changeset while fixing the merge conflict 👍
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.
Done