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

Update readme to show how to configure using new gradle plugin syntax #41

Closed
dalewking opened this issue Sep 24, 2020 · 3 comments · Fixed by #49
Closed

Update readme to show how to configure using new gradle plugin syntax #41

dalewking opened this issue Sep 24, 2020 · 3 comments · Fixed by #49

Comments

@dalewking
Copy link

The readme shows the old way to configure the plugin using classpath inside buildscript, but since you are publishing in the gradle plugin portal there is no reason to so it that way. The readme should reflect the prefered way using the new plugin syntax.

@dalewking
Copy link
Author

I've figured it out how to make it work in gradle kotlin dsl:

You can apply the plugin with:

plugins {
    kotlin("multiplatform")
    id("com.codingfeline.buildkonfig")
}

I added these imports to the file:

import com.codingfeline.buildkonfig.compiler.FieldSpec.Type
import com.codingfeline.buildkonfig.gradle.BuildKonfigExtension
import com.codingfeline.buildkonfig.gradle.TargetConfigDsl

And here is what I did to configure:

configure<BuildKonfigExtension> {
    packageName = "com.genesys.purecloud.wfmshared"

    defaultConfigs {
        buildConfigField(Type.STRING, "OAUTH_CLIENT_ID", "")
        buildConfigField(Type.STRING, "OAUTH_CLIENT_SECRET", "")
        buildConfigField(Type.STRING, "DEFAULT_ENVIRONMENT",
            if(publicReleaseBuild) "PRODUCTION" else "DEVELOPMENT")
        buildConfigField(Type.BOOLEAN, "ALLOW_ENVIRONMENT_SELECTION",
            (!publicReleaseBuild).toString())
    }

    targetConfigs("android", closureOf<TargetConfigDsl> {
        buildConfigField(Type.STRING, "OAUTH_CLIENT_ID",
            project.properties["oauth_client_id_android"].toString())
        buildConfigField(Type.STRING, "OAUTH_CLIENT_SECRET",
            project.properties["oauth_client_secret_android"].toString())
    })
    targetConfigs("ios", closureOf<TargetConfigDsl> {
        buildConfigField(Type.STRING, "OAUTH_CLIENT_ID",
            project.properties["oauth_client_id_ios"].toString())
        buildConfigField(Type.STRING, "OAUTH_CLIENT_SECRET",
            project.properties["oauth_client_secret_ios"].toString())
    })
}

This is hampered by the fact that for target configs you are using Closure, which is Groovy specific and requires the configureOf wrapper. As noted here you should use Action, not Closure. You did that on defaultConfig but not on targetConfigs.

@dalewking
Copy link
Author

And I guess I should have tested that before posting as that fails with:
org.gradle.api.internal.FactoryNamedDomainObjectContainer_Decorated cannot be cast to com.codingfeline.buildkonfig.gradle.TargetConfigDsl

@dalewking
Copy link
Author

dalewking commented Oct 9, 2020

OK, this works, but once again would be simplified by you switching to Action from Closure:

targetConfigs(closureOf<NamedDomainObjectContainer<TargetConfigDsl>> {
    create("android") {
        buildConfigField(
            Type.STRING, "OAUTH_CLIENT_ID",
            project.properties["oauth_client_id_android"].toString()
        )
        buildConfigField(
            Type.STRING, "OAUTH_CLIENT_SECRET",
            project.properties["oauth_client_secret_android"].toString()
        )
    }
    create("ios") {
        buildConfigField(
            Type.STRING, "OAUTH_CLIENT_ID",
            project.properties["oauth_client_id_ios"].toString()
        )
        buildConfigField(
            Type.STRING, "OAUTH_CLIENT_SECRET",
            project.properties["oauth_client_secret_ios"].toString()
        )
    }
})

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

Successfully merging a pull request may close this issue.

2 participants