Gradle
  1. Gradle
  2. GRADLE-1419

Add support for loading arbitrary properties files as per gradle.properties

    Details

    • Type: New Feature New Feature
    • Status: Open Open
    • Resolution: Unresolved
    • Affects Version/s: 1.0-milestone-1
    • Fix Version/s: None

      Description

      Gradle can currently load properties from a file called gradle.properties in the project directory. It would be great if the functionality that loads gradle.properties was made available as part of the dsl in order to load any arbitrary properties file as per the Ant <property> element.

        Issue Links

          Activity

          Hide
          Kevin Stembridge
          added a comment -

          Very nice Ido.

          I'd love to see the Gradle team make this available as a top-level method. They should also consider making it more flexible in how we specify the files to be loaded. e.g. classpath-relative, collections of files, etc.

          Show
          Kevin Stembridge
          added a comment - Very nice Ido. I'd love to see the Gradle team make this available as a top-level method. They should also consider making it more flexible in how we specify the files to be loaded. e.g. classpath-relative, collections of files, etc.
          Hide
          Jonas
          added a comment -

          You say "The properties are loaded as extra properties of your project, so when reading them you don't use the "ext." qualifier (read them just like dynamic properties), as opposed to when writing into them."

          Could you please give an exact example?

          Show
          Jonas
          added a comment - You say "The properties are loaded as extra properties of your project, so when reading them you don't use the "ext." qualifier (read them just like dynamic properties), as opposed to when writing into them." Could you please give an exact example?
          Hide
          Blaine Simpson
          added a comment - - edited

          I forgot to update this discussion last year. I updated my JavaPropFile plugin promptly. It supports the current API without warnings, and hasn't needed any modification since because of the rigorous unit tests. It will be updated aggresively whenever there is a need because it is used by very active open source projects. H

          Ido's snippet satisfies the most common use case. I often need more, like support for types other than strings, nesting of values, ability to reference sys properties (and set them), adding to arbitrary scope (not just the project), validation, default values, etc. See the feature list.

          Show
          Blaine Simpson
          added a comment - - edited I forgot to update this discussion last year. I updated my JavaPropFile plugin promptly. It supports the current API without warnings, and hasn't needed any modification since because of the rigorous unit tests. It will be updated aggresively whenever there is a need because it is used by very active open source projects. H Ido's snippet satisfies the most common use case. I often need more, like support for types other than strings, nesting of values, ability to reference sys properties (and set them), adding to arbitrary scope (not just the project), validation, default values, etc. See the feature list .
          Hide
          Ido
          added a comment -

          You say "The properties are loaded as extra properties of your project, so when reading them you don't use the "ext." qualifier (read them just like dynamic properties), as opposed to when writing into them."

          Could you please give an exact example?

          Sure:

          myprops.properties
          db-host-addr=100.100.100.100
          db-port=222
          db-name=myDB
          
          build.gradle
          ...
          loadProperties 'myprops.properties'
          ...
          println db-name // output: myDB
          ...
          
          Show
          Ido
          added a comment - You say "The properties are loaded as extra properties of your project, so when reading them you don't use the "ext." qualifier (read them just like dynamic properties), as opposed to when writing into them." Could you please give an exact example? Sure: myprops.properties db-host-addr=100.100.100.100 db-port=222 db-name=myDB build.gradle ... loadProperties 'myprops.properties' ... println db-name // output: myDB ...
          Hide
          Raja Nagendra Kumar
          added a comment - - edited

          It would be nice to have this as default method.
          Else, we need to include the script for loadProperties everywhere.. as loading properties from any where is so commonly used. More so this method is no optimal as one needs to read and assign to global properties.

          Please consider to get this ASAP.

          Regards,
          Raja Nagendra Kumar

          Show
          Raja Nagendra Kumar
          added a comment - - edited It would be nice to have this as default method. Else, we need to include the script for loadProperties everywhere.. as loading properties from any where is so commonly used. More so this method is no optimal as one needs to read and assign to global properties. Please consider to get this ASAP. Regards, Raja Nagendra Kumar

            People

            • Assignee:
              Unassigned
              Reporter:
              Kevin Stembridge
            • Votes:
              12 Vote for this issue
              Watchers:
              16 Start watching this issue

              Dates

              • Created:
                Updated: