We're using exec-maven-plugin to run RequireJS's optimizer (r.js) under Node.js (because it's a lot faster than Rhino):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>compile-js</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${node.executable}</executable>
<arguments>
<argument>${project.build.directory}/dependency/requirejs/r.js</argument>
<argument>-o</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
The issue is, whenever there's any issue during compilation, the error messages that r.js is supposed to blurt out are not shown in Maven's console output. What I do to troubleshoot is, I rerun the Maven command with the -X flag to get debug output so that exec-maven-plugin outputs the actual command being executed. It's something like:
project-root/target/dependency/node/node \ project-root/target/dependency/requirejs/r.js \ -o src/main/webapp/app.build.json
When I run the command manually from the command line, I then get the actual compilation errors in the console and then proceed to fixing them.
I've experimented with redirecting stderr to stdout with 2>&1
to no avail (on Windows) because I couldn't immediately find a way to make exec-maven-plugin like the redirection bit as an argument. I didn't pursue that route too far because it's just a wild guess that this is a stderr/stdout issue -- it could be, but I'm merely speculating.
Any pointers to as to what may be happening, or any suggestions for further diagnostic steps that I can take? Please remember there are multiple moving parts in this problem: Maven, exec-maven-plugin, Node.js, r.js, and one tired head.
P.S. I'm considering giving requirejs-maven-plugin a shot as a last resort because the project timeline doesn't allow me to do a complete overhaul of the POM right now. I'm trying to see if there's anything I can do with the current setup.
How about wrapping the call to node.js
and r.js
in a script, that you then call from the maven-exec
plugin?
From a look at r.js
, it seems to use console.log
for it's output. Maybe running it from a shell script will allow you to catch the output, pipe it into a file, regex for an errors, etc.
Depending on the OS, this might be easy to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With