We have a maven project where we use several linux bash scripts for various entries to our java application. We have solved this by the exec-maven-plugin so the scripts typically looks like: mvn -e -o -q exec:exec -Dexec.executable="java" -Dexec.args="...". For some reason, we are constrained to use tho offline flag (-o).
My question is: How do I ensure that the exec-maven-plugin is downloaded during the compile phase? There is a risk that a developer doesn't have the exec-maven-plugin downloaded and since the exec-maven-plugin is used with the maven offline flag it won't be downloaded if it is not there.
Thanks to the comments of #eis I managed to sort this out. The pom now looks like this:
<properties>
<additionalJavaArgs></additionalJavaArgs>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<executable>java</executable>
<commandlineArgs>
-XX:+PrintCommandLineFlags -showversion -classpath %classpath ${additionalJavaArgs}
</commandlineArgs>
</configuration>
</plugin>
</plugins>
</build>
The bash script looks like the following:
ADDITIONAL_JAVA_ARGS=$*
mvn -e -o -q exec:exec -DadditionalJavaArgs="$ADDITIONAL_JAVA_ARGS"
That way the user of the script can add a main class followed by an unlimited number of application arguments.
Related
maybe this is a generic question with regards to how to transfer maven plugin paramters from the pom.xml to the commandline, but I have usually done this without problems using the method below. For the find-security-bugs plugin, however, it is not working.
The find-security-bugs plugin docu says that you can configure the plugin in your pom.xml as follows:
<plugins>
[...]
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.7.2.1</version>
<configuration>
<includeFilterFile>spotbugs-security-include.xml</includeFilterFile>
<plugins>
<plugin>
<groupId>com.h3xstream.findsecbugs</groupId>
<artifactId>findsecbugs-plugin</artifactId>
<version>1.12.0</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
I would like to do the same, but cannot do any changes to the pom.xml I'm testing, so would have to specify everything in the command line.
I'm running (from powershell, therefore the quotation marks):
mvn com.github.spotbugs:spotbugs-maven-plugin:4.7.2.1:check -"Dplugins.plugin.groupId=com.h3xstream.findsecbugs" -"Dplugins.plugin.artifactId=findsecbugs-plugin" -"Dplugins.plugin.version=1.12.0" -"DincludeFilterFile=secbugsfilter.xml"
but the parameters are not used. Is there any way to run a plugin with a configuration like this from the command line without specifying anything in the pom?
I have maven surefire plugin on pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>org.mycompany.service/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
Now I want maven to execute test ONLY on deploy goal, therefore:
When executing mvn deploy tests should run
When executing mvn package or mvn install, tests should not run because goals are prior to deploy
The only way I can think of to make this work would be to bind the surefire plugin to the deploy phase. This has drawbacks:
The tests are run after the artifacts was installed.
Maybe the tests break because they are not meant to be run that late in the lifecycle.
I am not sure how to make sure that they are executed before the deployment happens.
Do you want this behaviour by default, or do you want that just for you or in certain environments?
Adding -DskipTests to the command line is usually good enough.
I have some CLI aliases that I use on my local workstation, so I don't have to type all of it, and don't forget to add it. See e.g. for zsh: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/mvn
using command /opt/jdk1.8.0_211/bin/java -jar webprx.jar get this error: Error: Invalid or corrupt jarfile webprx.jar
jar was build with mvn clean package and mvn install
Pom
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
Remove the executable configuration.
From the documentation this makes it executable by *NIX systems.
Make a fully executable jar for *nix machines by prepending a launch script to the jar.
Currently, some tools do not accept this format so you may not always
be able to use this technique. For example, jar -xf may silently fail
to extract a jar or war that has been made fully-executable. It is
recommended that you only enable this option if you intend to execute
it directly, rather than running it with java -jar or deploying it to
a servlet container.
https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/maven-plugin/repackage-mojo.html
I am studying Maven plugins from the official references. I read:
You can also configure a mojo using the executions tag. This is most
commonly used for mojos that are intended to participate in some
phases of the build lifecycle.
but If I do not use the <executions> tag, like this:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-myquery-plugin</artifactId>
<version>1.0</version>
<configuration>
<url>http://www.foobar.com/query</url>
<timeout>10</timeout>
<options>
<option>one</option>
<option>two</option>
<option>three</option>
</options>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
what happens?
Will we be able to run a goal from maven-myquery-plugin only in isolation giving a command like mvn myquery:myquery or does the plugin come up bundled in some phase/life cycle by default?
I also have been wondering if it's possible to skip the executions tag. As there is no direct answer on the official website I tried to make such a plugin with default phase bindings by myself and the answer is: no goals will be executed if they weren't specified in the executions tag. Such a plugin (goal) could be executed only by direct command: <plugin>:<goal>
Is it possible to set env vars in pom.xml that junit tests uses? Netbeans can get env vars and builds project correnctly. But when i use command line (mvn clean -> mvn install), build fails due to test errors.
Thanks.
There are two approaches I know.
Commandline:
You can pass it in command line like
mvn -DAM_HOME=conf install
Using pom :
If AM_HOM is the variable and the value is conf ,make entry like below.
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
...
<configuration>
...
<environmentVariables>
<AM_HOME>conf</AM_HOME>
</environmentVariables>
</configuration>
</plugin>
...
<plugins>