https://kotlinlang.org logo
Title
f

fitzoh

08/24/2017, 6:05 PM
@bamboo any thoughts on the issues I mentioned last night? What I’m basically looking to do is add an exec task to a plugin which is based on the value of an extension, but the command line args are being resolved before the extension value is set
b

bamboo

08/24/2017, 6:14 PM
You can set the commandLine on
doFirst { ... }
f

fitzoh

08/24/2017, 6:46 PM
sweet, that works
@Test
    fun `it sets the image`() {
        project.extensions.getByType(MyExtension::class.java).dockerRepository = "<http://myregistry.com/some/repo|myregistry.com/some/repo>"

        val buildDockerImage = project.tasks.getByName("buildDockerImage") as Exec

        //Run the `doFirst`
        val action = buildDockerImage.actions[0] as Action<Task>
        action.execute(buildDockerImage)
        
        assertThat(buildDockerImage.commandLine)
                .containsExactly("docker", "build", "-t", "<http://myregistry.com/some/repo|myregistry.com/some/repo>", "docker")
    }
testing it is a little bit janky
but it works
m

mkobit

08/25/2017, 6:06 PM
newer versions of Gradle have the
Provider
and
PropertyState
types, which might help too