├── .github
└── workflows
│ ├── release.yml
│ └── test.yml
├── .gitignore
├── .releaserc
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── build.gradle.kts
├── gradle.properties
├── gradle
├── libs.versions.toml
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample-app
├── .gitignore
├── build.gradle.kts
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── google
│ │ └── secrets_gradle_plugin
│ │ └── sample
│ │ └── MainActivity.kt
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ └── ic_launcher_background.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── values-night
│ └── themes.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── themes.xml
├── secrets-gradle-plugin
├── .gitignore
├── build.gradle.kts
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── google
│ │ └── android
│ │ └── libraries
│ │ └── mapsplatform
│ │ └── secrets_gradle_plugin
│ │ ├── Extensions.kt
│ │ ├── SecretsPlugin.kt
│ │ └── SecretsPluginExtension.kt
│ └── test
│ └── kotlin
│ └── com
│ └── google
│ └── android
│ └── libraries
│ └── mapsplatform
│ └── secrets_gradle_plugin
│ └── SecretsPluginTest.kt
├── secrets.defaults.properties
├── secrets.properties
└── settings.gradle.kts
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | name: Release
16 | on:
17 | push:
18 | branches: [ ]
19 | workflow_dispatch:
20 | jobs:
21 | release:
22 | runs-on: ubuntu-latest
23 | steps:
24 | - name: Checkout
25 | uses: actions/checkout@v4
26 |
27 | - name: Set up JDK 17
28 | uses: actions/setup-java@v4.2.1
29 | with:
30 | java-version: '17'
31 | distribution: 'temurin'
32 |
33 | - name: Copy secrets to gradle.properties
34 | run: |
35 | sed -i -e "s,gradle.publish.key=,gradle.publish.key=$GRADLE_PUBLISH_KEY,g" gradle.properties
36 | sed -i -e "s,gradle.publish.secret=,gradle.publish.secret=$GRADLE_PUBLISH_SECRET,g" gradle.properties
37 | env:
38 | GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUB_KEY }}
39 | GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUB_SEC }}
40 |
41 | - name: Set up node
42 | uses: actions/setup-node@v4
43 | with:
44 | node-version: '14'
45 |
46 | - name: Install conventionalcommits
47 | run: npm i -D conventional-changelog-conventionalcommits
48 |
49 | - name: Semantic Release
50 | uses: cycjimmy/semantic-release-action@v4.1.0
51 | with:
52 | extra_plugins: |
53 | "@semantic-release/commit-analyzer@8.0.1"
54 | "@semantic-release/release-notes-generator@9.0.3"
55 | "@google/semantic-release-replace-plugin@1.2.0"
56 | "@semantic-release/exec@5.0.0"
57 | "@semantic-release/git@9.0.1"
58 | "@semantic-release/github@7.2.3"
59 | env:
60 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | # A workflow that runs tests on every new pull request
16 | name: Tests
17 |
18 | on:
19 | repository_dispatch:
20 | types: [test]
21 | pull_request:
22 | branches: ['*']
23 | workflow_dispatch:
24 |
25 | jobs:
26 | run-unit-test:
27 | runs-on: ubuntu-latest
28 |
29 | steps:
30 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
31 | - name: Checkout Repo
32 | uses: actions/checkout@v2
33 |
34 | - name: Set up JDK 17
35 | uses: actions/setup-java@v4.2.1
36 | with:
37 | java-version: '17'
38 | distribution: 'temurin'
39 |
40 | - name: Run tests
41 | run: |
42 | echo "Running unit tests"
43 | ./gradlew :secrets-gradle-plugin:build check test -x lint --stacktrace
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 | .cxx
10 | local.properties
11 | .java-version
12 |
--------------------------------------------------------------------------------
/.releaserc:
--------------------------------------------------------------------------------
1 | branches:
2 | - main
3 | plugins:
4 | - "@semantic-release/commit-analyzer"
5 | - "@semantic-release/release-notes-generator"
6 | - - "@google/semantic-release-replace-plugin"
7 | - replacements:
8 | - files:
9 | - "./secrets-gradle-plugin/build.gradle.kts"
10 | from: "const val version = \".*\""
11 | to: "const val version = \"${nextRelease.version}\""
12 | - files:
13 | - "README.md"
14 | from: "version \".*\""
15 | to: "version \"${nextRelease.version}\""
16 | - files:
17 | - "README.md"
18 | from: "version '.*'"
19 | to: "version '${nextRelease.version}'"
20 | - - "@semantic-release/exec"
21 | - prepareCmd: "./gradlew build --warn --stacktrace"
22 | publishCmd: "./gradlew publishPlugins --warn --stacktrace"
23 | - - "@semantic-release/git"
24 | - assets:
25 | - "./secrets-gradle-plugin/build.gradle.kts"
26 | - "*.md"
27 | - "@semantic-release/github"
28 | options:
29 | debug: true
30 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Google Open Source Community Guidelines
2 |
3 | At Google, we recognize and celebrate the creativity and collaboration of open
4 | source contributors and the diversity of skills, experiences, cultures, and
5 | opinions they bring to the projects and communities they participate in.
6 |
7 | Every one of Google's open source projects and communities are inclusive
8 | environments, based on treating all individuals respectfully, regardless of
9 | gender identity and expression, sexual orientation, disabilities,
10 | neurodiversity, physical appearance, body size, ethnicity, nationality, race,
11 | age, religion, or similar personal characteristic.
12 |
13 | We value diverse opinions, but we value respectful behavior more.
14 |
15 | Respectful behavior includes:
16 |
17 | * Being considerate, kind, constructive, and helpful.
18 | * Not engaging in demeaning, discriminatory, harassing, hateful, sexualized, or
19 | physically threatening behavior, speech, and imagery.
20 | * Not engaging in unwanted physical contact.
21 |
22 | Some Google open source projects [may adopt][] an explicit project code of
23 | conduct, which may have additional detailed expectations for participants. Most
24 | of those projects will use our [modified Contributor Covenant][].
25 |
26 | [may adopt]: https://opensource.google/docs/releasing/preparing/#conduct
27 | [modified Contributor Covenant]: https://opensource.google/docs/releasing/template/CODE_OF_CONDUCT/
28 |
29 | ## Resolve peacefully
30 |
31 | We do not believe that all conflict is necessarily bad; healthy debate and
32 | disagreement often yields positive results. However, it is never okay to be
33 | disrespectful.
34 |
35 | If you see someone behaving disrespectfully, you are encouraged to address the
36 | behavior directly with those involved. Many issues can be resolved quickly and
37 | easily, and this gives people more control over the outcome of their dispute.
38 | If you are unable to resolve the matter for any reason, or if the behavior is
39 | threatening or harassing, report it. We are dedicated to providing an
40 | environment where participants feel welcome and safe.
41 |
42 | ## Reporting problems
43 |
44 | Some Google open source projects may adopt a project-specific code of conduct.
45 | In those cases, a Google employee will be identified as the Project Steward,
46 | who will receive and handle reports of code of conduct violations. In the event
47 | that a project hasn’t identified a Project Steward, you can report problems by
48 | emailing opensource@google.com.
49 |
50 | We will investigate every complaint, but you may not receive a direct response.
51 | We will use our discretion in determining when and how to follow up on reported
52 | incidents, which may range from not taking action to permanent expulsion from
53 | the project and project-sponsored spaces. We will notify the accused of the
54 | report and provide them an opportunity to discuss it before any action is
55 | taken. The identity of the reporter will be omitted from the details of the
56 | report supplied to the accused. In potentially harmful situations, such as
57 | ongoing harassment or threats to anyone's safety, we may take action without
58 | notice.
59 |
60 | *This document was adapted from the [IndieWeb Code of Conduct][] and can also
61 | be found at .*
62 |
63 | [IndieWeb Code of Conduct]: https://indieweb.org/code-of-conduct
64 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows
28 | [Google's Open Source Community Guidelines](https://opensource.google/conduct/).
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Secrets Gradle Plugin for Android
2 | 
3 | 
4 |
5 | A Gradle plugin for providing your secrets securely to your Android project.
6 |
7 | This Gradle plugin reads secrets from a properties file **not checked into version control**,
8 | such as `local.properties`, and expose those properties as variables in the Gradle-generated `BuildConfig`
9 | class and in the Android manifest file.
10 |
11 | **DISCLAIMER:** This plugin is primarily for hiding your keys from version control. Since your key is part of the static binary, your API keys are still recoverable by decompiling an APK. So, securing your key using other measures like adding restrictions (if possible) are recommended.
12 |
13 | ## Requirements
14 | * Gradle-based Android project
15 | * Android Gradle plugin 7.0.2
16 |
17 | ## Installation
18 |
19 | **NOTE**: Starting from v1.1.0, the plugin ID was changed to "com.google.android.libraries.mapsplatform.secrets-gradle-plugin" and the plugin is now being distributed via Google Maven (gMaven). You can still download previous versions of the plugin from Gradle's plugin portal, but new versions will now only be distributed through gMaven.
20 |
21 | 1. In your project's root `build.gradle` file:
22 |
23 | Groovy:
24 | ```groovy
25 | buildscript {
26 | dependencies {
27 | classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1"
28 | }
29 | }
30 | ```
31 |
32 | Kotlin:
33 | ```kotlin
34 | buildscript {
35 | dependencies {
36 | classpath("com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1")
37 | }
38 | }
39 | ```
40 |
41 | 2. In your app-level `build.gradle` file:
42 |
43 | Groovy:
44 | ```groovy
45 | plugins {
46 | id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
47 | }
48 | ```
49 |
50 | Kotlin:
51 | ```groovy
52 | plugins {
53 | id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
54 | }
55 | ```
56 |
57 | This plugin also supports library module type (`com.android.library`). Just install the plugin in your library-level `build.gradle` file and keys will be visible inside that module as well.
58 |
59 | ### Snapshot Releases
60 |
61 | Snapshot releases, which are distributed via [GitHub Packages](https://github.com/orgs/google/packages?repo_name=secrets-gradle-plugin), are also available for latest fixes. To use a snapshot release, add the following repository to your project-level `build.gradle` file:
62 |
63 | Groovy:
64 | ```groovy
65 | buildscript {
66 | repositories {
67 | maven {
68 | url = uri("https://maven.pkg.github.com/google/secrets-gradle-plugin")
69 | credentials {
70 | username = project.findProperty("GITHUB_USER") ?: System.getenv("GITHUB_USER")
71 | password = project.findProperty("GITHUB_TOKEN") ?: System.getenv("GITHUB_TOKEN")
72 | }
73 | }
74 | }
75 | dependencies {
76 | classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:-SNAPSHOT"
77 | }
78 | }
79 | ```
80 |
81 | Also, see [Authenticating to GitHub Packages](https://docs.github.com/en/packages/learn-github-packages/introduction-to-github-packages#authenticating-to-github-packages).
82 |
83 |
84 | ## Example Usage
85 |
86 | Example contents of `local.properties` under your root project:
87 | ```
88 | apiKey=YOUR_API_KEY
89 | ```
90 |
91 | After applying the plugin and building your project, the API key then becomes accessible in two ways.
92 |
93 | 1. As a `BuildConfig` value:
94 | ```kotlin
95 | val apiKey = BuildConfig.apiKey
96 | ```
97 | 2. As a variable accessible in your `AndroidManifest.xml` file:
98 | ```xml
99 |
100 | ```
101 |
102 | ## CI/CD Systems
103 |
104 | For CI/CD systems, consider creating and checking in version control a default properties file with all
105 | the same keys required by your app but with _safe_ default values. To do this, create a properties file
106 | and set the `defaultPropertiesFileName` value to that file name. For example:
107 |
108 | ```groovy
109 | secrets {
110 | defaultPropertiesFileName = 'local.defaults.properties'
111 | }
112 | ```
113 |
114 | ## Configuration Options
115 |
116 | The plugin can optionally be configured:
117 |
118 | ```groovy
119 | secrets {
120 | // Change the properties file from the default "local.properties" in your root project
121 | // to another properties file in your root project.
122 | propertiesFileName 'secrets.properties'
123 |
124 | // A properties file containing default secret values. This file can be checked in version
125 | // control.
126 | defaultPropertiesFileName = 'secrets.defaults.properties'
127 |
128 | // Configure which keys should be ignored by the plugin by providing regular expressions.
129 | // "sdk.dir" is ignored by default.
130 | ignoreList.add("keyToIgnore") // Ignore the key "keyToIgnore"
131 | ignoreList.add("sdk.*") // Ignore all keys matching the regexp "sdk.*"
132 | }
133 | ```
134 |
135 | ### Build-Variant Specific Properties
136 |
137 | To set build-variant specific properties (build type or flavor), create a properties file at the
138 | root directory of the project with the same name as the variant. For example, to set keys specific
139 | for the `release` build type, create a new file called `release.properties` containing
140 | release-specific keys.
141 |
142 | ## Contributing
143 |
144 | Contributions to this library are always welcome and highly encouraged!
145 |
146 | See [CONTRIBUTING.md](CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for more
147 | information on how to get started.
148 |
149 | ## License
150 | Apache 2.0. See [LICENSE](LICENSE) for more information.
151 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | // Copyright 2024 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | buildscript {
15 |
16 | repositories {
17 | mavenLocal()
18 | google()
19 | mavenCentral()
20 | maven {
21 | url = uri("https://maven.pkg.github.com/google/secrets-gradle-plugin")
22 | credentials {
23 | username = project.findProperty("ghGprUser") as String? ?: System.getenv("ghGprUser")
24 | password = project.findProperty("ghGprToken") as String? ?: System.getenv("ghGprToken")
25 | }
26 | }
27 | }
28 |
29 | dependencies {
30 | classpath(libs.gradle.v842)
31 | classpath(libs.kotlin.gradle.plugin)
32 | classpath(libs.secrets.gradle.plugin)
33 |
34 | // NOTE: Do not place your application dependencies here; they belong
35 | // in the individual module build.gradle.kts files
36 | }
37 | }
38 |
39 | allprojects {
40 | repositories {
41 | google()
42 | mavenCentral()
43 | }
44 | }
45 |
46 | tasks.register("clean") {
47 | delete(rootProject.layout.buildDirectory)
48 | }
49 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
23 | gradle.publish.key=
24 | gradle.publish.secret=
25 |
26 | ghGprUser=
27 | ghGprToken=
28 | android.defaults.buildfeatures.buildconfig=true
29 | android.nonTransitiveRClass=false
30 | android.nonFinalResIds=false
31 |
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | gradle = "7.0.4"
3 | gradleVersion = "8.4.2"
4 | junit = "4.13.2"
5 | kotlin = "1.9.24"
6 | kotlinGradlePlugin = "2.0.0"
7 | material = "1.12.0"
8 | appcompat = "1.7.0"
9 | mockitoKotlin = "2.2.0"
10 | secretsGradlePlugin = "2.0.1"
11 |
12 | [libraries]
13 | gradle = { module = "com.android.tools.build:gradle", version.ref = "gradle" }
14 | gradle-v842 = { module = "com.android.tools.build:gradle", version.ref = "gradleVersion" }
15 | junit = { module = "junit:junit", version.ref = "junit" }
16 | kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinGradlePlugin" }
17 | kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version.ref = "kotlin" }
18 | material = { group = "com.google.android.material", name = "material", version.ref = "material" }
19 | appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
20 | mockito-kotlin = { module = "com.nhaarman.mockitokotlin2:mockito-kotlin", version.ref = "mockitoKotlin" }
21 | secrets-gradle-plugin = { module = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin", version.ref = "secretsGradlePlugin" }
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 26 22:14:52 PST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/sample-app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/sample-app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | // Copyright 2021 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | plugins {
16 | id("com.android.application")
17 | id("kotlin-android")
18 |
19 | // 1. Include the plugin
20 | id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
21 | }
22 |
23 | android {
24 | compileSdk = 34
25 |
26 | defaultConfig {
27 | applicationId = "com.google.secrets_plugin.sample"
28 | minSdk = 21
29 | targetSdk = 34
30 | versionCode = 1
31 | versionName = "1.0"
32 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
33 | }
34 | compileOptions {
35 | sourceCompatibility = JavaVersion.VERSION_17
36 | targetCompatibility = JavaVersion.VERSION_17
37 | }
38 | kotlinOptions {
39 | jvmTarget = "17"
40 | }
41 | namespace = "com.google.secrets_plugin.sample"
42 | }
43 |
44 | dependencies {
45 | implementation(libs.kotlin.stdlib)
46 | implementation(libs.material)
47 | implementation(libs.appcompat)
48 | }
49 |
50 | // 2. Optionally configure the plugin
51 | secrets {
52 | // Optionally specify a different file name containing your secrets.
53 | // The plugin defaults to "local.properties"
54 | propertiesFileName = "secrets.properties"
55 | defaultPropertiesFileName = "secrets.defaults.properties"
56 |
57 | // Add keys that the plugin should ignore from the properties file
58 | ignoreList.add("keyToIgnore")
59 | ignoreList.add("ignore*")
60 | }
61 |
--------------------------------------------------------------------------------
/sample-app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.kts.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/sample-app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
27 |
30 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/sample-app/src/main/java/com/google/secrets_gradle_plugin/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | // Copyright 2021 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.google.secrets_gradle_plugin.sample
16 |
17 | import androidx.appcompat.app.AppCompatActivity
18 |
19 | /**
20 | * Dummy activity. See build.gradle.kts for sample usage of the plugin.
21 | */
22 | class MainActivity : AppCompatActivity() {
23 | }
--------------------------------------------------------------------------------
/sample-app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
23 |
24 |
25 |
31 |
34 |
37 |
38 |
39 |
40 |
46 |
--------------------------------------------------------------------------------
/sample-app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
23 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
176 |
181 |
186 |
187 |
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/sample-app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/sample-app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/sample-app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/sample-app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/sample-app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/sample-app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/sample-app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/sample-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/sample-app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/secrets-gradle-plugin/5c3b339fe27d99da803b4a007086d4338139087c/sample-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample-app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
32 |
--------------------------------------------------------------------------------
/sample-app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | #FFBB86FC
20 | #FF6200EE
21 | #FF3700B3
22 | #FF03DAC5
23 | #FF018786
24 | #FF000000
25 | #FFFFFFFF
26 |
--------------------------------------------------------------------------------
/sample-app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | 16dp
19 |
--------------------------------------------------------------------------------
/sample-app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | My Application
19 | Settings
20 |
21 | First Fragment
22 | Second Fragment
23 | Next
24 | Previous
25 |
26 | Hello first fragment
27 | Hello second fragment. Arg: %1$s
28 |
--------------------------------------------------------------------------------
/sample-app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
32 |
33 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/secrets-gradle-plugin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/secrets-gradle-plugin/build.gradle.kts:
--------------------------------------------------------------------------------
1 | // Copyright 2021 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | plugins {
16 | `java-gradle-plugin`
17 | `maven-publish`
18 | id("kotlin")
19 | }
20 |
21 | java {
22 | sourceCompatibility = JavaVersion.VERSION_17
23 | targetCompatibility = JavaVersion.VERSION_17
24 | }
25 |
26 | dependencies {
27 | compileOnly(libs.gradle)
28 | implementation(libs.kotlin.stdlib)
29 | testImplementation(libs.gradle)
30 | testImplementation(libs.junit)
31 | testImplementation(libs.mockito.kotlin)
32 | }
33 |
34 | gradlePlugin {
35 | plugins {
36 | create(PluginInfo.name) {
37 | id = PluginInfo.group
38 | implementationClass = PluginInfo.implementationClass
39 | displayName = PluginInfo.displayName
40 | description = PluginInfo.description
41 | }
42 | }
43 | }
44 |
45 | publishing {
46 | publications {
47 | create("mavenPub") {
48 | group = PluginInfo.group
49 | artifactId = PluginInfo.artifactId
50 | version = PluginInfo.version
51 |
52 | pom {
53 | name.set(PluginInfo.artifactId)
54 | description.set(PluginInfo.description)
55 | url.set(PluginInfo.url)
56 |
57 | scm {
58 | connection.set("scm:git@github.com:google/secrets-gradle-plugin.git")
59 | developerConnection.set("scm:git@github.com:google/secrets-gradle-plugin.git")
60 | url.set(PluginInfo.url)
61 | }
62 |
63 | licenses {
64 | license {
65 | name.set("The Apache Software License, Version 2.0")
66 | url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
67 | distribution.set("repo")
68 | }
69 | }
70 |
71 | organization {
72 | name.set("Google Inc.")
73 | url.set("https://developers.google.com/maps")
74 | }
75 |
76 |
77 | developers {
78 | developer {
79 | name.set("Google Inc.")
80 | }
81 | }
82 | }
83 | }
84 | }
85 | repositories {
86 | maven {
87 | name = "localPluginRepository"
88 | url = uri("build/repository")
89 | }
90 | mavenLocal()
91 | }
92 | }
93 |
94 | project(":secrets-gradle-plugin") {
95 | version = PluginInfo.version
96 | }
97 |
98 | object PluginInfo {
99 | const val artifactId =
100 | "com.google.android.libraries.mapsplatform.secrets-gradle-plugin.gradle.plugin"
101 | const val description = "A Gradle plugin for providing secrets securely to an Android project."
102 | const val displayName = "Secrets Gradle Plugin for Android"
103 | const val group = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin"
104 | const val implementationClass =
105 | "com.google.android.libraries.mapsplatform.secrets_gradle_plugin.SecretsPlugin"
106 | const val name = "secretsGradlePlugin"
107 | const val url = "https://github.com/google/secrets-gradle-plugin"
108 | const val version = "2.0.2"
109 | }
--------------------------------------------------------------------------------
/secrets-gradle-plugin/src/main/java/com/google/android/libraries/mapsplatform/secrets_gradle_plugin/Extensions.kt:
--------------------------------------------------------------------------------
1 | // Copyright 2021 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | @file:Suppress("UnstableApiUsage")
16 |
17 | package com.google.android.libraries.mapsplatform.secrets_gradle_plugin
18 |
19 | import com.android.build.api.variant.ApplicationAndroidComponentsExtension
20 | import com.android.build.api.variant.BuildConfigField
21 | import com.android.build.api.variant.LibraryAndroidComponentsExtension
22 | import com.android.build.api.variant.Variant
23 | import com.android.build.gradle.AppExtension
24 | import com.android.build.gradle.LibraryExtension
25 | import com.android.build.gradle.internal.core.InternalBaseVariant
26 | import org.gradle.api.Project
27 | import java.io.FileNotFoundException
28 | import java.util.Properties
29 |
30 | fun Project.androidAppComponent(): ApplicationAndroidComponentsExtension? =
31 | extensions.findByType(ApplicationAndroidComponentsExtension::class.java)
32 |
33 | fun Project.androidLibraryComponent(): LibraryAndroidComponentsExtension? =
34 | extensions.findByType(LibraryAndroidComponentsExtension::class.java)
35 |
36 | fun Project.androidProject(): AppExtension? =
37 | extensions.findByType(AppExtension::class.java)
38 |
39 | fun Project.libraryProject(): LibraryExtension? =
40 | extensions.findByType(LibraryExtension::class.java)
41 |
42 | fun Project.loadPropertiesFile(fileName: String): Properties {
43 | // Load file
44 | val propertiesFile = file(fileName)
45 | if (!propertiesFile.exists()) {
46 | throw FileNotFoundException(
47 | "The file '${propertiesFile.absolutePath}' could not be found"
48 | )
49 | }
50 |
51 | // Load contents into properties object
52 | return Properties().apply {
53 | propertiesFile.inputStream().use(::load)
54 | }
55 | }
56 |
57 | private val javaVarRegexp = Regex(pattern = "((?![a-zA-Z_\$0-9]).)")
58 |
59 | fun Variant.inject(properties: Properties, ignore: List) {
60 | val ignoreRegexs = ignore.map { Regex(pattern = it) }
61 | properties.keys.map { key ->
62 | key as String
63 | }.filter { key ->
64 | key.isNotEmpty() && !ignoreRegexs.any { it.containsMatchIn(key) }
65 | }.forEach { key ->
66 | val value = properties.getProperty(key).removeSurrounding("\"")
67 | val translatedKey = key.replace(javaVarRegexp, "")
68 | buildConfigFields.put(
69 | translatedKey,
70 | BuildConfigField("String", value.addParenthesisIfNeeded(), null)
71 | )
72 | manifestPlaceholders.put(translatedKey, value)
73 | }
74 | }
75 |
76 | fun InternalBaseVariant.inject(properties: Properties, ignore: List) {
77 | val ignoreRegexs = ignore.map { Regex(pattern = it) }
78 | properties.keys.map { key ->
79 | key as String
80 | }.filter { key ->
81 | key.isNotEmpty() && !ignoreRegexs.any { it.containsMatchIn(key) }
82 | }.forEach { key ->
83 | val value = properties.getProperty(key).removeSurrounding("\"")
84 | val translatedKey = key.replace(javaVarRegexp, "")
85 | buildConfigField("String", translatedKey, value.addParenthesisIfNeeded())
86 | mergedFlavor.manifestPlaceholders[translatedKey] = value
87 | }
88 | }
89 |
90 | fun String.addParenthesisIfNeeded(): String {
91 | if (isEmpty()) {
92 | return this
93 | }
94 | val charArray = this.toCharArray()
95 | if (length > 1 && charArray[0] == '"' && charArray[charArray.size - 1] == '"') {
96 | return this
97 | }
98 | return "\"$this\""
99 | }
100 |
--------------------------------------------------------------------------------
/secrets-gradle-plugin/src/main/java/com/google/android/libraries/mapsplatform/secrets_gradle_plugin/SecretsPlugin.kt:
--------------------------------------------------------------------------------
1 | // Copyright 2021 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | @file:Suppress("UnstableApiUsage")
15 |
16 | package com.google.android.libraries.mapsplatform.secrets_gradle_plugin
17 |
18 | import com.android.build.api.variant.Variant
19 | import com.android.build.gradle.internal.core.InternalBaseVariant
20 | import org.gradle.api.Plugin
21 | import org.gradle.api.Project
22 | import java.io.FileNotFoundException
23 | import java.util.Properties
24 |
25 | /**
26 | * Plugin that reads secrets from a properties file and injects manifest build and BuildConfig
27 | * variables into an Android project. Since property keys are turned into Java variables,
28 | * invalid variable characters from the property key are removed.
29 | *
30 | * e.g.
31 | * A key defined as "sdk.dir" in the properties file will be converted to "sdkdir".
32 | */
33 | class SecretsPlugin : Plugin {
34 |
35 | private val extensionName = "secrets"
36 |
37 | override fun apply(project: Project) {
38 | val extension = project.extensions.create(
39 | extensionName,
40 | SecretsPluginExtension::class.java
41 | )
42 | val supportedComponents =
43 | listOf(project.androidAppComponent(), project.androidLibraryComponent())
44 | supportedComponents.forEach { component ->
45 | component?.onVariants { variant ->
46 | val defaultProperties = extension.defaultPropertiesFileName?.let {
47 | project.rootProject.loadPropertiesFile(it)
48 | }
49 |
50 | val properties: Properties? = try {
51 | project.rootProject.loadPropertiesFile(
52 | extension.propertiesFileName
53 | )
54 | } catch (e: FileNotFoundException) {
55 | defaultProperties ?: throw e
56 | }
57 | generateConfigKey(project, extension, defaultProperties, properties, variant)
58 | }
59 | }
60 | }
61 |
62 | private fun generateConfigKey(
63 | project: Project,
64 | extension: SecretsPluginExtension,
65 | defaultProperties: Properties?,
66 | properties: Properties?,
67 | variant: Variant
68 | ) {
69 | // Inject defaults first
70 | defaultProperties?.let {
71 | variant.inject(it, extension.ignoreList)
72 | }
73 |
74 | properties?.let {
75 | variant.inject(properties, extension.ignoreList)
76 | }
77 |
78 | // Inject build-type specific properties
79 | val buildTypeFileName = "${variant.buildType}.properties"
80 | val buildTypeProperties = try {
81 | project.rootProject.loadPropertiesFile(buildTypeFileName)
82 | } catch (e: FileNotFoundException) {
83 | null
84 | }
85 | buildTypeProperties?.let {
86 | variant.inject(it, extension.ignoreList)
87 | }
88 |
89 | // Inject flavor-specific properties
90 | val flavorFileName = "${variant.flavorName}.properties"
91 | val flavorProperties = try {
92 | project.rootProject.loadPropertiesFile(flavorFileName)
93 | } catch (e: FileNotFoundException) {
94 | null
95 | }
96 | flavorProperties?.let {
97 | variant.inject(it, extension.ignoreList)
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/secrets-gradle-plugin/src/main/java/com/google/android/libraries/mapsplatform/secrets_gradle_plugin/SecretsPluginExtension.kt:
--------------------------------------------------------------------------------
1 | // Copyright 2021 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.google.android.libraries.mapsplatform.secrets_gradle_plugin
16 |
17 | /**
18 | * Configuration object for [SecretsPlugin].
19 | */
20 | open class SecretsPluginExtension {
21 | /**
22 | * The name of the properties file containing secrets. Defaults to "$defaultPropertiesFile"
23 | */
24 | var propertiesFileName: String = defaultPropertiesFile
25 |
26 | /**
27 | * A list of keys this plugin should ignore and not inject. Defaults to $defaultIgnoreList
28 | */
29 | var ignoreList: MutableList = defaultIgnoreList
30 |
31 | /**
32 | * The name of the properties file containing secrets' default values.
33 | */
34 | var defaultPropertiesFileName: String? = null
35 |
36 | companion object {
37 | const val defaultPropertiesFile = "local.properties"
38 | val defaultIgnoreList = mutableListOf("sdk.dir")
39 | }
40 | }
--------------------------------------------------------------------------------
/secrets-gradle-plugin/src/test/kotlin/com/google/android/libraries/mapsplatform/secrets_gradle_plugin/SecretsPluginTest.kt:
--------------------------------------------------------------------------------
1 | // Copyright 2021 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.google.android.libraries.mapsplatform.secrets_gradle_plugin
16 |
17 | import com.android.build.gradle.internal.core.InternalBaseVariant
18 | import com.nhaarman.mockitokotlin2.doReturn
19 | import com.nhaarman.mockitokotlin2.mock
20 | import com.nhaarman.mockitokotlin2.verify
21 | import org.gradle.api.Project
22 | import org.gradle.api.ProjectConfigurationException
23 | import org.gradle.api.internal.project.ProjectInternal
24 | import org.gradle.testfixtures.ProjectBuilder
25 | import org.junit.Assert
26 | import org.junit.Before
27 | import org.junit.Ignore
28 | import org.junit.Rule
29 | import org.junit.Test
30 | import org.junit.rules.TemporaryFolder
31 |
32 | class SecretsPluginTest {
33 |
34 | @Rule
35 | @JvmField
36 | val tempFolder = TemporaryFolder()
37 |
38 | lateinit var placeholders: MutableMap
39 | lateinit var root: Project
40 | lateinit var project: Project
41 | lateinit var variant: InternalBaseVariant
42 |
43 | @Before
44 | fun setUp() {
45 | root = ProjectBuilder.builder()
46 | .withProjectDir(tempFolder.root)
47 | .withName("root")
48 | .build()
49 | project = ProjectBuilder.builder()
50 | .withProjectDir(tempFolder.root.resolve("project"))
51 | .withName("project")
52 | .withParent(root)
53 | .build()
54 | placeholders = mutableMapOf()
55 | val flavor = mock {
56 | on { manifestPlaceholders } doReturn placeholders
57 | }
58 | variant = mock {
59 | on { mergedFlavor } doReturn flavor
60 | }
61 | project.pluginManager.apply("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
62 | }
63 |
64 | // TODO: This exception is no longer thrown since migrating to use onVariants API. Need to
65 | // reenable this test
66 | @Ignore
67 | @Test(expected = ProjectConfigurationException::class)
68 | fun `missing default properties fails`() {
69 | project.extensions.configure(SecretsPluginExtension::class.java) {
70 | it.propertiesFileName = "test.properties"
71 | }
72 | (project as ProjectInternal).evaluate()
73 | }
74 |
75 | @Test
76 | fun `properties are correctly ignored`() {
77 | val fileName = "local.properties"
78 | val propertiesFile = tempFolder.newFile(fileName)
79 | propertiesFile.writeText(
80 | """
81 | key="someValue"
82 | ignoreKey="sadf"
83 | sdk.dir="di"
84 | sdk.foo="di"
85 | """.trimIndent()
86 | )
87 | val properties = project.rootProject.loadPropertiesFile(fileName)
88 | val ignoreList = listOf("ignoreKey", "sdk*")
89 |
90 | variant.inject(properties = properties, ignore = ignoreList)
91 |
92 | check(
93 | Pair("key", "someValue")
94 | )
95 | checkKeysNotIn("ignoreKey", "sdk.dir", "sdk.foo")
96 | }
97 |
98 | @Test
99 | fun `properties are correctly added`() {
100 | val fileName = "local.properties"
101 | val propertiesFile = tempFolder.newFile(fileName)
102 | propertiesFile.writeText(
103 | """
104 | key1="someValue1"
105 | key2="someValue2"
106 | """.trimIndent()
107 | )
108 | val properties = project.rootProject.loadPropertiesFile(fileName)
109 |
110 | variant.inject(properties = properties, ignore = emptyList())
111 |
112 | check(
113 | Pair("key1", "someValue1"),
114 | Pair("key2", "someValue2"),
115 | )
116 | }
117 |
118 | @Test
119 | fun `invalid characters are removed`() {
120 | val fileName = "local.properties"
121 | val propertiesFile = tempFolder.newFile(fileName)
122 | propertiesFile.writeText(
123 | """
124 | sdk.Dir="value"
125 | sdk.Foo!="value2"
126 | """.trimIndent()
127 | )
128 | val properties = project.rootProject.loadPropertiesFile(fileName)
129 |
130 | variant.inject(properties = properties, ignore = emptyList())
131 |
132 | check(
133 | Pair("sdkDir", "value"),
134 | Pair("sdkFoo", "value2")
135 | )
136 | }
137 |
138 | @Test
139 | fun `parenthesis is appended if needed`() {
140 | val fileName = "local.properties"
141 | val propertiesFile = tempFolder.newFile(fileName)
142 | propertiesFile.writeText(
143 | """
144 | key1="value"
145 | key2=value2
146 | """.trimIndent()
147 | )
148 | val properties = project.rootProject.loadPropertiesFile(fileName)
149 |
150 | variant.inject(properties = properties, ignore = emptyList())
151 |
152 | check(
153 | Pair("key1", "value"),
154 | Pair("key2", "value2")
155 | )
156 | }
157 |
158 | private fun check(vararg keyValues: Pair) {
159 | keyValues.forEach { (key, value) ->
160 | Assert.assertEquals(value, placeholders[key])
161 | verify(variant).buildConfigField("String", key, value.addParenthesisIfNeeded())
162 | }
163 | }
164 |
165 | private fun checkKeysNotIn(vararg keys: String) {
166 | keys.forEach {
167 | Assert.assertFalse(placeholders.containsKey(it))
168 | }
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/secrets.defaults.properties:
--------------------------------------------------------------------------------
1 | ## Sample default properties file containing application secret keys with stub values.
2 | gmpApiKey=""
3 | keyToIgnore=""
4 | ignoreKey1=""
5 | ignoreKey2=""
6 |
--------------------------------------------------------------------------------
/secrets.properties:
--------------------------------------------------------------------------------
1 | ## Sample properties file containing application secrets.
2 | # This file is checked into version control for the sake of demonstrating sample contents.
3 | # In practice, your properties file that contains secrets *should not* be under version control.
4 | gmpApiKey="API_KEY_VALUE"
5 | keyToIgnore="This key is ignored"
6 | ignoreKey1="This key is ignored"
7 | ignoreKey2="This key is ignored, too"
8 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | // Copyright 2021 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | include(":secrets-gradle-plugin")
16 | include(":sample-app")
17 |
18 | pluginManagement {
19 | repositories {
20 | mavenLocal()
21 | maven(url = "./plugin/build/repository")
22 | gradlePluginPortal()
23 | }
24 | }
25 |
--------------------------------------------------------------------------------