Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set username and password config by project local.properties or by parameters #798

Open
zhlinh opened this issue Jun 25, 2024 · 1 comment

Comments

@zhlinh
Copy link

zhlinh commented Jun 25, 2024

Now provided two ways to set username and password config. by ~/.gradle/gradle.properties or by system env.

But if want different project has different username and password settings, I found it so hard to do it.

  1. I want the plugin to read config in project local.properties, but it can't
  2. Or I read it by myself and set it to this plugin, but I can not find how to set it by parameters
  3. It's hard to change system env in the gradle scripts which I tried, but not working
private fun Project.setSystemEnv() {
    // set environment variable
    val envMap = mapOf(
        "ORG_GRADLE_PROJECT_mavenCentralUsername" to getLocalProperties("mavenCentralUsername", ""),
        "ORG_GRADLE_PROJECT_mavenCentralPassword" to getLocalProperties("mavenCentralPassword", ""),
        "ORG_GRADLE_PROJECT_signingInMemoryKey" to getSigningInMemoryKey(),
        "ORG_GRADLE_PROJECT_signingInMemoryKeyId" to getLocalProperties("signing.keyId", ""),
        "ORG_GRADLE_PROJECT_signingInMemoryKeyPassword" to getLocalProperties("signing.password", "")
    )
    // or set in ~/.gradle/gradle.properties, but I do not want to share with other projects
    // mavenCentralUsername
    // mavenCentralPassword
    // signing.keyId
    // signing.password
    // signing.secretKeyRingFile
    // detail in https://vanniktech.github.io/gradle-maven-publish-plugin/central/#configuring-the-pom
    tasks.withType(Exec::class.java).configureEach {
        // set env
        environment(envMap)
        envMap.forEach { (key, value) ->
            if (value.isNotEmpty()) {
                System.setProperty(key, value)
            }
        }
    }
}
@alirezat775
Copy link

I need the same capability, we are using secrets.properties to provide our credentials for the project, and since the gradle.properties is committed to the git, we can not save the credentials in that file, and ~/.gradle/gradle.properties is ok but in that case we need to maintain two places for credentials, and it's preferable to have all of them in the secrets.properties.

basically, I need to provide a new properties file to the gradle plugin and it reads the variables from that file

val secretProperties = Properties().apply {
    load(FileInputStream(File(rootProject.rootDir, "secrets.properties")))
}
properties = secretProperties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants