Run a script after JSweet transpilation - java

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

Related

Is it possible to package a portable maven in the project (and some general direction on how)?

The solution which needs bootstrapping is supplied as java code. Absolutely sure that this is necessary.
Receivers of the solution are guaranteed to have a suitable JDK
However, receivers of the solution are unable to install Maven (they don't know how to and cannot be taught)
My idea is to include some sort of Maven with the project, such that can be set up in a script like so:
set up maven repo as a folder under the solution folder (using relative reference)
set up anything else maven needs (don't know what, exactly)
call /path/to/maven/mvn compile -f /path/to/oneAndOnly/pom.xml
java /target/MySolutionClas
I am aware of: https://dzone.com/articles/embedding-maven but it gets confusing when he talks about configuring the portable maven into the pom.xml - wait, how is that pom.xml going to mean anything if maven is not configured yet?
(PS: I mean no disrespect to the author. I probably got it all wrong)
One could include a shell script that would setup maven if it is not already present.
The same for building and packaging encapsulating the complexities of the setup to just runing a couple of scripts.
Maven Wrapper aims to do just that, similar to the gradle wrapper seen in many gradle projects.
Running the wrapper goal of the maven wrapper plugin will generate a mvnw script in your project that can be run in place of a globally installed mvn command.
It's part of the maven 3.7.0 release, and documented more fully here: https://maven.apache.org/plugins/maven-wrapper-plugin/index.html
See https://github.com/takari/maven-wrapper for maven < 3.7.0

IntelliJ maven vs normal maven

I would like to add my own commands to delete a specific folder in the mvn repository whenever I run a maven command.
For using maven through the command prompt, this is quite easy since we just update apache-maven-3.5.3\bin\mvn.cmd .
However, I noticed that when we run mvn from intelliJ Maven projects Tool Window, the command run is the following:
C:\mbakOrg\Oracle\JDK\jdk1.8.0_60\bin\java -Dmaven.multiModuleProjectDirectory=
C:\mbakOrg\_CODE\MNE_ARCHIT_GIT\_REPOS\sg-template-store -Dmaven.home=C:\mbakOrg\build\apache-maven-3.5.3 -
Dclassworlds.conf=C:\mbakOrg\build\apache-maven-3.5.3\bin\m2.conf "-javaagent:C:\mbakOrg\devel\JetBrains\IntelliJ IDEA
2017.1.3\lib\idea_rt.jar=42633:C:\mbakOrg\devel\JetBrains\IntelliJ IDEA 2017.1.3\bin" -Dfile.encoding=UTF-8 -classpath
C:\mbakOrg\build\apache-maven-3.5.3\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2017.1.3 clean install
So how will I add a command that will run every time?
Since maven in InteliJis using a custom way to run maven.
Explanation
My problem is basically that the mvn -U command does not properly pull the newest code all the time. Additionally, we are all using a snapshot of a parent project that is being updated quite often to fix issues.
I would strongly discourage modification of mvn.cmd. Even if you figure out how to do it in command line, and in InteliJ, then think about moving to some kind of Continuous Integration framework, like Jenkins for example, which will use default mvn.cmd?
If there is no possibility to achieve what you want with existing Maven tools, I would recommend writing own Maven plugin, (see this tutorial), and put required functionality there. It will guarantee, that this particular piece of code will be executed in all the environments, and this is the way to make sure, that the command will be launched every time.

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.

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.

Execute file from maven goal

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.

Categories