About Eric Wendelin
eriwen / gradle-js-plugin Goto Github PK
View Code? Open in Web Editor NEWGradle plugin for working with JS
Home Page: http://eriwen.github.io/gradle-js-plugin
License: Apache License 2.0
Gradle plugin for working with JS
Home Page: http://eriwen.github.io/gradle-js-plugin
License: Apache License 2.0
The tasks provided by this plugin should have descriptions and groups. It looks like they do in JsPlugin.applyTasks, but running gradle tasks does not show any description (I am using gradle 1.3), and all tasks provided by the plugin show up in "Other tasks"
Hi, I'm trying to minify my JS files and I'm getting this error :
Stacktrace:
Caused by: groovy.lang.MissingMethodException: No signature of method: org.gradle.api.internal.plugins.DefaultConvention.create() is applicable for argument types: (java.lang.String, java.lang.Class) values: [closure, class com.eriwen.gradle.js.ClosureCompilerExtension]
Possible solutions: grep(), iterator(), printf(java.lang.String, [Ljava.lang.Object;), printf(java.lang.String, java.lang.Object), getAt(java.lang.String)
at com.eriwen.gradle.js.JsPlugin.apply(JsPlugin.groovy:25)
at com.eriwen.gradle.js.JsPlugin.apply(JsPlugin.groovy)
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.providePlugin(DefaultProjectsPluginContainer.java:107)
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.addPluginInternal(DefaultProjectsPluginContainer.java:71)
at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.apply(DefaultProjectsPluginContainer.java:37)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:101)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:32)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:72)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:114)
at org.gradle.api.internal.project.AbstractProject.apply(AbstractProject.java:858)
at org.gradle.api.Project$apply.call(Unknown Source)
at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:35)
at org.gradle.api.Script$apply.callCurrent(Unknown Source)
at build_5kjao6060dseu1mam9ua565ren.run(/Users/christiangendreau/Documents/CodeSource/canadensys-explorer/build.gradle:3)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
I'm using Gradle 1.0, Groovy 1.8.4 and Java 6.
Thanks for the help
It would be nice to be able to produce output in an XML format that for example Jenkins can read.
I wish to set languageIn to ECMASCRIPT5 but I can't get it to work
please provide an example of how we instantiate a CompilerOptions in the build file, and configure its properties
It seems that something goes wrong with CompilerOptions
instance if a task of MinifyJsTask
type is defined in a standalone file that is then included via apply from
.
Please, check this example:
https://dl.dropbox.com/u/1571429/devroom/gradle-js-test.tar
buildAlt
task uses minifyJsLocal
task that is defined right in build.gradle
and it does work properly. But build
, which depends on minifyJsExtermal
from commons/minify.gradle
, produces the following exception:
Execution failed for task ':minifyJsExtermal'.
> No signature of method: com.eriwen.gradle.js.JsMinifier.minifyJsFile() is applicable for argument types: (java.util.LinkedHashSet, java.util.LinkedHashSet, java.io.File, com.google.javascript.jscomp.CompilerOptions, java.lang.String, java.lang.String) values: [[/Volumes/Users/esycat/tmp/gradle-js-test/js/main.js], ...]
Possible solutions: minifyJsFile(java.util.Set, java.util.Set, java.io.File, com.google.javascript.jscomp.CompilerOptions, java.lang.String, java.lang.String)
The following classes appear as argument class and as parameter class, but are defined by different class loader:
com.google.javascript.jscomp.CompilerOptions (defined by 'org.gradle.util.MutableURLClassLoader@7f3846fc' and 'org.gradle.util.MutableURLClassLoader@6574f7a7')
If one of the method suggestions matches the method you wanted to call,
then check your class loader setup.
The built-in jshint task fails the build because it returns an exit code of 1 when warnings are found. Ignore the exit code.
When specifying a sourceset and using a multiproject setup, the sourceset will contain all files from each subproject instead of being project dependent.
Simplified example:
include 'project1', 'project2'
subprojects {
javascript.source {
dev {
js {
srcDir jsSrcDir
include "*.js"
exclude "*.min.js"
}
}
}
}
Then when accessing javascript.source.dev.js in project1, it will contain the files in project2 aswell
The order of the combined scriptes are not the same as in the includes array. It seems they are added in alphabetical order by default.
The examples have this block in them:
js {
input.files fileTree(dir: "${projectDir}/js", include: "**/*.js")
output.file file("${buildDir}/combinedMinifiedAndGzipped.js")
}
It looks like the input and output parts should be changed to inputs and outputs
Just changed my version of the plugin to 0.4 with only the jshint task in my build and get the following error. Not sure about what might be going on here.
Cause: Could not generate a proxy class for class com.eriwen.gradle.js.tasks.MinifyJsTask.
The outputs.files syntax is crappy. Do better.
Something like input =
etc will suffice.
Given the following Gradle build script, running gradle jshint
fails with the error "Could not find property 'rhino' on configuration container."
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:0.4'
}
}
apply plugin: 'js'
jshint {
source = ['test.js']
}
test.js
in this example is a 0-length file, but it doesn't seem to matter what we're setting source
to.
Gradle version: 1.0-rc-2
Is there a good reason this plugin does not use DefaultSourceSetContainer (ie project.sourceSets) or a subclass with support for javascript?
Is it not straightforward to get the instantiator to insantiate the specific implementing class you want it to?
I don't know if this is just me or not but I have added my files to the javascript.source
is there a way to make it combine in a certain order?
Need to add an easy way to run JSHint and get a nice report.
Hi,
Well, compilationLevel = 'WHITESPACE_ONLY' is working but to go all the way I need to declare externs like:
/tmp/all.js:74 - variable _ is undeclared
/tmp/all.js:128 - variable console is undeclared
/tmp/all.js:390 - variable value is undeclared
/tmp/all.js:423 - variable jQuery is undeclared
/tmp/all.js:1003 - variable JSON is undeclared
/tmp/all.js:1380 - variable Gettext is undeclared
/tmp/all.js:1380 - variable json_locale_data is undeclared
/tmp/all.js:1442 - variable $ is undeclared
/tmp/all.js:1584 - variable localStorage is undeclared
/tmp/all.js:1600 - variable QUOTA_EXCEEDED_ERR is undeclared
/tmp/all.js:2294 - variable Audio is undeclared
The closure docs mention using "--externs extern1.js" where extern1.js can be a handcrafted file with simple declarations.
I looked at the Java class CompilerOptions but I cannot find a place to add the --externs?
thanks,
Jan
The minifyJs task currently only allows one file as an input. This makes it impossible to use goog.require/goog.provide so that the closure compiler can automatically order the input files in the correct order of dependencies (see http://code.google.com/p/closure-compiler/wiki/ManageClosureDependencies)
"gradle install" should not attempt to sign jars unless asked to.
If I try to use your plugin with java 1.6 (and gradle 1.3), I have the following issue:
FAILURE: Build failed with an exception.
Where:
Build file 'D:\gui\com\build.gradle' line: 62
What went wrong:
A problem occurred evaluating root project 'com'.
Could not create an instance of type com.eriwen.gradle.js.JavaScriptExtension_ Decorated.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Thanks !
Could consider this project:
http://code.google.com/p/jstd-maven-plugin/
But taking care to exclude transitive dependencies:
http://code.google.com/p/jstd-maven-plugin/issues/detail?id=5
In the github usage documentation for this plugin, it shows example such as
// Specify a collection of files to be combined, then minified and finally GZip compressed.
task combinejs(type: com.eriwen.gradle.js.tasks.CombineJsTask) {
if (env == 'prod') {
source = javascript.source.prod.js.files
} else {
source = javascript.source.dev.js.files
}
dest = file("${buildDir}/all.js")
}
The issue is that the underlying task name in this case is combineJs. Since the plugin adds the task to grade, I think the more appropriate usage would be
combineJs {
// do configuration here
}
This way you are configuring the existing task rather than creating a new one. Note this applies to all of the tasks, not just combineJs.
The jshintjs task doesn't output all warnings for me. I've noticed that 'laxbreak', 'asi' and 'newcap' warnings are output but 'strict' and 'eqeqeq' are not.
I'm running Gradle 1.4
Have I missed something out of my configuration or is there a way to specify the options? ...
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:1.3.1'
}
}
apply plugin: 'js'
javascript.source {
jshint {
js {
srcDir 'owc/WebContent/js'
include "/owc//.js"
exclude "/owcRt//.min.js"
}
}
}
task jshintjs(type: com.eriwen.gradle.js.tasks.JsHintTask) {
source = javascript.source.jshint.js.files
dest = file("${buildDir}/jshint.out")
}
The js plugin does not create any dependencies among the various tasks. It seems like certain tasks will almost always have some dependencies: combine -> minify -> gzip.
It also seems like these dependencies could be used to add defaults. For example,
minifyJs.source = combineJs.dest
Or would this make the plugin too opinionated?
Other language plugins (e.g. Java, Groovy and Scala) create and or modify project.sourceSets, which allows the gradle DSL to be consistent across different languages. It would be great if the javascript source sets were consistent with the other languages in this respect.
Desirable example: specifying LESS and javascript sources
sourceSets {
main {
javascript {
exclude "*.min.js"
}
less {
exclude "_*"
}
}
}
Greetings,
I've started on support for CommonJS modules, but I'm brand new to Gradle, so I'd love some tips.
Basic idea is that any JS repo w/ a package.json should be resolvable with something like:
class GithubCommonJsDependency {
String userName
String name
String repoName
GithubCommonJsDependency(String packageJsonUrl, String version = "master") {
// Example: https://github.com/vodori/dojo/blob/master/package.json
// /vodori is the userName
// /dojo is the repoName
userName = packageJsonUrl.split("github.com/")[1].split("/")[0]
name = repoName = packageJsonUrl.split("github.com/")[1].split("/")[1]
}
File getZip() {
Object tag = getTagByName(version)
return new File((tag.getAt("zipball_url") as String).toURL().getText())
}
Object getTagByName(String name) {
// SEE: http://developer.github.com/v3/
// TODO: This could be a whole lot nicer.
String tagJson = "https://api.github.com/repos/${userName}/$repoName/tags".toURL().getText()
ArrayList<Object> tags = new JsonSlurper().parseText(tagJson) as ArrayList<Object>
for (Object tag in tags) {
if (tag.name == name) {
return tag
}
}
return null
}
}
Initial concept comes from VoloJS, which is a great concept, but requires Node and does more than just resolve packages.
Please let me know if you're interested. I'll probably be bothering you with pull requests fairly frequently with related and advice on what you're looking for would be great.
All the best,
Josh
I receive this error when I try and import the project with IntelliJ (which runs on Java 6 as of this writing). I saw a similar issue in gradle-css-plugin (eriwen/gradle-css-plugin#5) and figured it was caused by the version in build.gradle not matching the version in plugin.gradle (on master build.gradle shows 1.3.1 whereas plugin.gradle shows 1.3). Unfortunately bumping plugin.gradle to 1.3.1 did not solve the issue. I then specified sourceCompatibility/targetCompatibility (1.6) in build.gradle, and the issue was resolved. I will add a pull request to show those changes, though I'm not certain that this is the correct solution.
Lastly, I get a warning when building with the changes. It should be resolvable with the jvm arg 'bootclasspath' (https://blogs.oracle.com/darcy/entry/bootclasspath_older_source). Here's the warning: 'warning: [options] bootstrap class path not set in conjunction with -source 1.6'. I'm wondering who/what conventionally supplies rt.jar for a build, whether it be the developer running the build or the project itself. Come to think of it, rt.jar seems like something gradle itself should supply, doesn't it? Just wondering aloud here.
The ResolverFactory seems to have been changed in Gradle 1.3, causing the plugin to break. Need to refactor or remove.
When I try to combine this two files (where I missed the ;
after a()
) :
function a(){}
a()
and
function b(){}
it will combine to
function a(){}
a()function b(){}
To prevent this combineJS needs a line break before append a new file
Hello,
I've been trying to use the jshint task from the plugin. Unfortunately I don't have access to a maven repository from my build environment. I've tried downloading the dependencies and run the task from my shell. However, the rhino configuration seems to require maven...
Selected primary task 'jshint'
Tasks to be executed: [task ':ucs-thinclient:jshint']
:ucs-thinclient:jshint
Executing task ':ucs-thinclient:jshint' due to:
No history is available for task ':ucs-thinclient:jshint'.
file or directory 'C:\Users.gradle\caches\artifacts-14\filestore', not found
:ucs-thinclient:jshint FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':ucs-thinclient:jshint'.
Could not resolve all dependencies for configuration ':ucs-thinclient:rhino'.
Could not resolve group:org.mozilla, module:rhino, version:1.7R4.
Required by:
gradle-cdl-cci:ucs-thinclient:0.1-SNAPSHOT
Could not GET 'http://repo1.maven.org/maven2/org/mozilla/rhino/1.7R4/rhino-1.7R4.pom'.
Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.
BUILD FAILED
Total time: 30.628 secs
Here is my build.gradle file...
buildscript {
// Might consider adding to gradle library...
dependencies {
classpath files ("$rootDir/lib/js/gradle-js-plugin-1.2.jar",
"$rootDir/lib/js/closure-compiler-r1918.jar",
"$rootDir/lib/js/guava-13.0.1.jar",
"$rootDir/lib/js/args4j-2.0.12.jar",
"$rootDir/lib/js/protobuf-java-2.4.1.jar",
"$rootDir/lib/js/spock-core-0.6-groovy-1.8.jar")
}
}
//https://github.com/eriwen/gradle-js-plugin
apply plugin: 'js'
//apply plugin: 'war'
// Declare your sources
javascript.source {
dev {
js {
srcDirs 'src/main/js',
'src/main/js/libraries',
'src/main/js/model',
'src/main/js/HelloWorld',
'src/main/js/HelloWorld/desktop'
include "*.js"
exclude "*.min.js"
}
}
}
configurations {
rhino
}
dependencies {
rhino files("$rootDir/lib/js/rhino-1.7R3.jar")
}
jshint {
source = javascript.source.dev.js.files
dest = file("${buildDir}/jshint.out")
}
Currently the source and dest attribute in requirejs task is mandatory. This is blocking the usage of 'modules' option of r.js. It should be optional and fallback to requirejs build file.
The minify task uses the closure compiler, but it'd be great to be able to configure the closure builder with gradle, too.
I'm having an issue with multiple js blocks in my build script I get the following error in gradle milestone 7
* What went wrong:
Execution failed for task ':js'.
Cause: Output must be exactly 1 File object. Example: outputs.file = file("myFile")
I'm pretty new to this so I certainly could be screwing something up but if I remove one of my blocks then it will execute fine.
My blocks look like the following where filea, fileb, etc... are all just references to files needed and they are broke out to preserve order.
js {
inputs.file filea + fileb + filec + filed + filee + filef + fileg + fileh + filef + fileg + fileh + filei + filej + filek + filel + filem + filen + filen + fileo + filep + fileq + filer + files + filet + fileu + filev + filew
outputs.file file("../bin/pulse-debug.js")
compilationLevel = 'WHITESPACE_ONLY'
}
js {
inputs.file filea + fileb + filec + filed + filee + filef + fileg + fileh + filef + fileg + fileh + filei + filej + filek + filel + filem + filen + filen + fileo + filep + fileq + filer + files + filet + fileu + filev + filew
outputs.file file("../bin/pulse-min.js")
compilationLevel = 'SIMPLE_OPTIMIZATIONS'
}
Please include JSHint options,
thanks.
I have a need to run multiple (many) CombineJs and MinifyJs-operations, and would like to not have to create a separate task for each, instead doing something like shown below:
task js2 {
// This works
new com.eriwen.gradle.js.JsMinifier().minifyJsFile (
file("target/build/iknowbase/iknowbase-full.js"),
[] as Set<File>,
file("target/build/iknowbase/iknowbase-full.min.js"),
project.closure.compilerOptions, project.closure.warningLevel, project.closure.compilationLevel
)
// Maybe something like this should work?
com.eriwen.gradle.js.JsMinifier.minifyJs {
source = file (...)
dest = file (...)
}
}
Greetings,
I've recently begun the migration to Gradle. Most of our apps have a massive JS stack and so, we use AMD loaders. There are several popular AMD loaders (ordered by what I think is most popular):
Additionally, there's a CommonJS (site down today, but I'm hoping it'll be back up soon) loader built on top of RequireJS called Cajon.'
All of these serve the purpose of making JavaScript loading in the browser somewhat reasonable.
I've done this w/ Maven internally, and there is a Maven plugin available, but I've not used it. Neither is much fun to use.
I'd really like a way to hook into your build system w/ various script loaders. The basic syntax might look like:
javascript.source {
dev {
// Could use a package.json to resolve the deps sort of like https://github.com/eriwen/gradle-js-plugin/issues/20
amd {
name "foo"
path "path/to/foo"
}
// A module w/ a second module builk-in
amd {
name "bar"
path "path/to/bar"
include ["foo"]
}
}
prod {
amd {
path "path/to/module"
}
}
}
task combinejs(type: foo.bar.CombineBackDraftJsTask) {
source = javascript.source.dev.amds
dest = file("${buildDir}/all.js") // Handy for combining AMD and non-AMD modules into a single built file.
}
I've started on this locally, and would be happy to implement, but I could certainly use a few pointers as I'm new to Groovy and Gradle.
Thanks for producing a great tool,
Josh
Allow task configuration inputs to use project.file()
or strings.
Would be nice to have support for props2js
Some defaults are hardcoded in tasks and should instead be wired in through the plugin convention. See the jsdoc, props2js and minify tasks of places where this needs to be fixed.
When using the combine you can do source [file,file]
, can this be added to the Gzip as that would be rather useful.
I am trying to do it that way so that I can just place a load of JS files into a directory and have it just gzip them.
I've read that since Gradle 1.2, you can natively compile Coffeescript.
http://www.gradle.org/docs/current/javadoc/org/gradle/plugins/javascript/coffeescript/package-frame.html
I'd like to know, if there is a plan about integrating this compilation in the gradle-js-plugin?
I have javascript files et coffeescript files, it would be nice to manage them in the same plugin to produce combined and minified files.
What do you think?
Closure compiler can easily generate source maps; it'd be nice if we could auto-generate these for our users.
I imagine setting sourceMaps = true
or something should be how this feature is invoked.
I am attempting to add the js plugin on an existing build but once I apply the plugin I can no longer start our application using jettyRun.
The existing build copies the multiple js files into a zip artifact for publishing, and allows a jettyRun server to be started for testing. The jettyRun pulls in the expected REST service package and its dependencies and copies the js files into the web app. This have been working for months without a problem.
However when I add the gradle-js-plugin I get an exception when calling the jettyRun (see below). For some reason when the js plugin is applied it causes the jettyRun to no longer be able to resolve all of the required dependencies. If I add the gradle-js-plugin to the buildscript classpath, but don't apply it, then there are no problems with jettyRun.
org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ArtifactNotFoundException: Artifact 'javax.jms:jms:1.1@jar' not found.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:1.0.2'
}
}
apply plugin: 'js'
apply plugin: 'jetty'
Java Version 1.7.0_03
Gradle Version 1.0
gradle-js-plugin 1.0.2 (also tested 1.0.3)
I have two different sets of javascripts, one that I want to apply simple optimizations on and one that should have advanced optimizations. But when I invoke the target with advanced optimization (gradle projectx:minifyBJs) I get the simple optimization of the files defined for target minifyBJs. If I remove minifyAJs it works as expected.
task minifyBJs(type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
source = combineBJs
dest = file("${buildDir}/js/b-min.js")
closure {
compilationLevel = 'ADVANCED_OPTIMIZATIONS'
externs = files("${javascriptSourceDir}/externs.js")
warningLevel = 'QUIET'
}
}
task minifyAJs(type: com.eriwen.gradle.js.tasks.MinifyJsTask) {
source = combineAJs
dest = file("${buildDir}/js/a-min.js")
closure {
compilationLevel = 'SIMPLE_OPTIMIZATIONS'
warningLevel = 'QUIET'
}
}
Hi,
I am probably doing something wrong, but when I run the following build script
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.eriwen:gradle-js-plugin:1.1'
}
}
// Invoke the plugin
apply plugin: 'js'
I get an error on the apply plugin line of "Could not find property 'extensions' on root project".
Version info:
Gradle build time: Thursday, September 8, 2011 4:06:52 PM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.2 compiled on December 3 2011
Ivy: non official version
JVM: 1.7.0_07 (Oracle Corporation 23.3-b01)
OS: Linux 3.2.0-29-generic amd64
Any ideas?
Please add a warning when a non existed file was added to the includes array.
It would be good if we could pass in our own jshint configuration options, such as failing on undefined variables, customizing globals, etc. I know we can provide that information in comment blocks in the javascript files, but it's a bit of a pain to define the same comment block like that at the top of every js file (especially if the configuration changes).
It would be great if this plugin could be used to provide an automated, build-time way to switch html back and forth between unminified dev versions and minified prod versions of JS files. This could be done by directly updating the HTML, but it might be nicer if it worked something like this:
Thanks for the cool plugins. I've just started using them, but so far they're a great solution to an annoying problem.
I would be cool to have the possibility to generate JavaScript docs with jsdoc (http://code.google.com/p/jsdoc-toolkit/)
I've tried to use the techniques mentioned here and here. I'm getting the following error, and I'm a bit confused as to how to resolve it:
A problem occurred evaluating root project 'myprojectname'.
Could not find property 'outputs' on
com.eriwen.gradle.js.source.internal.DefaultJavaScriptSourceSet_Decorated@65144e1b
.
Here's the offending SourceSet definition:
javascript.source {
configfile {
js {
srcDir 'app'
include "config.js"
}
}
dev {
js {
srcDir 'app'
include "**/*.js"
exclude "**/*.min.js", "config.js"
}
compileClasspath += configfile.outputs
}
prod {
js {
srcDir 'app'
include "**/*.min.js"
}
}
}
Do you have any insight as to why this might be happening?
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.