A small plugin which loads an additional properties file for secret values.

Overview

Gradle Secrets Plugin

A small plugin which loads an additional properties file for secret values.

Why

Using this plugin, you can have an additional file (secrets.properties) which can hold secret values like API-keys, tokens, private file paths and so on.

There are already two main ways to define secret values:

  1. Environment variables and
  2. The gradle.properties file which is located in GRADLE_USER_HOME which defaults to USER_HOME/.gradle.

However, environment variables can be annoying to set up for every new project. Searching, opening and editing the global gradle properties file isn't that fast and simple as well. It is also impossible to have the same property name with different values in two or more projects.

Usage

  1. Apply the gradle plugin to your project (Kotlin DSL: id("at.stnwtr.gradle-secrets-plugin") version "1.0.1").
  2. Create a new file named secrets.properties in the project root.
  3. Optionally, create a secrets.example.properties file which describes the used secrets.
  4. Done! Now you can set values in the secrets.properties without publishing the file.

Examples

An example task in the build.gradle.kts (Kotlin DSL):

plugins {
    id("at.stnwtr.gradle-secrets-plugin") version "1.0.1"
}

// Throw an exception if the value was not found - else null is returned
secrets.throwIfNotFound = true // Default 'false'

task("sec-test").doLast {
    // Prints the value of 'key' or throws an error
    // because 'secrets.throwIfNotFound' was set to 'true'
    println(secrets.get("key"))

    // Searches in the 'secrets.properties' first
    // If not found in the file, it checks the environment variables
    // If not found in the environment variables an error is thrown
    // because 'secrets.throwIfNotFound' was set to 'true'
    println(secrets.getOrEnv("key"))

    // Tries parsing the result to an integer
    // Throws if the value was not found
    // because 'secrets.throwIfNotFound' was set to 'true'
    println(secrets.get("key") { it?.toInt() })
}

The method secrets.getOrEnv(String) can be useful because:

  1. When developing locally, you don't have to define environment variables but
  2. on pushing to a remote and having a CI/CD configured, the secret values can be applied by the CI/CD as environment variables.

You could also set a local environment variable instead of using the secrets.properties file, but if more than one project needs different API-Keys for example, it is easier and more convenient to keep the same variable name and not to configure two environment variables PROJECT_ALPHA_API_KEY and PROJECT_BRAVO_API_KEY.

You might also like...
K6-intellij-plugin - IntelliJ-based Plugin to run k6 tests locally or in the k6 Cloud from your IntelliJ IDE
K6-intellij-plugin - IntelliJ-based Plugin to run k6 tests locally or in the k6 Cloud from your IntelliJ IDE

IntelliJ-based Plugin to run k6 tests locally or in the k6 Cloud from your Intel

Ownership-gradle-plugin - Gradle code ownership verification plugin

Gradle code ownership verification plugin A gradle plugin that will verify owner

Android Studio plugin which automatically generates drawable selectors from appropriately named resources.
Android Studio plugin which automatically generates drawable selectors from appropriately named resources.

SelectorChapek for Android This Android Studio plugin automatically generates drawable selectors from appropriately named Android resources. How to in

 Gradle plugin which downloads and manages your Android SDK.
Gradle plugin which downloads and manages your Android SDK.

DEPRECATED This plugin is deprecated and is no longer being developed. Tools and dependencies are automatically downloaded using version 2.2.0 of the

Gradle plugin which validates the licenses of your dependency graph match what you expect

Licensee 📜 👀 A Gradle plugin which validates the licenses of your dependency graph match what you expect, or it fails your build! Jump to: Introduct

✈️ IDE plugin for the IntelliJ platform which adds GitHub Copilot support. (VERY WIP)
✈️ IDE plugin for the IntelliJ platform which adds GitHub Copilot support. (VERY WIP)

JetBrains Copilot GitHub Copilot support for the IntellIJ Platform. Installation Download the latest release. Select the Install Plugin from Disk opti

Gradle plugin which helps you analyze the size of your Android apps.
Gradle plugin which helps you analyze the size of your Android apps.

Ruler Ruler is a Gradle plugin which helps you analyze the size of your Android apps. Motivation App size is an important metric which directly correl

A flutter plugin through which you can get audios, videos, or images from the local storage.

Getter Made flutter easier. Description A flutter plugin through which you can get audios, videos or images from the local storage. Dependencies Befor

GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.
GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.

Gradle Play Publisher Gradle Play Publisher is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and

Comments
  • Secrets DSL

    Secrets DSL

    I think it would be nice to define secrets in a DSL in the buildscript. The actual secret values should stay in the secrets.properties. It would also be nice to be able to define more than one "source" for a secret. This would allow also to read secrets from env variables. (This is already possible, but this would make it a bit cleaner). Also the example file could be generated with this. It would be also possible to provide default values.

    Example (feel free to suggest changes):

    secrets {
        create("my_secret") // read from secrets.properties
        create("my_secret_2") { // tries to read from secrets.properties, then from Environment Variables
            sources += SecretSource.ENVIRONMENT
        }
        create("git_user") {
            default = {
                  // run shell command
            }
        }
    }
    
    opened by NyCodeGHG 0
Owner
null
A IntelliJ plugin to provide check on 'value type' which is limited to numerical constant values

ValueType A IntelliJ plugin to provide check on 'value type' which is limited to

Bennyhuo 4 Mar 11, 2022
A IntelliJ plugin to provide check on 'value type' which is limited to numerical constant values

ValueDef A IntelliJ plugin to provide check on 'value type' which is limited to

Bennyhuo 4 Mar 11, 2022
A Intellij platform plugin to view truetype font file(.ttf) that includes icon glyphs usually

Icon Font Viewer 一个用于查看.ttf字体文件的Intellij平台(支持IDEA/Android Studio等)的插件,通常用于展示icon

null 7 Oct 22, 2022
A gradle plugin to optimize built jars through individual file optimizations and increased compression

Machete Machete is a gradle plugin that attempts to optimize the size of output JARs through both individual file optimizations and overall compressio

Silver 9 Nov 2, 2022
Gradle Replace In Place (GRIP): a gradle plugin to update your documentation or any file with a simple gradle task

GRIP (Gradle Replace In-Place) A gradle tool to update some values in your (documentation) files by running a task. (inspired by Knit) Directives Inse

Grégory Lureau 2 Oct 18, 2022
gradle-android-scala-plugin adds scala language support to official gradle android plugin

gradle-android-scala-plugin gradle-android-scala-plugin adds scala language support to official gradle android plugin. See also sample projects at htt

saturday06 345 Dec 10, 2022
eventbus-intellij-plugin 3.8 0.0 L1 Java Plugin to navigate between events posted by EventBus.

eventbus-intellij-plugin Plugin to navigate between events posted by EventBus. Post to onEvent and onEvent to Post Install There are two ways. Prefere

Shinnosuke Kugimiya 315 Aug 8, 2022
IntelliJ Idea Astor Plugin is a plugin that integrates Astor in Intellij Idea

IntelliJ Idea Astor Plugin IntelliJ Idea Astor Plugin is a plugin that integrates Astor in Intellij Idea. It communicates with a local/remote program

null 4 Aug 28, 2021
Intellij-platform-plugin-template - IntelliJ Platform Plugin Template

IntelliJ Platform Plugin Template TL;DR: Click the Use this template button and

null 0 Jan 1, 2022
BuildPlots-Plugin - PaperMC-Plugin for build contests written in Kotlin.

BuildPlotsPlugin PaperMC-Plugin for build contests. This is my first time using Kotlin and the first plugin I've written after a long time. It is stil

Lukas Heinzl 0 Jan 1, 2022