I am using maven-ant-tasks-2.1.3 to pull dependencies from an Archiva repository.I get a failure when doing a re-deploy of a release to Archiva using existing Ant scripts.I cannot use Maven directly. I want to catch the failure and not cause a build failure.I have a property file for the variable values like groupId.
I tried to pull the dependency and it fails if it doesn't exist.
<artifact:dependencies filesetId="dependency.fileset" >
<remoteRepository id="central" url="http://mvn-repo....../archiva/repository/internal/"/>
<dependency
groupId="${groupId}"
artifactId="${artifactId}"
version="${version}"
/>
</artifact:dependencies>
I also get a failure when re-deploying an artifact to Archiva repo.
<target name="deploy-to-maven">
<artifact:install-provider artifactId="wagon-webdav" version="1.0-beta-2"/>
<artifact:pom id="deploypom" file="${basedir}/pom-entity.xml" />
<artifact:deploy file="${unzip.dir}/${target.jar.name}.jar">
<remoteRepository url="dav:${repository-uri}">
<authentication username="${repository.username}" password="${repository.password}"/>
</remoteRepository>
<pom refid="deploypom"/>
</artifact:deploy>
</target>
I was hoping to check if the file exists and then set an available property to false if it doesn't exist.Then i could check that property with target deploy-to-maven.
Thanks in advance for any tips,
Vijay
This sounds like a good time to use ant-contrib's trycatch task:
<trycatch>
<try>
<artifact:dependencies filesetId="dependency.fileset">
<remoteRepository id="central" url="http://mvn-repo....../archiva/repository/internal/" />
<dependency
groupId="${groupId}"
artifactId="${artifactId}"
version="${version}"
/>
</artifact:dependencies>
<property name="dependency.exists" value="true" />
</try>
<catch>
<echo message="Dependency cannot be resolved." />
<property name="dependency.exists" value="false" />
</catch>
</trycatch>
Related
I have written ant build script to run sonar. But, am getting below issue while building:
Error Message :
BUILD FAILED
C:\sonar\workspace\Sample\build.xml:12: Problem: failed to create task or type sonar
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
build.xml:
<project name="SampleSonar" default="sonar" basedir=".">
<target name="cleanclasses">
<javac srcdir="src" destdir="bin/temp" classpath="" debug="on"/>
</target>
<target name="sonar" depends="cleanclasses">
<!-- Add the Sonar task -->
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="C:\apache-ant-1.7.1\lib\sonar-ant-task-2.2.jar" />
</taskdef>
<sonar>
<property name="sonar.sources" value="src" />
<property name="sonar.projectKey" value="Sample" />
<property name="sonar.projectName" value="Sonarqube Sample Project" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.language" value="java" />
<property name="sonar.sources" value="src" />
<property name="sonar.sourceEncoding" value="UTF-8" />
<property name="sonar.host.url" value="http://localhost:9000" />
<property name="temp.dir" value="/src/temp" />
</sonar>
</target>
</project>
I am using :
java: 1.6
sonar ant task : 2.2
sonarqube : 4 ant : 1.7.1
How can I create ant task to run sonar ?
According to documentation, task is <sonar:sonar> but not <sonar>.
There are two errors in your script which can be solved as following:
add a namespace to the sonar task (e.g. ´sonarns´ or just ´sonar´)
define the ant properties outside the the sonar task tag
Your sonar target should look like that:
<target name="sonar" depends="cleanclasses">
<!-- Add the Sonar task -->
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="C:\apache-ant-1.7.1\lib\sonar-ant-task-2.2.jar" />
</taskdef>
<property name="sonar.sources" value="src" />
<property name="sonar.projectKey" value="Sample" />
...
<sonarns:sonar xmlns:sonarns="antlib:org.sonar.ant" />
</target>
I have the following ant project settings for sonar:
<!-- list of Sonar project related properties -->
<property name="sonar.projectName" value="bla bla" />
<property name="sonar.projectKey" value="com.my.project" />
<property name="sonar.projectVersion" value="7.3" />
<property name="sonar.language" value="java" />
<property name="sonar.modules" value="admin-api" />
<!-- all of the sub-modules -->
<property name="admin-api.sonar.projectName" value="admin-api" />
<property name="admin-api.sonar.projectBaseDir" location="server/admin/admin-api"/>
<property name="admin-api.sonar.sources" value="src" />
<property name="admin-api.sonar.binaries" value="build" />
<sonar:sonar xmlns:sonar="antlib:org.sonar.ant">
<!-- path to libraries (optional). These libraries are for example used by the Java Findbugs plugin -->
<libraries>
<path>
<fileset dir="server/third-party-jars" includes="*.jar" />
</path>
</libraries>
</sonar:sonar>
I am getting 1 warning :
[sonar:sonar] *****************************************************************************************************************************************
[sonar:sonar] /!\ Sonar Ant Task running in compatibility mode: please refer to the documentation to udpate your scripts to comply with the standards.
[sonar:sonar] *****************************************************************************************************************************************
And also The following error:
The following mandatory information is missing:
- task attribute 'key'
- task attribute 'version'
I understand that there were changes migrating to the new sonar ant task 2.0 but couldn't find any place where the changes were specified.
Also, I understand that all of the modules settings now have to be specified in the parent build.xml only and not in the sub-modules build.xml files. So why do I get the errors ? I followed the example in https://github.com/SonarSource/sonar-examples/tree/master/projects/multi-module/ant . Am I missing something ?
Thanks
You're in the compatibility mode because you have defined "libraries" inside the "sonar:sonar" tag. Instead, you should define "sonar.libraries" outside of this tag, by joining all the JAR file paths with a comma.
Then the multi-module mechanism will work as expected.
I am facing the same issue. In my case, the build.xml looks like belows:
<target depends="build" name="sonar-runner">
<!-- Define the SonarQube properties -->
<property name="sonar.host.url" value="http://sonar-server:9000/sonar" />
<property name="sonar.jdbc.url" value="jdbc:jtds:sqlserver://comp-sql-db-server/sonar;SelectMethod=Cursor" />
<property name="sonar.jdbc.username" value="XXXXXX" />
<property name="sonar.jdbc.password" value="*******" />
<property name="sonar.projectKey" value="asdfsaf:2550" />
<property name="sonar.projectName" value="Proj 1" />
<property name="sonar.projectVersion" value="4.0.1" />
<property name="sonar.language" value="java" />
<property name="sonar.profile" value="Sonar Way" />
<property name="sonar.sources" value="src" />
<property name="sonar.sourceEncoding" value="UTF-8" />
<!-- run sonar for this project -->
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonar-ant-task-*.jar" file
in your "$HOME/.ant/lib" folder -->
<classpath path="${lib-dist}/sonar/sonar-ant-task-2.1.jar" />
</taskdef>
<!-- Execute Sonar -->
<sonar:sonar />
</target>
This means that I have setup ant for single project but don't know why its requiring for Key and Version even its defined in properties even I didn't provide any thing inside the sonar:sonar tag.
Thanks
I have a multi module project (with many sub-modules) defined in Sonar and it was working great until i've upgraded sonar to the newer version.
My previous settings were:
a single parent build.xml that contain all of the general project properties like jdbc connection etc. Also it contained the <sonar:sonar /> task to run Sonar. This parent project does not contain any source / binaries, just the instruction to build the sub-modules.
many sub-modules build.xml files that contained only the sub-module specific properties like sonar.projectKey, sonar.sources and sonar.binaries
Now in the new Sonar ant task I need to define everything in the parent buid.xml. I have defined it in the following way (I only show one sub-module here, I assume it should work the same if I add more modules later) :
<target name="sonar">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<classpath path="build-utils/lib/sonar-ant-task-2.0.jar" />
</taskdef>
<!-- list of Sonar database related properties -->
<property name="sonar.jdbc.url" value="jdbc:oracle:thin:#localhost/DB11g" />
<property name="sonar.jdbc.driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<!-- for security reasons, pass these parameters from outside -->
<property name="sonar.jdbc.username" value="" />
<property name="sonar.jdbc.password" value="" />
<property name="sonar.host.url" value="http://localhost:9000" />
<!-- list of Sonar project related properties -->
<property name="sonar.projectName" value="My Project" />
<property name="sonar.projectKey" value="com.my.project" />
<property name="sonar.projectVersion" value="7.3" />
<property name="sonar.language" value="java" />
<property name="sonar.libraries" value="server/third-party-jars"/>
<property name="sonar.modules" value="admin-api" />
<!-- all of the sub-modules -->
<property name="admin-api.sonar.projectName" value="admin-api" />
<property name="admin-api.sonar.projectBaseDir" location="server/admin/admin-api"/>
<property name="admin-api.sonar.sources" value="src" />
<property name="admin-api.sonar.binaries" value="build" />
<sonar:sonar xmlns:sonar="antlib:org.sonar.ant" />
</target>
When I run the target I get the following error:
You must define the following mandatory properties for 'com.orca.rightv': sonar.sources
Another question, is there any way to keep the specific definition of the sub-modules in each module's build.xml like I did in the previous version ? That would save me a lot of work.
Thanks
There's a bug in the current version of the Ant Task, which is related to the version of the Sonar Runner API embedded. This will be fixed in the next version: http://jira.codehaus.org/browse/SONARPLUGINS-2818
Meanwhile, you can define "sonar.sources" at the top, its value will be inherited in to modules (and obviously you can still override it in modules).
As for the definition of properties at module level, you can define those properties in a "sonar-project.properties" file that you put at the root of the module, like:
sonar.projectName=My Project
# following needed only to override the values defined in top build.xml
sonar.sources=src
sonar.binaries=build
, and just leave "admin-api.sonar.projectBaseDir" property (like you did) in the top build.xml file.
(I hope I phrased the title correctly!)
I have an ant buildfile which is referencing a maven pom like so:
<artifact:dependencies filesetId="dependency.fileset" useScope="compile">
<pom file="pom.xml"/>
</artifact:dependencies>
<copy todir="${jar.location}">
<fileset refid="dependency.fileset" />
<mapper type="flatten" />
</copy>
In pom.xml, some of the dependencies use a property in place of a hard-coded version number. But the copy task doesn't seem to resolve that property - it's trying to use "jarname-{app.version}" literally. I tried setting the value for "app.version" somewhere in the buildfile, to no effect. What am I doing wrong??
Thanks for any input!
As stated on the maven site, you should use artifact:pom to get that info:
<artifact:pom id="mypom" file="pom.xml" />
<artifact:dependencies filesetId="dependency.fileset" useScope="compile" pomRefId="mypom" />
If you have profiles to process:
<artifact:pom id="maven.project" file="pom.xml">
<profile id="my-profile"/>
</artifact:pom>
Im using eclipse and maven for my day to day development, which works fine. However I need a specialized war created when its time to export to send over to production, which includes things like minifying and combining js/css etc, separating out static resources for apache rather than tomcat etc.
I tried the maven plugin route but it was a hassle, I'd rather write a simply ant script to export when necessary. I'm using the ant war task, but the exported war contains everything except my WEB-INF/libs folder, which is blank. Does anyone know a way to make the script work with all the libs that maven looks up? This is what I have:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="war" basedir=".">
<property name="builder" value="Me" />
<property name="project-name" value="${ant.project.name}" />
<property name="war-file-name" value="${project-name}.war" />
<property name="source-directory" value="src/main/java" />
<property name="classes-directory" value="target/classes" />
<property name="web-directory" value="src/main/webapp" />
<property name="web-xml-file" value="src/main/webapp/WEB-INF/web.xml" />
<property name="build-directory" value="/" />
<tstamp prefix="build-info">
<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
</tstamp>
<target name="war" depends="">
<mkdir dir="${build-directory}" />
<delete file="${build-directory}/${war-file-name}" />
<war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
<classes dir="${classes-directory}" />
<fileset dir="${web-directory}">
<exclude name="WEB-INF/web.xml" />
</fileset>
<manifest>
<attribute name="Built-By" value="${builder}" />
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>
</project>
You can use maven ant tasks for this. I have not tried this, but from the examples, something like this should work...
<artifact:dependencies filesetId="dependency.fileset" useScope="runtime">
<pom file="pom.xml"/>
</artifact:dependencies>
<copy todir="${webapp.output}/WEB-INF/lib">
<fileset refid="dependency.fileset" />
<!-- This mapper strips off all leading directory information -->
<mapper type="flatten" />
</copy>