Skip to content

Problem with use cases of executing subproject's task with dotenv option by using CLI arguments #67

@uzzu

Description

@uzzu

Forked from #39 (comment)

refs: #39 (comment)

I'm still working on how to make the use cases of executing subproject's task with dotenv option by using CLI arguments, but I think the following tests would be good to pass.

Now failing test case
    @Test
    fun changeFileWithIgnoringParentByUsingCliOptionWithCallSubProject() {
        RootProject(projectDir) {
            settingsGradle(
                """
                include("sub")
                """.trimIndent()
            )
            buildGradle(
                """
                plugins {
                    id("base")
                    id("co.uzzu.dotenv.gradle")
                }
                println("[root] FOO: ${'$'}{env.FOO.value}")
                """.trimIndent()
            )
            file(
                ".env.template",
                """
                FOO=
                """.trimIndent()
            )
            file(
                ".env",
                """
                FOO=100
                """.trimIndent()
            )
            directory("sub")
            file(
                "sub/build.gradle",
                """
                plugins {
                    id("base")
                }
                println("[sub] BAR: ${'$'}{env.BAR.value}")
                """.trimIndent()
            )
            file(
                "sub/.env.template",
                """
                BAR=
                """.trimIndent()
            )
            file(
                "sub/.env",
                """
                BAR=200
                """.trimIndent()
            )
            file(
                "sub/.env.local",
                """
                BAR=2000
                """.trimIndent()
            )
        }

        val result = GradleRunner.create()
            .withPluginClasspath()
            .withProjectDir(projectDir)
            .withArguments(":sub:clean", "-Pdotenv.filename=.env.local")
            .build()

        assertAll {
            assertThat(result.output).contains("[root] FOO: 100")
            assertThat(result.output).contains("[sub] BAR: 2000")
        }
    }

execution log

FAILURE: Build failed with an exception.

* Where:
Build file '/private/var/folders/xxx/build.gradle.kts' line: 1

* What went wrong:
An exception occurred applying plugin request [id: 'co.uzzu.dotenv.gradle']
> Failed to apply plugin 'co.uzzu.dotenv.gradle'.
   > Could not read the dotenv file specified in the gradle.properties. dotenv.filename: .env.local, path: /private/var/folders/xxx/.env.local

workaround: Use gradle.properties

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions