How to add custom properties to configurations


(extern.christoph.kuhnke) #1

I’d like to use a custom syntax within closure argument to “configurations” in my dependency configuration file

configurations {
    configA
    configB { userProperty 'user value' }
}

When executing gradle, I get error message “Could not find method userProperty() for arguments [user value] on configuration ‘:configB’.”

My plan is to implement a custom class Configuration, resp. replace or extend class DefaultConfiguration.

By browsing the source of gradle it seems to me, that I have to implement ConfigurationContainer, resp. replace or extend DefaultConfigurationContainer.

I wonder, whether this is the best way and whether it is wise to extend internal gradle classes.

  • Is there an easier or recommended solution? - Could plugins help here? - Are there properties or methods of Project, that are better suited to achieve my task?

I’m currently bound to gradle 1.4, but the problem seems to be identical up to gradle 1.7.

Greetings, Chris.


(Attila Kelemen) #2

Instead of writing ‘userProperty ‘user value’’ which is equivalent to a method call: ‘userProperty(‘user value’)’. You have to write ‘ext.userProperty = ‘user value’’. Actually, “ext” is usable in most context.

I would avoid implementing interfaces of the Gradle API because often new methods are added to existing interfaces in new versions of Gradle. Extending implementations are problematic as well because they are usually “internal”.