Play Plugin and Sass Assets


(Felix) #1

Hello,

I’m trying to a gradle project from SBT to Gradle and I’ve got a problem.
I wanna compile the sass to css and then include it into the binary.
I’ve found something similar here Gradle + Play: Configuring CSS sources
but @eriwen uses Less and not SASS. Overmore the does not show his LessCompileTask which I would need to create something similar for SASS.

Current approach:

model {
    components {
        play {
            platform play: playVersion, scala: scalaVersion, java: '1.8'
            injectedRoutesGenerator = true

            sources {
                twirlTemplates {
                    defaultImports = TwirlImports.SCALA
                }
            }

            binaries.all { binary ->
                tasks.create("${binary.name}Sass", SassCompileTask) { sassTask ->
                    source "app/assets/stylesheets"
                    exclude ["**/_*.scss", "**/_*.sass"]

                    dest = "${buildDir}/tmp/${sassTask.name}"

                    binary.assets.builtBy(sassTask)
                }
            }
        }
    }
}

The SassCompileTask comes from the applied plugin https://github.com/kravemir/GradleSassPlugin but it still says: No such property: SassCompileTask for class: org.gradle.play.PlayApplicationBinarySpec

Current build.gradle: https://gist.github.com/felixoi/3ee1ac4247ab696a937c790212161f20

Thanks for your help,
felixoi


(Eric Wendelin) #2

I think first you may need to explicitly import or fully qualify SassCompileTask:

tasks.create("${binary.name}Sass", org.kravemir.gradle.sass.SassCompileTask) { ... }


(Felix) #3

Oh yeah thank you. Unfortunatly, the sass plugin is very outdated (the compiler) so it throws stupid errors. If anyone knows a good gradle sass plugin in which task I could hook into please message me.


(Eric Wendelin) #4

I wish I did. Getting Sass to work especially with Play would be a huge pain I’m afraid. If you find a solution, let me know as well.


(Felix) #5

@eriwen Is https://github.com/eriwen/gradle-css-plugin/blob/master/src/main/groovy/com/eriwen/gradle/css/tasks/CompileSassTask.groovy working? I hooked into the task and specified the directory like this:

sourceDir = file("$projectDir/app/assets/stylesheets")
destDir = file("${buildDir}/tmp/${sassTask.name}")

binary.assets.builtBy(sassTask)

But executing the task gives me NO-SOURCE


(Eric Wendelin) #6

I’m afraid I never finished that task.

When I did all this stuff for a previous employer, I had to write a bunch of custom tasks for things like this, that I could not open source.

Unless you’re willing to do that, I would recommend not using Gradle for your Play app. If you are, though, and can open source your work, I will help you promote the heck out of it :slight_smile:


(Felix) #7

We want to switch because of speed reasons (sbt is slooow) and in additon to that all our jvm projects are using gradle on this organization. Our work is open source: https://github.com/SpongePowered/Ore/tree/feature/gradle?files=1

If you think it’s really not good to use gradle tell me, otherwise we would really want the switch.


(Eric Wendelin) #8

All I can say is that it took me a month to convert, which is far longer than I expected.

SBT is quite painful. I do fully get that. A decent number of folks are using Gradle with Play, but they all seem to have a bunch of their own tooling to do it.

I regret that I cannot afford to spend time making this better, as I have some bigger things in work. I would recommend you go forward developing some Gradle plugins for this. One rather unknown plugin that may help you as it helped me is a digest plugin. I should publish that to the plugin portal I suppose, if you think you’d find that helpful.