Skip to content

Commit c723057

Browse files
authored
[Gradle] Use variant aware resolution for deps on hfds-fixture (#128860) (#128882)
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: # test/fixtures/hdfs-fixture/build.gradle
1 parent 24461bd commit c723057

File tree

5 files changed

+57
-17
lines changed

5 files changed

+57
-17
lines changed

plugins/repository-hdfs/build.gradle

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,36 @@
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
12+
import org.elasticsearch.gradle.internal.test.RestIntegTestTask
1213

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

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

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

2526
def patched = Attribute.of('patched', Boolean)
27+
def hdfsVersionAttr = Attribute.of('hdfs.major.version', Integer)
2628

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

85-
hdfsFixture2 project(path: ':test:fixtures:hdfs-fixture', configuration: 'shadowedHdfs2')
86-
hdfsFixture3 project(path: ':test:fixtures:hdfs-fixture', configuration: 'shadow')
95+
hdfsFixture2 project(':test:fixtures:hdfs-fixture')
96+
hdfsFixture3 project(':test:fixtures:hdfs-fixture')
8797

8898
attributesSchema {
8999
attribute(patched)

test/fixtures/hdfs-fixture/build.gradle

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ 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)
18+
1719
configurations {
1820
hdfs2 {
1921
attributes {
@@ -25,7 +27,26 @@ configurations {
2527
attribute(patched, true)
2628
}
2729
}
28-
consumable("shadowedHdfs2")
30+
consumable("shadowedHdfs2") {
31+
attributes {
32+
attribute(hdfsVersionAttr, 2)
33+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY))
34+
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
35+
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, Integer.parseInt(buildParams.minimumRuntimeVersion.getMajorVersion()))
36+
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.JAR))
37+
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
38+
}
39+
}
40+
consumable("shadowedHdfs3") {
41+
attributes {
42+
attribute(hdfsVersionAttr, 3)
43+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY))
44+
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
45+
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, Integer.parseInt(buildParams.minimumRuntimeVersion.getMajorVersion()))
46+
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.JAR))
47+
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
48+
}
49+
}
2950
}
3051

3152
dependencies {
@@ -154,4 +175,5 @@ tasks.withType(ShadowJar).configureEach {
154175

155176
artifacts {
156177
shadowedHdfs2(hdfs2Jar)
178+
shadowedHdfs3(tasks.named("shadowJar"))
157179
}

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
@@ -9,11 +9,19 @@ apply plugin: 'elasticsearch.internal-java-rest-test'
99
apply plugin: 'elasticsearch.rest-resources'
1010
apply plugin: 'elasticsearch.internal-available-ports'
1111

12+
configurations {
13+
javaRestTestRuntimeClasspath {
14+
attributes {
15+
attribute(Attribute.of('hdfs.major.version', Integer), 2)
16+
}
17+
}
18+
}
19+
1220
dependencies {
1321
clusterPlugins project(':plugins:repository-hdfs')
1422
javaRestTestImplementation(testArtifact(project(xpackModule('searchable-snapshots'))))
1523
javaRestTestCompileOnly project(path: ':test:fixtures:hdfs-fixture')
16-
javaRestTestRuntimeOnly project(path: ':test:fixtures:hdfs-fixture', configuration:"shadowedHdfs2")
24+
javaRestTestRuntimeOnly project(path: ':test:fixtures:hdfs-fixture')
1725
javaRestTestImplementation project(':test:fixtures:krb5kdc-fixture')
1826
javaRestTestRuntimeOnly "com.google.guava:guava:16.0.1"
1927
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
@@ -8,10 +8,18 @@
88
apply plugin: 'elasticsearch.internal-java-rest-test'
99
apply plugin: 'elasticsearch.rest-resources'
1010

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

0 commit comments

Comments
 (0)