# Create a property for build script locations

**URL:** <https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787>\
**Category:** Help/Discuss\
**Created:** [May 16, 2019, 2:14am UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787 "2019-05-16T02:14:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![deanhiller](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/deanhiller/32/5516_2.png) [@deanhiller](https://discuss.gradle.org/u/deanhiller)\
**Post date:** [May 16, 2019, 2:14am UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/1 "2019-05-16T02:14:29Z")

</div>

I have the following code in one build.gradle file. NOTICE the line “classpath ‘org.webpieces:gradle-plugin-htmlcompiler:1.9.98’”

buildscript {  
…  
dependencies {  
classpath ‘org.webpieces:gradle-plugin-htmlcompiler:1.9.98’  
}  
}

Then, I have this section in the master build.gradle file which is used by all the jar dependencies.

ext {  
webpiecesVersion = ‘1.9.98’  
…  
}

How can I create a property that both of those things use so I only have to modify the version in one location?

thanks,  
Dean

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [May 16, 2019, 10:24pm UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/2 "2019-05-16T22:24:35Z")

</div>

I believe project properties are available in the buildscript block, so you should be able to add a gradle.properties file to the root directory of your project and place the line `foo=1.2.3` in there and then just use `$foo` where you need it.

---

<div class="post-metadata">

**Author:** ![deanhiller](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/deanhiller/32/5516_2.png) [@deanhiller](https://discuss.gradle.org/u/deanhiller)\
**Post date:** [June 16, 2019, 2:51pm UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/3 "2019-06-16T14:51:27Z")

</div>

nope! doesn’t seem to work. Easy to reproduce the failure though

(RUN exact commands…do NOT rename project)

git clone [https://github.com/deanhiller/webpiecesexample-all.git](https://github.com/deanhiller/webpiecesexample-all.git)  
cd webpiecesexample-all/  
git checkout -t origin/testBuildScriptReadProperties  
./gradlew build

FAILS with  
Could not find org.webpieces:gradle-plugin-htmlcompiler:${webpiecesVersion}

IMPORTANT files  
webpiecesexample-all/gradle.properties contains variable  
webpiecesexample-all/build.gradle USES variable just fine  
webpiecesexample-all/webpiecesexample/build.gradle has buildscript trying to use the variable and fails

---

<div class="post-metadata">

**Author:** ![deanhiller](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/deanhiller/32/5516_2.png) [@deanhiller](https://discuss.gradle.org/u/deanhiller)\
**Post date:** [June 20, 2019, 1:50am UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/4 "2019-06-20T01:50:21Z")

</div>

bump! oh, but I need 20 characters to bump this thread…grrr.

---

<div class="post-metadata">

**Author:** ![deanhiller](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/deanhiller/32/5516_2.png) [@deanhiller](https://discuss.gradle.org/u/deanhiller)\
**Post date:** [June 23, 2019, 9:02pm UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/5 "2019-06-23T21:02:29Z")

</div>

bump…anyone? would love to get just a little advice on this. @Schalk_Cronje any ideas?

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [June 23, 2019, 9:47pm UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/6 "2019-06-23T21:47:38Z")

</div>

Well this works for me:

```groovy
buildscript {
        repositories {
                jcenter()
        }

        dependencies {
                classpath "org.jsoup:jsoup:$jsoupVersion"
        }
}

```

```gradle
$ gradle tasks -PjsoupVersion=1.10.2

```

```gradle

```

---

<div class="post-metadata">

**Author:** ![deanhiller](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/deanhiller/32/5516_2.png) [@deanhiller](https://discuss.gradle.org/u/deanhiller)\
**Post date:** [June 23, 2019, 10:00pm UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/7 "2019-06-23T22:00:17Z")

</div>

@Schalk_Cronje hmmm, do you have an example with it working in properties files. I mean I am thinking I don’t want to put all property versions on the command line. That would be really annoying for something that never changes. ie.

gradle tasks -PjsoupVersion=1.10.2 -PwebpiecesVersion=1.5 -Pslf4jVersion=1.4

kind of gets a bit unweildy for people that want to build the project, right? (and more importantly, than they need to know all the versions or I need to create a bash script but gradle should really handle that instead so I don’t need a bash script).

thanks!!!  
Dean

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [June 23, 2019, 10:13pm UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/8 "2019-06-23T22:13:00Z")

</div>

You can set it by adding a `gradle.properties` files in the root of the project i.e.

```gradle
jsoupVersion=1.10.2

```

Only limitations of the above are:

- You cannot substitute project properties into the version of a plugin when supplied in the `plugins {}` block.
- You can use propertjies from `gradle.properties` in `buildSrc` - for that you will need to do some more magic.

---

<div class="post-metadata">

**Author:** ![deanhiller](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/deanhiller/32/5516_2.png) [@deanhiller](https://discuss.gradle.org/u/deanhiller)\
**Post date:** [June 24, 2019, 4:17am UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/9 "2019-06-24T04:17:51Z")

</div>

@Schalk_Cronje I’m very confused now then. Have you not tried the simple and quick 4 steps above I gave in my example? It doesn’t seem to be working.

They were simply

git clone [https://github.com/deanhiller/webpiecesexample-all.git](https://github.com/deanhiller/webpiecesexample-all.git)  
cd webpiecesexample-all/  
git checkout -t origin/testBuildScriptReadProperties  
./gradlew build

fails with “Could not find org.webpieces:gradle-plugin-htmlcompiler:${webpiecesVersion}”

thanks,  
Dean

---

<div class="post-metadata">

**Author:** ![Schalk\_Cronje](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/schalk_cronje/32/6511_2.png) [@Schalk\_Cronje](https://discuss.gradle.org/u/Schalk_Cronje)\
**Post date:** [June 24, 2019, 9:44am UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/10 "2019-06-24T09:44:19Z")

</div>

@deanhiller The problem is not `gradle.properties`, but the fact that you used a non-interpolated string in `webpiecesexample/build.gradle`. Switch to using `"org.webpieces:gradle-plugin-htmlcompiler:${webpiecesVersion}"` instead.

---

<div class="post-metadata">

**Author:** ![deanhiller](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/deanhiller/32/5516_2.png) [@deanhiller](https://discuss.gradle.org/u/deanhiller)\
**Post date:** [June 24, 2019, 5:00pm UTC](https://discuss.gradle.org/t/create-a-property-for-build-script-locations/31787/11 "2019-06-24T17:00:35Z")

</div>

@Schalk_Cronje thanks so much!!! worked like a charm. sorry, duh me.
