# How to use MavenFilteringHack to replace var from YAML files

**URL:** <https://discuss.elastic.co/t/how-to-use-mavenfilteringhack-to-replace-var-from-yaml-files/209959>\
**Category:** Elasticsearch\
**Created:** [November 29, 2019, 10:51am UTC](https://discuss.elastic.co/t/how-to-use-mavenfilteringhack-to-replace-var-from-yaml-files/209959 "2019-11-29T10:51:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ethan-Zhang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ethan-zhang/32/54812_2.png) [@Ethan-Zhang](https://discuss.elastic.co/u/Ethan-Zhang)\
**Post date:** [November 29, 2019, 10:51am UTC](https://discuss.elastic.co/t/how-to-use-mavenfilteringhack-to-replace-var-from-yaml-files/209959/1 "2019-11-29T10:51:27Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/c/6/c6e4d0929789a5d007305e27780bf40a1d4f5994.png)

I wrote my own rest-api-spec above, and I want to replace the ${} from in gradle build

```
processTestResources {
Map<String, Object> expansions = [
    'bucket': cosBucket,
    'base_path': cosBasePath,
]
inputs.properties(expansions)
MavenFilteringHack.filter(it, expansions)

```

When I run this code in gradle build, it doesn't worked. I seems gradle build could not find the value of ${cosBucket}.

Anyone who have developed ES plugin, Please help 🥰

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 2, 2019, 9:19am UTC](https://discuss.elastic.co/t/how-to-use-mavenfilteringhack-to-replace-var-from-yaml-files/209959/2 "2019-12-02T09:19:40Z")

</div>

Is there any error or just no replacement?

---

<div class="post-metadata">

**Author:** ![Ethan-Zhang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ethan-zhang/32/54812_2.png) [@Ethan-Zhang](https://discuss.elastic.co/u/Ethan-Zhang)\
**Post date:** [December 2, 2019, 9:22am UTC](https://discuss.elastic.co/t/how-to-use-mavenfilteringhack-to-replace-var-from-yaml-files/209959/3 "2019-12-02T09:22:39Z")

</div>

no error just no replacement，I attach build.gradle below

```auto
import org.elasticsearch.gradle.MavenFilteringHack

buildscript {
    ext {
        pluginName = project.properties['pluginName']
        publishedPluginVersion = project.properties['esVersion']
        pluginVersion = project.properties['esVersion']
        esVersion = project.properties['esVersion']
    }
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'org.elasticsearch.gradle:build-tools:' + esVersion
        classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.10.0'
    }
}

// import external plugin
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'maven'
apply plugin: 'license'

ext.projectSubstitutions = [:]
// license of this project
licenseFile = rootProject.file('LICENSE.txt')

license {
    header rootProject.file('LicenseHeader.txt')
    skipExistingHeaders true
    useDefaultMappings = false
    mapping {
        java = 'SLASHSTAR_STYLE'
    }
}

// copyright notices
noticeFile = rootProject.file('NOTICE.txt')

esplugin {
    name pluginName
    description 'The Cos Repository plugin adds support for using Tencent Cloud Cos as a repository fro Snapshot/Restore.'
    classname 'org.elasticsearch.repositories.cos.COSRepositoryPlugin'
    version pluginVersion
    licenseFile rootProject.file('LICENSE.txt')
    noticeFile rootProject.file('NOTICE.txt')
}

repositories {
    mavenCentral()
}

dependencies {
    compile "org.elasticsearch:elasticsearch:" + esVersion
    compile "com.qcloud:cos_api:5.6.8"
    compile "commons-codec:commons-codec:1.11"
    compile "commons-logging:commons-logging:1.1.3"
    compile "org.slf4j:slf4j-log4j12:1.7.21"
    compile "org.slf4j:slf4j-api:1.7.21"
    compile "log4j:log4j:1.2.17"
    compile "com.fasterxml.jackson.core:jackson-core:2.8.11"
    compile "com.fasterxml.jackson.core:jackson-annotations:2.9.4"
    compile "com.fasterxml.jackson.core:jackson-databind:2.9.4"
    compile "org.apache.httpcomponents:httpclient:4.5.8"
    compile "org.apache.httpcomponents:httpcore:4.4.11"
}

bundlePlugin {

}

test {
    exclude '**/CosRepositoryThirdPartyTests.class'
    dependsOn processTestResources
}

String cosAccessKeyId = System.getenv("qcloud_cos_access_key_id")
String cosAccessKeySecret = System.getenv("qcloud_cos_access_key_secret")
String cosBucket = System.getenv("qcloud_cos_bucket")
String cosBasePath = System.getenv("qcloud_cos_base_path")
String cosRegion = System.getenv("qcloud_cos_region")

task thirdPartyTest(type: Test) {
    include '**/CosRepositoryThirdPartyTests.class'
    systemProperty 'es.allow_insecure_settings', 'true'
    systemProperty 'access_key_id', cosAccessKeyId
    systemProperty 'access_key_secret', cosAccessKeySecret
    systemProperty 'bucket', cosBucket
    systemProperty 'base_path', cosBasePath
    systemProperty 'region', cosRegion
}

thirdPartyTest {
    dependsOn tasks.bundlePlugin
}

processTestResources {
    Map<String, Object> expansions = [
            'bucket': cosBucket,
            'base_path': cosBasePath,
    ]
    inputs.properties(expansions)
    MavenFilteringHack.filter(it, expansions)
}

integTest {
    dependsOn processTestResources
}

// elasticsearch.esplugin task configure
checkstyleMain.enabled = false
checkstyleTest.enabled = false
dependencyLicenses.enabled = false
licenseMain.enabled = false
thirdPartyAudit.enabled = false
licenseHeaders.enabled = false
forbiddenApisMain.enabled = false
forbiddenApisTest.enabled = false
licenseTest.enabled = false

```

---

<div class="post-metadata">

**Author:** ![Ethan-Zhang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ethan-zhang/32/54812_2.png) [@Ethan-Zhang](https://discuss.elastic.co/u/Ethan-Zhang)\
**Post date:** [December 20, 2019, 9:47am UTC](https://discuss.elastic.co/t/how-to-use-mavenfilteringhack-to-replace-var-from-yaml-files/209959/4 "2019-12-20T09:47:46Z")

</div>

It worked. Because I did not match the var name both in MavenFilteringHack and YAML file.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 17, 2020, 9:57am UTC](https://discuss.elastic.co/t/how-to-use-mavenfilteringhack-to-replace-var-from-yaml-files/209959/5 "2020-01-17T09:57:53Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
