Can we bind some native OS commands to the maven goals and/or phases?
Actually there is the Exec Maven Plugin for these cases.
See exec-maven-plugin for details
Not natively.
However, by using the AntRun plugin, you can specify an Ant task (using Exec) that execute a OS command during the build.
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase> <!-- a lifecycle phase --> </phase>
<configuration>
<tasks>
<!--
Place any Ant task here. You can add anything
you can add between <target> and </target> in a
build.xml.
-->
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
Related
I wonder if there is any way to update Firebird's database record after (or during) maven's build. This is necessary to refresh application's version in db. Is there any maven plugin or possibility to run any shell script after package maven's goal? Thank for any support.
You can execute any shell command from maven using the exec-maven-plugin
Here's an example configuration:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>obfuscate</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<!-- Change the value to your jar -->
<argument>path/to/your/Programm.jar</argument>
<!-- Jar-Args -->
<argument>arg1</argument>
</arguments>
</configuration>
</plugin>
When will plugin execute if I don't specify a phase?
for example that plugin
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<configuration>
<!-- if you don't specify any modules, the plugin will find them -->
<!-- <modules> <module>learning.vaadin.gwt.ColorPickerWidgetSet</module> </modules> -->
</configuration>
<goals>
<goal>update-widgetset</goal>
</goals>
</execution>
</executions>
</plugin>
It depends on the plugin. If the plugin author specified an #phase in the mojo metadata, it will end up there. If not, it won't run at all.
Is there something for maven like http://subclipse.tigris.org/svnant.html ? Something to automate your project updates without having to click update?
The Maven SCM Plugin does support Subversion. Check the Usage page.
There is always the possibility to run ant inside maven.
Ant is much more powerful than maven in many respects, but maven excels in dependency management and ease of deployment. So if you need the power of ant inside maven, use the maven antrun plugin:
Taken from
http://maven.apache.org/plugins/maven-antrun-plugin/usage.html :
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase> <!-- a lifecycle phase --> </phase>
<configuration>
<tasks>
<!--
Place any Ant task here. You can add anything
you can add between <target> and </target> in a
build.xml.
-->
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Sean
I have defined the following profile in pom.xml:
<profiles>
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>dev</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete file="src/main/application/META-INF/data-sources.xml"/>
<copy file="src/main/resources/data-sources-dev.xml" tofile="src/main/application/META-INF/data-sources.xml"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The issues is that it doesn't seem to work!
mvn help:effective-pom -P dev
Does echo also the profile.
However, if I do
mvn -X -Pdev install
The delete / copy part is not visible in the logs.
There is no phase with the name dev. Please specify a correct phase.
I've just copy-pasted your configuration into a basic pom and it works just fine. Are you sure it doesn't appear in the config as well as the profile? If you redirect the output to a file and search for "antrun" I suspect you'll see that it is declared in the build section of the effective pom.
Your antrun plugin configuration needs to bind to a valid phase for its packaging type before it will be executed. If you want the contents to be available in the jar (assuming jar packaging), this needs to be before the package phase. I would suggest process-resources.
So change:
<phase>dev</phase>
to:
<phase>process-resources</phase>
I've some test resources (that are specific for a particular task) zipped in /test/resources/my.zip.
I want to extract the zip content to /target during the maven Test Phase.
Do you know what should I specify in the pom.xml to achieve this?
One solution is to use the maven-antrun-plugin to run the unzip Ant task. The following configuration in the build section of your POM should be pretty much what you need (but I haven't tested it):
<build>
<plugins>
<!-- ... -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-test-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<unzip src="test/resources/my.zip" dest="target/" overwrite="true"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<!-- ... -->
</plugins>
</build>