# Locking a configuration

**URL:** <https://discuss.gradle.org/t/locking-a-configuration/6662>\
**Category:** Old Forum Archive\
**Created:** [April 11, 2014, 2:59am UTC](https://discuss.gradle.org/t/locking-a-configuration/6662 "2014-04-11T02:59:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Baron\_Roberts](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@Baron\_Roberts](https://discuss.gradle.org/u/Baron_Roberts)\
**Post date:** [April 11, 2014, 2:59am UTC](https://discuss.gradle.org/t/locking-a-configuration/6662/1 "2014-04-11T02:59:00Z")

</div>

Is there a mechanism for a configuration to be “locked”. That is, prevent a configuration from being effected by an upstream build script performing an “all” closure and thereby effecting a configuration that may be in a plugin. In my case I had a build.gradle set transitive to false in an “all” configurations closure. Needless to say this broken my plugin with a ClassDefNotFound exception.

---

<div class="post-metadata">

**Author:** ![bmuschko](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/bmuschko/32/5458_2.png) [@bmuschko](https://discuss.gradle.org/u/bmuschko)\
**Post date:** [April 11, 2014, 12:57pm UTC](https://discuss.gradle.org/t/locking-a-configuration/6662/2 "2014-04-11T12:57:00Z")

</div>

You might want to look into making the configuration [non-visible](http://www.gradle.org/docs/current/javadoc/org/gradle/api/artifacts/Configuration.html#setVisible(boolean)). I am not sure if that will solve your problem. Let me know if that works for you.

---

<div class="post-metadata">

**Author:** ![Baron\_Roberts](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@Baron\_Roberts](https://discuss.gradle.org/u/Baron_Roberts)\
**Post date:** [April 12, 2014, 5:40pm UTC](https://discuss.gradle.org/t/locking-a-configuration/6662/3 "2014-04-12T17:40:00Z")

</div>

Thanks Ben, how does this setting work for a plugin? If a plugin has its internal configuration(s) visibility set to false, can the project applying the plugin see and/or change the configuration?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [April 12, 2014, 5:56pm UTC](https://discuss.gradle.org/t/locking-a-configuration/6662/4 "2014-04-12T17:56:00Z")

</div>

‘visible’ won’t help here. If a plugin wants to internally use a configuration, it should create a detached configuration with ‘configurations.detachedConfiguration’. Such a configuration isn’t added to the configuration container, and therefore isn’t accessible to anyone else (including ‘configurations.all’ rules).

---

<div class="post-metadata">

**Author:** ![Baron\_Roberts](https://avatars.discourse-cdn.com/v4/letter/b/a3d4f5/32.png) [@Baron\_Roberts](https://discuss.gradle.org/u/Baron_Roberts)\
**Post date:** [April 12, 2014, 7:56pm UTC](https://discuss.gradle.org/t/locking-a-configuration/6662/5 "2014-04-12T19:56:00Z")

</div>

Thanks Peter! This sounds exactly like what I need.

I am a little surprised that this method does not get more publicity (i.e. a mention in the users guide for this use case, an expanded description in the Javadoc). Seems like a very important method for plugin developers to consider. Any large site with many developers will likely hit the issue of someone doing a configurations.all in their build.gradle that busts various plugins. I am inclined to treat all my plugin configurations as detached unless I explicitly intend the applying build.gradle to manipulate it.

Cheers, Baron

---

<div class="post-metadata">

**Author:** ![Szczepan\_Faber](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/szczepan_faber/32/213_2.png) [@Szczepan\_Faber](https://discuss.gradle.org/u/Szczepan_Faber)\
**Post date:** [April 14, 2014, 9:26am UTC](https://discuss.gradle.org/t/locking-a-configuration/6662/6 "2014-04-14T09:26:00Z")

</div>

I wouldn’t use detached configurations in this instance. Detached configuration does not give the user any way to influence the resolution.

Baron’s use case (I have the insider info 🙂 is wrapping a built-in checkstyle plugin with his own, specifically configured checkstyle plugin. I think it is really important if tools like checkstyle, jacoco, findbugs, etc expose the configurations they use.
