Search code examples
gradleplayback

Not able to extend a Gradle task


I'm new with Gradle (we're switching from SBT) and using it to build apps made with Play Framework.

I need to add some filtering on the resources before Gradle processes them (I would like to inject some build properties into the configuration to make them available from the code).

I've managed to "extend" the java processResources task, but, for some reason, I cannot do the same with play processPlayBinaryPlayResources.

processPlayBinaryPlayResources {
    filter ReplaceTokens, tokens: [
            "applicationVersion": version
    ]
}

Even this doesn't work :

def playVersion = "2.6.20"
def scalaVersion = "2.12"
def javaVersion = "1.8"

apply plugin: "java"
apply plugin: "idea"
apply plugin: "play"

model {
    components {
        play {
            platform play: playVersion, scala: scalaVersion, java: javaVersion
            injectedRoutesGenerator = true
        }
    }
}

processPlayBinaryPlayResources {
    doLast {
        println("ok")
    }
}

dependencies {
    compile "io.vavr:vavr:0.9.2"
    compile "org.imgscalr:imgscalr-lib:4.2"
    compile "com.typesafe.play:play-guice_${scalaVersion}:2.6.20"
    compile "com.typesafe.akka:akka-http_${scalaVersion}:10.1.5"
    compile "com.typesafe.play:filters-helpers_${scalaVersion}:2.6.20"
    compile "ch.qos.logback:logback-classic:1.2.3"
}

It yields :

> Could not find method processPlayBinaryPlayResources() for arguments [build_6grwx7eowye82rdqpu4qlinur$_run_closure2@582d9dbd] on root project 'myproject' of type org.gradle.api.Project.

Any idea why ?


Solution

  • Your assumption of finding a task processPlayBinaryPlayResources is based on that, that the java plugin automatically adds a processResources task for all source set as process<sourceset_name>Resources . This happens only when a source set is added using java pugins sourceSets method which, in this case PlayBinaryPlay is not. The play plugin uses its own DSL to configure source sets. Therefore when you try extending processPlayBinaryPlayResources it does not happen as no such tasks by that name exists in the first place and hence while delegating it to Project, you end up with this

     Could not find method processPlayBinaryPlayResources() for arguments [build_6grwx7eowye82rdqpu4qlinur$_run_closure2@582d9dbd] on root project 'myproject' of type org.gradle.api.Project.
    

    Lastly, I would like to add that the processPlayBinaryPlayResources task is not added by the play plugin.