I have a Maven POM file with a plugin that runs on the test phase. What command line arguments do I have to pass mvn in order to execute just that plugin rather than all of the plugins for that phase? I am also trying to execute a specific ant-run plugin, that looks like the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<dependencies>
<dependency>
<groupId>com.googlecode.jslint4java</groupId>
<artifactId>jslint4java-ant</artifactId>
<version>1.3.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>jslint</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<ant antfile="${basedir}/jslint.xml">
<property name="root" location="${basedir}" />
<target name="jslint" />
</ant>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Thanks.
Specify the fully-qualified goal in the form of:
mvn groupID:artifactID:version:goal
For example:
mvn sample.plugin:maven-hello-plugin:1.0-SNAPSHOT:sayhi
EDIT: I'm modifying my answer to cover the update of the initial question and a comment from the OP.
I won't cover all the details but, it the particular case of the antrun plugin, you could just run:
mvn antrun:run
But now that you've updated the question, I understand that things are a bit more complicated than what I thought initially and I don't think that this will actually work. I mean, invoking mvn antrun:run won't fail but it won't pick up the configuration of the execution bound to the test phase.
The only (ugly) solution I can think of would be to add another maven-antrun-plugin configuration in a specific profile, something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<dependencies>
<dependency>
<groupId>com.googlecode.jslint4java</groupId>
<artifactId>jslint4java-ant</artifactId>
<version>1.3.3</version>
</dependency>
</dependencies>
<configuration>
<tasks>
<ant antfile="${basedir}/jslint.xml">
<property name="root" location="${basedir}" />
<target name="jslint" />
</ant>
</tasks>
</configuration>
</plugin>
And to use this profile when calling antrun:run:
mvn antrun:run -Pmyprofile-for-antrun
Related
I want to define property or want to use maven.plugin.classpath and maven.dependency.classpath in my build.xml.
How can i do it ?
Sample code is as below...
<property> </property> is not working and not able to read the values from my build.xml so please explain me how can i do it ?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<property name="maven_dependency_classpath" refid="maven.dependency.classpath" />
<executable>antscript.bat</executable> <!-- ant -f build.xml build -->
</configuration>
</plugin>
Hi Sean Patrick Floyd,
Yes i tried using maven-antrun-plugin but i am not able to setup JDK 1.4.2 version in it. I am trying to specify all possible way to apply JDK version 1.4.2 but it's still taking tools.jar or JDK version, Which maven.bat file is using (jdk 1.5)
I was using following code in MAVEN-ANTRUN-PLUGIN as below code.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<compilerVersion>${java-version}</compilerVersion>
<executable>${java.1.4.2.home}/bin/javac</executable>
<target>
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<property name="maven_dependency_classpath" refid="maven.dependency.classpath" />
<ant antfile="ant_build.xml" />
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>${java.1.4.2.home}/lib/tools.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>rt</artifactId>
<version>${java-version}</version>
<scope>system</scope>
<systemPath>${java.1.4.2.home}/jre/lib/rt.jar</systemPath>
</dependency>
</dependencies>
</plugin>
That's why i choose exec GOAL where my SYSTEM JAVA_HOME is 1.4.2 and it's able to execute it if i have all dependencies which i needed.
Please help me out.
Thanks.
maven.plugin.classpath etc. are variables defined in the maven-antrun-plugin only. The exec plugin doesn't know about these values. Also, it wouldn't be possible to do it like that in the first place, as you are calling an external .bat file and hence starting a new process.
If I were you I'd use the antrun plugin. See the usage page for details.
Update: ok, now I see your problem. No, you can't use a different JDK, since antrun works within the same vm. So either you need to switch the JDK maven uses, or you do in fact need to use the exec-maven-plugin. In the latter case, you will have to use
dependency:build-classpath -DoutputFile=someFile.txt
and on the ant side, read the contents of someFile.txt as a property and create a classpath from it. Or you can use the %classpath variable placeholder in your command line args.
Yes correct answer which i found is to Use MAVEN version which supports JDK 1.4.2. So i have to use apache-maven-2.0.11 which supports JDK 1.4.2
Thanks all for your answers.
I am trying to write an integration test POM for our project. We've got the project downloading and installing/unzipping appropriately (using the maven-dependency-plugin), but one caveat of our project is that it can't yet run in paths that have spaces in them. I'm looking for a very simple way to evaluate ${project.build.directory} and throw a human readable error if it contains spaces. I'd like this to happen BEFORE downloading dependencies, since this takes quite a bit of time.
This will do it with the help of antrun plugin and <contains> condition.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<fail message="project.build.directory(${project.build.directory}) contains spaces">
<condition>
<contains string="${project.build.directory}" substring=" "/>
</condition>
</fail>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
How can Flyway commands be chained into a single command using Maven?
For example, I want to run mvn initialize flyway:clean followed by mvn initialize compile flyway:migrate. However, mvn initialize flyway:clean compile flyway:migrate fails.
Thanks!
I just checked
mvn initialize flyway:clean compile flyway:migrate
with both Maven 2.2.1 and Maven 3.0.3 and it works every time.
Could you double check this? In case you think you really found a problem, please file an issue in the Issue Tracker with the necessary steps to reproduce it and I'll do my best to fix it asap.
That will give you the ability to chain maven steps, just add the goals you want in there
<profile>
<id>clean-migrate</id>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>process-resources1</id>
<goals>
<goal>resources</goal>
</goals>
<!-- Populate the database before querydsl-sql runs -->
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>com.googlecode.flyway</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<executions>
<execution>
<id>process-resources2</id>
<goals>
<goal>clean</goal>
<goal>migrate</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<version>1.4.2</version>
<configuration>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<url>jdbc:oracle:thin:#${database-hostname}:${database-port}:${database-sid}</url>
<user>${database-username}</user>
<password>${database-password}</password>
<schemas>${database-schema}</schemas>
<table>schema_history</table>
<initialVersion>0.1.00</initialVersion>
<initialDescription>Base Migration</initialDescription>
</configuration>
</plugin>
</plugins>
</build>
</profile>
You will also need the following in your settings.xml
<profile>
<id>inject-flyway-properties</id>
<properties>
<database-hostname>${env.DB_HOSTNAME}</database-hostname>
<database-port>${env.DB_PORT}</database-port>
<database-username>${env.DB_USER}</database-username>
<database-password>${env.DB_PASSWORD}</database-password>
<database-sid>${env.DB_DEFAULT_SID}</database-sid>
<database-schema>${env.DB_SCHEMA}</database-schema>
</properties>
</profile>
If i understand the docs correct you have to configure the maven-flyway plugin to do the work and bound it to the correct phases of maven than you can use the default maven calls like mvn clean package or mvn clean verify.
You can use profiles in order to bundle "commands" together. Once it's done you just call:
mvn -Pmy-profile
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>
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>