0

Using the following Gradle gulp plugin which simply executes the gulp task from a gradle task via a simple naming convention gulp_<task name>

In the extended options on the docs : Gradle gulp plugin extended docs it demonstrates the following:

task gulpBuildWithOpts(type: GulpTask) {
  args = ["build", "arg1", "arg2"]
}

In my standard build task executed by gradle like so:

// runs "gulp build" as part of your gradle build
bootRepackage.dependsOn gulpBuildWithOpts

task gulpBuildWithOpts(type: GulpTask) {
  args = ["build", "--env prod", "--buildType gradle"]
}

The following is executed and built, however the args are ignored, gulp never picks them up. The args should be handled by Yargs command line parser

If I run direct with gulp (like below) then this works fine, so why am I getting my args ignored when ran from gradle?

 gulp build --env dev --buildType gulp

NOTE - App layout is Springboot / AngularJS (^1.5) if you're wondering about choice of tooling.

RRR
  • 35
  • 7

1 Answers1

0

You need to pass those options in separately:

task gulpBuildWithOpts(type: GulpTask) {
  args = ["build", "--env", "prod", "--buildType", "gradle"]
}

Otherwise "--env prod" is interpreted by yargs as a single option named env prod, instead of an option named env with an argument of prod.

Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70
  • Thanks for your response :)... That's not true about the key val [see yargs website scroll to bottom to see example](http://yargs.js.org/). As you can see demonstrated above or here: `gulp build --env dev` would work fine and you can see it is set with a simple `console.log('Env is:', argv.env)` . I did however try your response above, but that doesn't work either `:'(` – RRR Sep 19 '16 at 15:34
  • The gradle task in your question doesn't run `gulp build --env dev`. It runs `gulp build "--env dev"`. Try running that on the command line and you will see the same problem you have in your gradle build. – Sven Schoenung Sep 19 '16 at 15:42
  • If my solution above really doesn't work then you need to provide a proper [MCVE](http://stackoverflow.com/help/mcve), because something else is amiss. – Sven Schoenung Sep 19 '16 at 15:46
  • Yes that too doesn't run: `gulp build "--env dev"`... Your OP above doesn't work either unfortunately... one would assume, the values would be interpolated into one string to be executed. Struggling to see where this is happening [plugin source class](https://github.com/srs/gradle-gulp-plugin/blob/master/src/main/groovy/com/moowork/gradle/gulp/GulpPlugin.groovy) – RRR Sep 19 '16 at 16:24
  • Tried even `args = ["build --env test --buildType whatever"]` no joy – RRR Sep 19 '16 at 16:33
  • `args` isn't "interpolated into one string". It's passed as an array directly to the `node` executable. That's why the code I posted above is correct. I tested it on a simple example and it works. If it doesn't work for you that's because you have another mistake somewhere else. So you either post an MCVE or I'm voting to close this question. – Sven Schoenung Sep 19 '16 at 16:47
  • Right your solution does work :) ... something else must be causing the issue went back to basics empty build and basically just yargs in the gulp file. It worked so thanks you very much (y) – RRR Sep 19 '16 at 22:27