Skip to content

Commit ed79ca3

Browse files
authored
[Gradle] Use variant aware resolution for deps on hfds-fixture (elastic#128860) (elastic#128883)
This reworks the dependency resolution for hdfs fixture dependencies to use gradles variant aware dependency resolution instead of relying on outgoing configuration names. (cherry picked from commit 2856923) # Conflicts: # plugins/repository-hdfs/build.gradle # test/fixtures/hdfs-fixture/build.gradle # x-pack/plugin/searchable-snapshots/qa/hdfs/build.gradle # x-pack/plugin/snapshot-repo-test-kit/qa/hdfs/build.gradle
1 parent 024e5ce commit ed79ca3

File tree

5 files changed

+56
-17
lines changed

5 files changed

+56
-17
lines changed

plugins/repository-hdfs/build.gradle

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,37 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import org.elasticsearch.gradle.internal.test.RestIntegTestTask
10+
1111
import org.elasticsearch.gradle.OS
1212
import org.elasticsearch.gradle.internal.info.BuildParams
13+
import org.elasticsearch.gradle.internal.test.RestIntegTestTask
1314

1415
apply plugin: 'elasticsearch.internal-java-rest-test'
1516
apply plugin: 'elasticsearch.internal-yaml-rest-test'
1617

1718
esplugin {
1819
description = 'The HDFS repository plugin adds support for Hadoop Distributed File-System (HDFS) repositories.'
19-
classname ='org.elasticsearch.repositories.hdfs.HdfsPlugin'
20+
classname = 'org.elasticsearch.repositories.hdfs.HdfsPlugin'
2021
}
2122

2223
versions << [
2324
'hadoop': '3.4.1'
2425
]
2526

2627
def patched = Attribute.of('patched', Boolean)
28+
def hdfsVersionAttr = Attribute.of('hdfs.major.version', Integer)
2729

2830
configurations {
29-
hdfsFixture2
30-
hdfsFixture3
31+
hdfsFixture2 {
32+
attributes {
33+
attribute(hdfsVersionAttr, 2)
34+
}
35+
}
36+
hdfsFixture3 {
37+
attributes {
38+
attribute(hdfsVersionAttr, 3)
39+
}
40+
}
3141
compileClasspath {
3242
attributes {
3343
attribute(patched, true)
@@ -83,8 +93,8 @@ dependencies {
8393
yamlRestTestRuntimeOnly "commons-cli:commons-cli:1.5.0"
8494
yamlRestTestRuntimeOnly "org.apache.logging.log4j:log4j-1.2-api:${versions.log4j}"
8595

86-
hdfsFixture2 project(path: ':test:fixtures:hdfs-fixture', configuration: 'shadowedHdfs2')
87-
hdfsFixture3 project(path: ':test:fixtures:hdfs-fixture', configuration: 'shadow')
96+
hdfsFixture2 project(':test:fixtures:hdfs-fixture')
97+
hdfsFixture3 project(':test:fixtures:hdfs-fixture')
8898

8999
attributesSchema {
90100
attribute(patched)

test/fixtures/hdfs-fixture/build.gradle

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ apply plugin: 'com.gradleup.shadow'
1414
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
1515

1616
def patched = Attribute.of('patched', Boolean)
17+
def hdfsVersionAttr = Attribute.of('hdfs.major.version', Integer)
1718
configurations {
1819
hdfs2 {
1920
attributes {
@@ -25,7 +26,26 @@ configurations {
2526
attribute(patched, true)
2627
}
2728
}
28-
consumable("shadowedHdfs2")
29+
consumable("shadowedHdfs2") {
30+
attributes {
31+
attribute(hdfsVersionAttr, 2)
32+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY))
33+
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
34+
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, Integer.parseInt(buildParams.minimumRuntimeVersion.getMajorVersion()))
35+
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.JAR))
36+
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
37+
}
38+
}
39+
consumable("shadowedHdfs3") {
40+
attributes {
41+
attribute(hdfsVersionAttr, 3)
42+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY))
43+
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
44+
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, Integer.parseInt(buildParams.minimumRuntimeVersion.getMajorVersion()))
45+
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.JAR))
46+
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
47+
}
48+
}
2949
}
3050

3151
dependencies {
@@ -154,4 +174,5 @@ tasks.withType(ShadowJar).configureEach {
154174

155175
artifacts {
156176
shadowedHdfs2(hdfs2Jar)
177+
shadowedHdfs3(tasks.named("shadowJar"))
157178
}

test/fixtures/krb5kdc-fixture/build.gradle

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ configurations {
2525
all {
2626
exclude group: 'org.hamcrest', module: 'hamcrest-core'
2727
}
28-
krb5ConfHdfsFile {
29-
canBeConsumed = true
30-
canBeResolved = false
31-
}
32-
krb5KeytabsHdfsDir {
33-
canBeConsumed = true
34-
canBeResolved = false
35-
}
3628
}
3729

3830
dependencies {

x-pack/plugin/searchable-snapshots/qa/hdfs/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ apply plugin: 'elasticsearch.internal-java-rest-test'
1111
apply plugin: 'elasticsearch.rest-resources'
1212
apply plugin: 'elasticsearch.internal-available-ports'
1313

14+
configurations {
15+
javaRestTestRuntimeClasspath {
16+
attributes {
17+
attribute(Attribute.of('hdfs.major.version', Integer), 2)
18+
}
19+
}
20+
}
21+
1422
dependencies {
1523
clusterPlugins project(':plugins:repository-hdfs')
1624
javaRestTestImplementation(testArtifact(project(xpackModule('searchable-snapshots'))))
17-
javaRestTestImplementation project(path: ':test:fixtures:hdfs-fixture', configuration:"shadowedHdfs2")
25+
javaRestTestImplementation project(path: ':test:fixtures:hdfs-fixture')
1826
javaRestTestImplementation project(':test:fixtures:krb5kdc-fixture')
1927
javaRestTestRuntimeOnly "com.google.guava:guava:16.0.1"
2028
javaRestTestRuntimeOnly "commons-cli:commons-cli:1.2"

x-pack/plugin/snapshot-repo-test-kit/qa/hdfs/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ import org.elasticsearch.gradle.internal.info.BuildParams
1010
apply plugin: 'elasticsearch.internal-java-rest-test'
1111
apply plugin: 'elasticsearch.rest-resources'
1212

13+
configurations {
14+
javaRestTestRuntimeClasspath {
15+
attributes {
16+
attribute(Attribute.of('hdfs.major.version', Integer), 3)
17+
}
18+
}
19+
}
20+
1321
dependencies {
1422
javaRestTestImplementation testArtifact(project(xpackModule('snapshot-repo-test-kit')))
15-
javaRestTestImplementation project(path: ':test:fixtures:hdfs-fixture', configuration:"shadow")
23+
javaRestTestImplementation project(path: ':test:fixtures:hdfs-fixture')
1624
javaRestTestImplementation project(':test:fixtures:krb5kdc-fixture')
1725
javaRestTestImplementation "org.slf4j:slf4j-api:${versions.slf4j}"
1826
javaRestTestImplementation "org.slf4j:slf4j-simple:${versions.slf4j}"

0 commit comments

Comments
 (0)