mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-08 22:14:59 +00:00
Add explanation of the configuration trick used to find transitive deps
for exclusion
This commit is contained in:
parent
be147719ff
commit
24d306c2f4
@ -101,7 +101,28 @@ class BuildPlugin implements Plugin<Project> {
|
|||||||
project.ext.javaHome = project.rootProject.ext.javaHome
|
project.ext.javaHome = project.rootProject.ext.javaHome
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Makes dependencies non-transitive by default */
|
/** Return the name
|
||||||
|
*/
|
||||||
|
static String transitiveDepConfigName(String groupId, String artifactId, String version) {
|
||||||
|
return "_transitive_${groupId}:${artifactId}:${version}"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes dependencies non-transitive.
|
||||||
|
*
|
||||||
|
* Gradle allows setting all dependencies as non-transitive very easily.
|
||||||
|
* But this mechanism does not translate into maven pom generation. In order
|
||||||
|
* to effectively make the pom act as if it has no transitive dependencies,
|
||||||
|
* we must exclude each transitive dependency of each direct dependency.
|
||||||
|
*
|
||||||
|
* Determining the transitive deps of a dependency which has been resolved as
|
||||||
|
* non-transitive is difficult because the process of resolving removes the
|
||||||
|
* transitive deps. To sidestep this issue, we create a configuration per
|
||||||
|
* direct dependency version. This specially named and unique configuration
|
||||||
|
* will contain all of the transitive dependencies of this particular
|
||||||
|
* dependency. We can then use this configuration during pom generation
|
||||||
|
* to iterate the transitive dependencies and add excludes.
|
||||||
|
*/
|
||||||
static void configureConfigurations(Project project) {
|
static void configureConfigurations(Project project) {
|
||||||
// fail on any conflicting dependency versions
|
// fail on any conflicting dependency versions
|
||||||
project.configurations.all({ Configuration configuration ->
|
project.configurations.all({ Configuration configuration ->
|
||||||
@ -119,12 +140,11 @@ class BuildPlugin implements Plugin<Project> {
|
|||||||
dep.transitive = false
|
dep.transitive = false
|
||||||
|
|
||||||
// also create a configuration just for this dependency version, so that later
|
// also create a configuration just for this dependency version, so that later
|
||||||
// we can determine which dependencies it has (for pom generation excludes)
|
// we can determine which transitive dependencies it has
|
||||||
String depId = "${dep.getGroup()}:${dep.getName()}:${dep.getVersion()}"
|
String depConfig = transitiveDepConfigName(dep.group, dep.name, dep.version)
|
||||||
String depConfig = "_transitive_${depId}"
|
|
||||||
if (project.configurations.findByName(depConfig) == null) {
|
if (project.configurations.findByName(depConfig) == null) {
|
||||||
project.configurations.create(depConfig)
|
project.configurations.create(depConfig)
|
||||||
project.dependencies.add(depConfig, depId)
|
project.dependencies.add(depConfig, "${dep.group}:${dep.name}:${dep.version}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,8 +169,7 @@ class BuildPlugin implements Plugin<Project> {
|
|||||||
String version = depNode.get('version').get(0).text()
|
String version = depNode.get('version').get(0).text()
|
||||||
|
|
||||||
// collect the transitive deps now that we know what this dependency is
|
// collect the transitive deps now that we know what this dependency is
|
||||||
String depId = "${groupId}:${artifactId}:${version}"
|
String depConfig = transitiveDepConfigName(groupId, artifactId, version)
|
||||||
String depConfig = "_transitive_${depId}"
|
|
||||||
Configuration configuration = project.configurations.findByName(depConfig)
|
Configuration configuration = project.configurations.findByName(depConfig)
|
||||||
if (configuration == null) {
|
if (configuration == null) {
|
||||||
continue // we did not make this dep non-transitive
|
continue // we did not make this dep non-transitive
|
||||||
|
Loading…
x
Reference in New Issue
Block a user