etiennemiret / sass-gradle-plugin Goto Github PK
View Code? Open in Web Editor NEWA Gradle plugin to compile scss files using the official Dart Sass compiler.
License: MIT License
A Gradle plugin to compile scss files using the official Dart Sass compiler.
License: MIT License
My SCSS source base has a single file entry point (call it main.scss
) that includes a number of other files to create a single output (style.css
). These other files won't compile on their own.
I can make this compile well enough:
compileSass {
style = compressed
outputDir = project.file("${projectDir}/path/to/output/")
destPath = 'style.css'
sourceMap = none
sourceDir = project.file("${projectDir}/path/to/input/main.scss")
}
because most of these options are passed straight through to the sass
executable.
But since this plugin uses sourceDir
both as an argument to sass
and as Gradle's input file list, incremental builds won't pick up any changes to SCSS files other than main.scss
.
I'd like to have an optional additional entryPoint
option (or something like that) that gets passed through to sass
instead of sourceDir
if set so that sourceDir
can still be used for Gradle's input file list.
Using Gradle <= 4.8 will cause this Exception:
Caused by: java.lang.NoSuchMethodError: org.gradle.api.tasks.TaskContainer.register(Ljava/lang/String;Ljava/lang/Class;Lorg/gradle/api/Action;)Lorg/gradle/api/tasks/TaskProvider;
at io.miret.etienne.gradle.sass.SassGradlePlugin.apply(SassGradlePlugin.java:30)
Please add the information about minimum Gradle version in your README.md
.
I use the plugin in a multiproject build and it works well. I have one question about efficiency. On every build for every project I see
> Task :project1:downloadSass UP-TO-DATE
Download https://github.com/sass/dart-sass/releases/download/1.54.4/dart-sass-1.54.4-windows-x64.zip
> Task :project2:downloadSass UP-TO-DATE
Download https://github.com/sass/dart-sass/releases/download/1.54.4/dart-sass-1.54.4-windows-x64.zip
> Task :project2:downloadSass UP-TO-DATE
Download https://github.com/sass/dart-sass/releases/download/1.54.4/dart-sass-1.54.4-windows-x64.zip
Is the artifact "UP-TO-DATE"? Or is the build downloading the file each time?
It would be great if there could be an "examples" folder with at least one example of a full setup (with build.gradle
) using this plugin. Currently, I'm struggling with getting the compileSass
task to run on build, so I'd appreciate some example material to see how this should be done.
This used to work both in the IDE and also in the multi-stage docker build, but I've evergreened a few versions and now I get this error in the docker build, but it still works ok in the IDE (vscode)
Caused by: net.rubygrapefruit.platform.NativeException: Could not start '/application/.gradle/sass/dart-sass/sass'
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
at org.gradle.process.internal.ExecHandleRunner.startProcess(ExecHandleRunner.java:98)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:71)
... 4 more
Caused by: java.io.IOException: Cannot run program "/application/.gradle/sass/dart-sass/sass" (in directory "/application"): error=2, No such file or directory
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
... 7 more
Caused by: java.io.IOException: error=2, No such file or directory
... 8 more
Gradle version: 7.2
Java version: 16
plugins {
id 'io.miret.etienne.sass' version '1.1.1'
}
sass {
version = '1.41.1'
baseUrl = 'https://github.com/sass/dart-sass/releases/download'
}
Same issue on 1.1.2
Looking in the docker build, the file does seem to exist at /application/.gradle/sass/dart-sass/sass
Current dart sass release is 1.24.2
This makes it impossible for anyone to use the plugin unless they build with Java 13. I suggest targeting Java 8, as that is the minimum version for Gradle.
We are using the sass-gradle-plugin in some of our projects. Trying to activate the Gradle configuration cache failed with an exception:
org.gradle.api.InvalidUserCodeException: Invocation of 'Task.project' by task ':compileSass' at execution time is unsupported.
at org.gradle.configurationcache.initialization.DefaultConfigurationCacheProblemsListener.onTaskExecutionAccessProblem(ConfigurationCacheProblemsListener.kt:96)
at org.gradle.configurationcache.initialization.DefaultConfigurationCacheProblemsListener.onProjectAccess(ConfigurationCacheProblemsListener.kt:59)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:464)
at org.gradle.internal.event.DefaultListenerManager$ListenerDetails.dispatch(DefaultListenerManager.java:446)
at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:61)
at org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch.dispatch(DefaultListenerManager.java:434)
at org.gradle.internal.event.DefaultListenerManager$EventBroadcast.dispatch(DefaultListenerManager.java:221)
at org.gradle.internal.event.DefaultListenerManager$EventBroadcast.dispatch(DefaultListenerManager.java:192)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy86.onProjectAccess(Unknown Source)
at org.gradle.api.internal.AbstractTask.notifyProjectAccess(AbstractTask.java:1046)
at org.gradle.api.internal.AbstractTask.getProject(AbstractTask.java:234)
at org.gradle.api.DefaultTask.getProject(DefaultTask.java:59)
at io.miret.etienne.gradle.sass.CompileSass.getExecutable(CompileSass.java:89)
at io.miret.etienne.gradle.sass.CompileSass_Decorated.getExecutable(Unknown Source)
at io.miret.etienne.gradle.sass.CompileSass.compileSass(CompileSass.java:164)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[...]
The Gradle call was gradlew --configuration-cache build -x test
The --watch
argument should be supported as well. The task should run in another thread in order to work with (server) applications.
More information: https://sass-lang.com/documentation/cli/dart-sass#watch
As of Gradle 4 @ParallelizableTask
was removed. Now the Worker API should be used: https://guides.gradle.org/using-the-worker-api/#converting_to_the_worker_api
I installed your Gradle plugin like that :
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
id 'io.miret.etienne.sass' version '1.1.1'
}
sass {
version = '1.24.4'
directory = file ("${rootDir}/.gradle/sass")
baseUrl = 'https://github.com/sass/dart-sass/releases/download'
}
compileSass {
outputDir = project.file ("${buildDir}/sass")
sourceDir = project.file (${projectDir}/src/main/sass)
loadPath project.file ('sass-lib')
loadPath project.file ('/var/lib/compass')
style = expanded
noCharset ()
noErrorCss ()
watch ()
sourceMap = file
sourceMapUrls = relative
}
But now when I want to launch anything gradle task, I have this error :
> No signature of method: build_dykzla3ri5dkhpuy7mfct10yx.compileSass() is applicable for argument types: (build_dykzla3ri5dkhpuy7mfct10yx$_run_closure4) values: [build_dykzla3ri5dkhpuy7mfct10yx$_run_closure4@4a7da083]
What do you think about that ?
is there others requirements or prerequisites to use your plugin ?
Thank you for your help
Hello,
I'm using the plugin in 2 separate subprojects of a root project. These are: libraries/uicomponents and features/userdetails. It's a JavaFX project and I'm adding a functionality to define different styles per screen. Each screen has its own subproject.
Right now, the plugin configuration in build.gradle is the same in both subprojects:
jar {
dependsOn compileSass
from compileSass.outputDir
}
sass {
noAutoCopy()
}
compileSass {
sourceDir = project.file("${projectDir}/src/main/resources")
outputDir = project.file("${buildDir}/resources/main")
loadPath project.file("${rootDir}/common/sass-lib")
sourceMap = none
}
However, when building the whole project there goes an error:
> Task :compileJava NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :jar
> Task :assemble
> Task :compileTestJava NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test NO-SOURCE
> Task :check UP-TO-DATE
> Task :build
> Task :libraries:core:compileJava
> Task :libraries:core:processResources NO-SOURCE
> Task :libraries:core:classes
> Task :libraries:core:jar
> Task :libraries:uicomponents:compileJava
> Task :libraries:uicomponents:processResources NO-SOURCE
> Task :libraries:uicomponents:classes
> Task :libraries:uicomponents:downloadSass UP-TO-DATE
> Task :libraries:uicomponents:installSass UP-TO-DATE
> Task :features:home:processResources
> Task :features:settings:processResources
> Task :features:userdetails:processResources
> Task :features:userdetails:downloadSass UP-TO-DATE
> Task :libraries:uicomponents:compileSass FAILED
The process cannot access the file because it is being used by another process.
> Task :features:userdetails:installSass
Execution optimizations have been disabled for task ':features:userdetails:installSass' to ensure correctness due to the following reasons:
- Gradle detected a problem with the following location: 'C:\projects\javafx-app-template\.gradle\sass\archive\dart-sass-1.54.0-windows-x64.zip'. Reason: Task ':features:userdetails:installSass' uses this output of task ':libraries:uicomponents:downloadSass' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.3.3/userguide/validation_problems.html#implicit_dependency for more details about this problem.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
Execution optimizations have been disabled for 1 invalid unit(s) of work during this build to ensure correctness.
Please consult deprecation warnings for more details.
14 actionable tasks: 9 executed, 5 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':libraries:uicomponents:compileSass'.
> A failure occurred while executing io.miret.etienne.gradle.sass.CompileSassWorkAction
> Process 'command 'C:\projects\javafx-app-template\.gradle\sass\1.54.0\dart-sass\sass.bat'' finished with non-zero exit value 1
Everything is ok when running subprojects build separately.
I found a workaround for the problem and this is setting separate directory for the sass exec files per project, like this:
sass {
directory = file("${rootDir}/.gradle/sass/${name}")
noAutoCopy()
}
but when having a lot of subprojects I can imagine this being space consuming.
I'm using Gradle 7.3.3 version.
I would really appreciate some help on the matter :)
Recent versions of dart-sass support both linux and apple arm64 architectures. This is fixed by #20.
Setting a version like
sass {
// dart-sass version to use:
version = '1.26.2'
}
Results in a failed download attempt:
Not Found (HTTP status code: 404, URL: https://github.com/sass/dart-sass/releases/download/1.26.2/dart-sass-1.24.4-linux-x64.tar.gz)
The URL uses the specified version for the directory but not for the file name. (Most likely, the file name is evaluated in the wrong gradle phase.)
I am seeing a failure with Gradle 8.0-rc-1:
$ ./gradlew installSass --stacktrace
...
> Task installSass FAILED
...
> Unable to expand TAR '.../.gradle/sass/archive/dart-sass-1.57.1-linux-x64.tar.gz'
The tar might be corrupted or it is compressed in an unexpected way.
By default the tar tree tries to guess the compression based on the file extension.
If you need to specify the compression explicitly please refer to the DSL reference.
...
Caused by: java.io.IOException: Not a TAR archive
at org.gradle.api.internal.file.archive.TarFileTree.checkFormat(TarFileTree.java:178)
at org.gradle.api.internal.file.archive.TarFileTree.visitImpl(TarFileTree.java:103)
at org.gradle.api.internal.file.archive.TarFileTree.lambda$visit$0(TarFileTree.java:88)
... 63 more
tasks.named<CompileSass>("CompileSass") {
loadPath(project.file("${projectDir}/src/main/resources/coderdocs/assets/scss"))
sourceDir.set(sassSources)
outputDir = project.file("${projectDir}/src/main/resources/coderdocs-dist/assets/css")
}
Line 119: sourceDir.set(sassSources)
^ Cannot access 'sourceDir': it is private in 'CompileSass'
Thanks for providing this useful plugin!
Feature: It would be nice to have a configuration switch to disable the automatic copying of the compiled CSS files to the WAR file when the WAR plugin is present. It could be an additional switch like "disableCopyToWar()".
Context: I'm using this plugin in a Spring Boot application and use it to compile SCSS files from "src/main/sass" to a subfolder of "src/main/resources/". This is an intermediate step and the CSS files from there will then already be packaged in the WAR file according to the default resource processing of the WAR plugin. So in my use-case, the SASS plugin copies all files of the output folder in the root of the WAR file, which requires an additional build step to remove these files again. Having a possibility to disable that behaviour in the plugin would be nice and would improve the support for more custom setups such as mine.
Cheers,
Ben
When I use the plugin on windows OS with ubuntu 20.04 the compile time is too long.
Probably this is a problem with dart-sass
and not the plugin per-se but I am seeing the following after adding to our build.
Running the plugin locally (windows and ubuntu-linux) I have no problems:
/home/myuser/myrepo/myproduct/portal $ gradle compileSass
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :downloadSass
Download https://github.com/sass/dart-sass/releases/download/1.54.4/dart-sass-1.54.4-linux-x64.tar.gz
BUILD SUCCESSFUL in 13s
3 actionable tasks: 3 executed
But the same command executed in the gradle image gradle:7.5.1-jdk17-alpine
in our build pipeline says command not found:
/builds/myproduct/product/myproduct/portal # gradle compileSass
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.5.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build
> Task :downloadSass UP-TO-DATE
> Task :installSass UP-TO-DATE
> Task :compileSass FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileSass'.
> A failure occurred while executing io.miret.etienne.gradle.sass.CompileSassWorkAction
> A problem occurred starting process 'command '/builds/myproduct/product/myproduct/portal/.gradle/sass/1.54.4/dart-sass/sass''
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
3 actionable tasks: 1 executed, 2 up-to-date
I shelled into the container and the executable is there, but I get the same result on the command line:
/builds/myproduct/product/myproduct/portal/.gradle/sass/1.54.4/dart-sass # $(pwd)/sass
/bin/sh: /builds/myproduct/product/myproduct/portal/.gradle/sass/1.54.4/dart-sass/sass: not found
/builds/myproduct/product/myproduct/portal/.gradle/sass/1.54.4/dart-sass # ls -lah
total 9M
drwxr-xr-x 3 root root 4.0K Oct 27 07:40 .
drwxr-xr-x 3 root root 4.0K Oct 27 07:40 ..
-rwxr-xr-x 1 root root 9.1M Oct 27 07:40 sass
drwxr-xr-x 2 root root 4.0K Oct 27 07:40 src
/builds/myproduct/product/myproduct/portal/.gradle/sass/1.54.4/dart-sass # ./sass
/bin/sh: ./sass: not found
What am I missing here? Maybe it cannot run in an alpine environment?
When using Kotlin Gradle DSL to specify style or source map
tasks.compileSass {
style = compressed
sourceMap = none
}
Gradle 8.2 (and earlier versions) shows warnings
w: ... Type CompileSass.Style! is inaccessible in this context due to: public/*package*/ final enum class Style : Enum<CompileSass.Style!> defined in io.miret.etienne.gradle.sass.CompileSass
w: ... Type CompileSass.SourceMap! is inaccessible in this context due to: public/*package*/ final enum class SourceMap : Enum<CompileSass.SourceMap!> defined in io.miret.etienne.gradle.sass.CompileSass
Intellij IDEA shows the same warnings when editing build.gradle.kts
It still works in the end, but warnings are printed on every build.
Hi @EtienneMiret,
I'm a gradle novice and I'm currently attempting to have my scss files converted to css upon saving changes, just as I had it using a run configuration in eclipse.
I'm currently using netbeans v12.4 on a gradle web project. I originally thought that it could be automatically done by the IDE, since the css preprocessor settings (e.g. path to sass executable and input and output properties) ARE available on the IDE, but no "run configurations". Maybe the settings are there so that a sass compiler plugin can pick them up or something.
So I guess the only route to have this working is by installing an sass compiler plugin.
So I configured my build.gradle file to as follows:
plugins {
id 'java'
id 'jacoco'
id 'war'
id 'io.miret.etienne.sass' version '1.1.1'
}
and then pasted your configuration example (just changed my paths) as follows:
compileSass {
// Directory where to output generated CSS:
outputDir = project.file ("${projectDir}/src/main/webapp/resources/layout/css")
// Source directory containing sass to compile:
sourceDir = project.file ("${projectDir}/src/main/webapp/resources/layout/sass")
// Adds a directory to sass load path (default is empty):
loadPath project.file ('sass-lib')
loadPath project.file ('/var/lib/compass')
// Set the output style:
// Possible values are “expanded” and “compressed”, default is “expanded”.
style = expanded
// Don’t emit a @charset for CSS with non-ASCII chars (default to emit):
noCharset ()
// When an error occurs, do not emit a stylesheet describing it:
// (Default to emit)
noErrorCss ()
// Watch sass files in sourceDir for changes
watch ()
// Source map style:
// - file: output source map in a separate file (default)
// - embed: embed source map in CSS
// - none: do not emit source map.
sourceMap = file
// How to link source maps to source files [relative (default) or absolute]:
sourceMapUrls = relative
}
I then run the compileSass
task directly from the netbeans IDE (Project->Run Gradle->Tasks...) and get following message after a few seconds:
Sass is watching for changes. Press Ctrl-C to stop.
I then went to change a file and after saving it, the Build (Project Web Store) Task :compileSass
progress bar at the bottom right started to flash by, but wouldn't stop after a long while. I could not stop the tasks by hitting the stop button. So after a while, I closed out netbeans.
Now, when I go back into netbeans and start the task compileSass
, the progress bar endlessly cycles without stopping. It seems like something got stock there from the first action after I forcefully exited the IDE and after restaring netbeans and the compileSass
task, it picks up where it left off.
What do you think? Do you think you can point me in the right direction. I would appreciate it very much!
Best regards,
When changing the sass version to use in a build.gradle, the version previously set is still used if it was already downloaded.
As a workaround, user can delete projectDir/.gradle/sass, but this still needs to be fixed.
CI/CD is now done with Travis, let’s switch to GitHub actions.
Thanks for your plugin. We have configured it in this way so that we can have tomcat live host our source (jsp project)
compileSass {
sourceDir = project.file("site/scss")
outputDir = project.file("site/styles")
}
However your plugin adds the contents of site/styles to the root of the war file. I don't think that is what was intended. Thanks for your help!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.