Execute file from maven goal - java

I like to integrate compass (https://github.com/Compass/compass/wiki)
in my java project, and I need something to compile .sass files to css without running commands manualy.
So is there a way to execute a file using some maven plugin or goal?

Try the exec-maven plugin

The maven-antrun-plugin is the usual practice here, as it allows you to use an ant task to execute whatever. An alternative might be Groovy, but I confess that I don't know for sure that it can execute an arbitrary executable.

Related

Run a script after JSweet transpilation

I'm trying to build a TypeScript project with JSweet. After the transpilation, I want to run a script in any language to move some files around; specifically files that are already in TypeScript that don't need transpilation. I wrote a Groovy script that does just that but I can't make it run after the generate-sources instructions for JSweet.
Here's my pom.xml file: https://pastebin.com/932r9cWw
I am far from a Maven expert. I think the script shows that I'm trying to run the script scripts/addJsScripts.groovy after the transpilation, but I'm clearly doing something very wrong. The goals available to Maven Invoker plugin don't match the goals of the JSweet transpiler at all.
Is there a way to do what I'm trying to do?
There are plenty of ways to achieve this, but this is more a Maven issue than a JSweet one.
I suggest you use the exec-maven-plugin, as explained here: I want to execute shell commands from Maven's pom.xml

create a Groovy script distribution/executable via Maven

I have a project module full of groovy scripts which are run via embedded IntelliJ Groovy shell. In a new issue I need to have one of those scripts being run in combination with crontab. Needless to say I cannot just run groovy myScript.groovy dev to have this script executed out of the box - no the dependencies are missing for sure.
I now need a way to have this one particular groovy script being compiled and ready to run out of the box (with the use of the "dev" parameter)
Assuming that I put the myScript.groovy into a directory
main/
|_src/
|_groovy/
What do I need to have a maven build creating a usable executable for me to drop into my machine and let crontab run it accordingly.
I tried a lot of Maven Plugins - but never came far enough. Also I'm sure that there must be a way more trivial way to achieve this since it's a simple build operation in my opinion.

Perform additional tasks within a maven build

I am wondering about how to perform specific tasks during a maven build: I would like to use some of my code to do some preprocessing on the data that I am shipping in the resulting jar. Generally given some input.xml in src/main/resources I would like to be able to call a java function / main method to obtain a file output.xml which is included available as a resource (and probably placed in target/classes/...). Using Makefiles this would correspond to an additional rule, I guess this could be done with an ant task as well (though I have never used ant myself). can I add such a rule to a maven project as well?
You can use the Maven Exec Plugin to run arbitrary Java code during your build.
If you should happen to have your tasks formulated as Ant targets, the Maven Antrun Plugin can be used to run those.

Using maven in scripts or adding a script-runner task at the end

I'm using maven on both mac and linux to build a .war file for a website. I'd like to know the best way to automatically run a script that will deploy the website to the server after a build.
What I am currently doing is I have a deploy.sh script that will run
mvn -P<PROFILE> clean package
and will then do a bunch of ssh / scp stuff to copy the target/file.war to the web server and run a bunch of commands to start/stop tomcat - clean out the logs etc.
Problems
Although various stack posts say using $? is supposed to catch the error code from maven I have yet to get it working and if for some reason I have a bad maven build I have no way to detect it. I would not like to do all my deploy tasks if the build fails.
Options?
1) Is there a correct way to detect a bad "build" from maven and have my script abort (I guess i could check if the war doesn't exist ...??)
2) Is there a maven "plugin" that will actually handle this for me, and if so could somebody provide a small code example.
I would do two things in the shell script which calls Maven and the deployment commands:
test whether the WAR file exists before attempting to deploy it, as you suggest yourself;
save Maven output to a timestamped log file for reference.
You may want to consider using maven as the entry point to the deployment and let it call deploy.sh rather than the other way around. This way maven will fail the build if something goes wrong.
The Ant plugin should be able to help with this, take a look at the second example here. It allows you to run a script and fail on error if desired.

Do i have a chance to run a user defined program to generate resource?

I have a war project with maven ,
And I wonder if there is a plugin OR such a mechanism to generate resources at compile time so that I can minify CSS or minify JS or generate CSS-sprite ?
I think this should be a very nice plugin.
I've not used it myself, but the invoker plugin appears to be what you need. It gives you the ability to run scripts pre and post-build. For your case, just use a pre-build script to run whatever utility you need.

Categories