I am using mvn-ant-task in a build file to clean and install the Maven projects.
Below is the configuration I did
<project name="maven-project"
default="default"
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
and in the target, I have added something like this
<target name="CleanInstall">
<echo message="Building the project using maven and skipping tests if any in ${RepoFolder}" />
<artifact:mvn pom="${GIT_REPO_HOME}\${RepoFolder}\pom.xml">
<arg value="clean:clean" />
</artifact:mvn>
<artifact:mvn pom="${GIT_REPO_HOME}\${RepoFolder}\pom.xml">
<arg value="install:install -DskipTests=true" />
</artifact:mvn>
</target>
When I run this build, clean is processing properly, but I am unable to send the arguments skipTests in the install plugin.
Is there any other way to execute the Maven commands from Ant? I also tried
<exec command="mvn install -DskipTests=true" dir=""${GIT_REPO_HOME}\${RepoFolder}\pom.xml"/>
Its failing with error given below
C:\Users\sharath\Desktop\devsetup\build.xml:102: Execute failed:
java.io.IOException: Cannot run program "mvn" (in directory
"D:\sbhaskara\GIT\connectmodel"): CreateProcess error=2, The system
cannot find the file specified
You are not building the argument for the task correctly, it should be:
<target name="CleanInstall">
<echo message="Building the project using maven and skipping tests if any in ${RepoFolder}" />
<artifact:mvn pom="${GIT_REPO_HOME}\${RepoFolder}\pom.xml" >
<arg value="-Dmaven.test.skip=true" />
<arg value="clean" />
<arg value="install" />
</artifact:mvn>
</target>
i.e. each argument must be in its own <arg> tag. Note that I collapsed all the calls to Maven inside a single task.
Related
I am trying to create an ant task to execute a maven command, but I am getting error while running the ant task
<target name="Junit">
<exec dir="./MServer/BuildServer/Workspc/CustMgmt" executable="cmd">
<arg value="/C"/>
<arg value="E:\EOM Setup\maven-3.3.9\bin\mvn.bat"/>
<arg value="test" />
</exec>
</target>
While am running this, am getting an error:
'E:\EOM' is not recognized as internal or external command, operable program or batch file
(I am running on Windows 7)
You can get around this issue by using Ant's property task with the location attribute (as opposed to the more common value attribute). This will store the value as a properly formatted path. In addition, you can use this to reference mvn.bat instead of typing out the entire path every time.
<target name="Junit">
<property name="mvn.executable" location="E:\EOM Setup\maven-3.3.9\bin\mvn.bat" />
<exec dir="./MServer/BuildServer/Workspc/CustMgmt" executable="cmd">
<arg value="/C"/>
<arg value="${mvn.executable}"/>
<arg value="test" />
</exec>
</target>
I'm trying to install highcharts exporting server(by java). I want to write below maven command line in build.xml file of my project. Not run from cmd.
$ cd highcharts-export/
$ mvn install
How should I do that in build.xml file?
I wrote following in build.xml file and run by ANT. But nothing happens. And idea?
<target name="buildHighchartsExporting" description="Builds highcharts exporting">
<exec dir="${basedir}/highcharts-export" executable="cmd">
<arg value="mvn" />
<arg line="-f highcharts-export/pom.xml install" />
</exec>
<target name="buildWarFile" description="Builds highcharts exporting War">
<exec dir="${basedir}/highcharts-export/highcharts-export-web" executable="cmd">
<arg value="mvn" />
<arg line="clean package" />
</exec>
If you are just trying to execute a project where the pom.xml is at another folder, you can use the -f parameter:
6.1.6. Using a Custom POM or Custom Settings File
If you don’t like the pom.xml file name, the location of your user-specific Maven
settings, or the default location of your global settings file, you
can customize any of these things with the following options:
-f, --file <file>
Forces the use of an alternate POM file
This way, from where you'd execute:
$ cd highcharts-export/
$ mvn install
You can just use:
$ mvn -f highcharts-export/pom.xml install
Running mvn from an ANT build.xml file
You can use the Ant Exec Task:
<target name="buildProject" description="Builds the project">
<exec dir="${source.dir}\${projectName}" executable="cmd">
<arg value="mvn" />
<arg line="-f highcharts-export/pom.xml install" />
</exec>
</target>
Or, more specifically (to your example):
<target name="buildWarFile" description="Builds highcharts exporting War">
<exec dir="${basedir}/highcharts-export" executable="cmd">
<arg value="mvn" />
<arg line="clean package" />
</exec>
I am dealing with a relatively large project, and up until this point building has been done in a NAnt build script. Recently a small portion of development was done in ruby, and is built using a rake file. I would like to create a NAnt target that will call the rakefile. Current set-up in the NAnt build: (Note that the rakefile is in a different directory from the NAnt script)
<property overwrite="false" name="project.rootdirectory" value="${project::get-base-directory()}" />
<property overwrite="false" name="rake.exe" value="rake.bat" />
<target name="callrake">
<exec program="${rake.exe}" verbose="true">
<arg value="build:foo" />
<arg line="-f ${project.rootdirectory}/../pathtorakefile" />
</exec>
</target>
The error that I recieve when I run nant callrake is:
[exec] ruby.exe: No such file or directory -- c:/pathtoNAntscript/rake (LoadError)
c:/pathtoNAntscript/NAntscript.build
External Program Failed: rake.bat (return code was 1)
Ruby and rake are installed, and the Ruby bin is in the path variable. Not sure why NAnt cant seem to call rake.
This issue is solved by calling cmd.exe and passing it the rake command as text:
<exec program="cmd.exe" verbose="true">
<arg line="/c ${rake.exe} build:foo" />
<arg line="-f ${project.rootdirectory}/../pathtorakefile/Rakefile.rb" />
</exec>
I'm currently looking at TeamCity and how to get our Ruby tests running. I can run the tests just fine when using the Command line or Rake builders. The question I'm trying to solve right now is two fold:
In one of my previous jobs, we also relied on TeamCity to run our .NET tests. We used Nant for this and we had means of tracking the amount of queries that were ran during tests as well as the average execution time for these queries.
I'm trying to do the same right now with my Ruby project. So the first logical step I want to tackle is, How do I run for example RSpec or Cucumber tests using Ant?
I tried looking at Ant itself and grasp it a little bit, but all the examples I find are for jRuby, which we don't use. We rely on RVM and a normal Ruby installation.
The second part of the question is, How can I track the amount of queries ran and their execution time? I'm guessing there is probably a gem for it or some sort of global variable to track. Would love to output this information back to TeamCity somehow.
EDIT
Ok, so I managed to get things running with Ant for my TeamCity server.
This is the XML i'm using atm:
<?xml version="1.0"?>
<project name="rubycas" default="init">
<description>
This buildfile is used to build the RubyCAS project under TeamCity and run the required tasks to validated
whether the project is stable and fully functional.
</description>
<property name="test_type" value="cucumber" />
<target name="init">
<echo message="##teamcity[testStarted name='Rubycas']" />
<condition property="cucumberBool">
<equals arg1="${test_type}" arg2="cucumber" />
</condition>
<condition property="rspecBool">
<equals arg1="${test_type}" arg2="rspec" />
</condition>
</target>
<target name="rspec" if="rspecBool" depends="init">
<exec executable="rspec" outputproperty="result">
<arg value="--require teamcity/spec/runner/formatter/teamcity/formatter" /> <arg value="--format Spec::Runner::Formatter::TeamcityFormatter" />
</exec>
<echo message="${result}" />
</target>
<target name="cucumber" if="cucumberBool" depends="init">
<exec executable="cucumber" outputproperty="result">
<arg value="--format junit" />
<arg value="--out results" />
<arg value="features" />
</exec>
<echo message="${result}" />
</target>
</project>
Problem now is, I cannot get the output from RSpec into TeamCity to recognize the tests.
You can use ant's exec task to run arbitrary system calls, which in your case might be rspec:
https://ant.apache.org/manual/Tasks/exec.html
Something along the lines of
<target name="rspec">
<exec executable="rake">
<arg value="spec"/>
</exec>
</target>
I don't know if your tracking stuff will work with this though, because it's really executing the commands outside of ant.
Is it possible to use Maven deploy:deploy-file or similar to deploy your main src jar snapshot and the test src jar snapshot to Archiva so that it results in a single entry?
Currently I have an Ant project which has jars I want publishing to Archiva and here is how I am doing it:
<!--Main Src Jar-->
<exec executable="${maven.bin}" dir="../lib">
<arg value="deploy:deploy-file" />
<arg value="-DgroupId=com.xxx.gt" />
<arg value="-DartifactId=${ant.project.name}" />
<arg value="-Dversion=${manifest.implementation.version}-SNAPSHOT" />
<arg value="-Dpackaging=jar" />
<arg value="-Dfile=../lib/${ant.project.name}-${manifest.implementation.version}-SNAPSHOT.jar" />
<arg value="-Durl=http://archiva.xxx.com/archiva/repository/snapshots" />
<arg value="-DrepositoryId=snapshots" />
</exec>
<!--Test Src Jar-->
<exec executable="${maven.bin}" dir="../lib">
<arg value="deploy:deploy-file" />
<arg value="-DgroupId=com.xxx.gt" />
<arg value="-DartifactId=${ant.project.name}" />
<arg value="-Dversion=${manifest.implementation.version}-SNAPSHOT" />
<arg value="-Dpackaging=jar" />
<arg value="-Dfile=../lib/${ant.project.name}-${manifest.implementation.version}-SNAPSHOT-tests.jar" />
<arg value="-Durl=http://archiva.xxx.com/archiva/repository/snapshots" />
<arg value="-DrepositoryId=snapshots" />
<arg value="-Dclassifier=tests" />
</exec>
The above Ant script will result in two snapshots on Archiva, 1 with the main src jar and the other with the test src jar.
Using mvn deploy on a typical Maven project will group the artifacts together.
Non Grouped Archiva Image
Has a sanpshot entry per deploy:deploy-file command
Grouped Archiva Image
Has a single sanpshot entry grouping src and tests jars.
Here's my earlier post which will help explain how I got to this point.
If anyone knows how to solve this I'd appreciate it.
Thank You
I think that the maven-deploy-plugin has evolved a lot. Right now it is possible to deploy multiple files within a single execution. See http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploying-with-classifiers.html for the description.