Maven jarsigner plugin - maven

I just tried to configure the maven jarsigner plugin for signing a jar project.
As far as I can understand, the plugin should run automatically when I run mvn clean package but it doesn't.
I must run mvn clean package jarsigner:sign for the plugin to be executed.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.4</version>
<configuration>
<executions>
<execution>
<id>sign</id>
<phase>package</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<alias>java-code</alias>
<keystore>mykeystore.keystore</keystore>
<keypass>mykeypass</keypass>
<storepass>mystorepass</storepass>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
I could find the error on my own. The configuration element has to be within the execution element.
Thanks.

Related

Trouble launching chromedriver in Spock test

I have a Maven web project for which I'm trying to run a couple of simple Spock web UI tests under Eclipse with Selenium and Chromedriver. I can run each test class individually by clicking on it and selecting "Run As>Junit Test" if I add the following to the file's run configuration VM arguments:
-Dwebdriver.chrome.driver=/Users/mht/ChromeDriver/2.3.1/chromedriver
Obviously, this is the location of the Chromedriver on my system. Then I tried to set up a Maven build goal at the project level to run the tests. I click on the project name and select "Run Configurations>Maven Build" and create a "Verify" configuration to match the verify goal defined in my pom. In the "Goals, box I enter "verify" and on the JRE tab I also enter the above location for the chromedriver in the VM arguments box. When I run this goal, or on the command line type "mvn verify", I get the following error:
geb.driver.DriverCreationException: failed to create driver from callback 'script15040527017471153797989$_run_closure1#1046d517'
at com.google.common.base.Preconditions.checkState(Preconditions.java:754)
...
This tells me the test can not locate the chromedriver. If I copy the chromedriver into the base directory of the project, the then the test will run using the verify goal or by typing "mvn verify" on the command line. Why isn't setting the chromedriver location not working at the maven goal level?
I don't think this really matters, but the build section of my pom is
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*Spec.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>run-war-only</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<port>9081</port>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>tomcat-shutdown</id>
<goals>
<goal>shutdown</goal>
</goals>
<phase>post-integration-test</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The maven arguments are not passed to the surefire and failsafe configurations per default. Both fork new JVMs which doesn't get these arguments. See the docs Surefire and Failsafe regarding argLine.
So mvn verify -DargLine="-Dwebdriver.chrome.driver=/Users/mht/ChromeDriver/2.3.1/chromedriver" should work for you.
However, the better way is to use the WebDriver Extensions Maven Plugin which can be used to automatically download the appropriate driver. You can then do some simple scripting to locate the driver via your geb config, or hard code the known relative location.
BTW the gmaven-plus plugin is outdated.

Maven shade plugin is not called automatically for goal "package"

I've spent quite a bit of time figuring out how to invoke Maven shade plugin to build a uber-jar (with all dependencies).
Most of the google-able info that I found (including numerous examples, and Maven documentation) suggests that all I have to do is include the plugin into pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
and then "mvn package" (or any other goal that eventually invokes "package") will automatically trigger this plugin.
But no matter what I tried - the only way to actually invoke the plugin appears to be: running "mvn package shade:shade" (which seems to defeat the purpose of config-driven build). Same results whether running Maven from within Eclipse (STS Version: 3.8.2.RELEASE), or from command line (Apache Maven 3.3.9).
Am I missing anything?
UPD: solved, see answer by GauravJ.
I have managed to reproduce your problem. In your pom.xml, you must have defined plugin like below,
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
....
</plugins>
</pluginManagement>
</build>
instead of
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
This will probably fix your problem.

How can I execute following maven plugin before resolving the dependencies

I am from ANT background and newbie to Maven.
For some reason, I need to execute shell script before maven tries to fetch snapshot dependencies.
So I wrote following plugin configuration, but I not getting how can I make it invoke before resolving dependencies task.
I am using Apache Maven 3.0.5
Following is the part of my pom.xml
<build>
<finalName>edte</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<phase>clean</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>Docs/ci/delete_snapshots.sh</executable>
<arguments>
<argument>${user.home}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Any help is appreciated.

Maven how to invoke a plugin goal?

In the Tomcat Maven plugin, tomcat7-maven-plugin, how to invoke the goal, tomcat7:deploy, after package phase ? can you please give me concise sample pom file ?
Thanks.
Add an execution for the plugin and tie it to a phase after the package phase, i.e. verify or install..
<build>
<plugins>
<plugin>
<dependency>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>deploy</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

is is possible to install the source and javadoc jar to maven repository along with a single command `mvn clean all`

As we all know that using mvn clean install will install the built package,eg jar, zip, pom, to local repo , but source and javadoc jar . Can I make some changes on pom.xml so that source and jardoc jar would be installed to local repo with mvn clean install
Yes, what you want to do is to add the maven-source-plugin and maven-javadoc-plugin to your pom. This will cause the jar goal to execute automatically during the package phase without needing to specify it on the command line.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
...
<plugins>

Resources