Search code examples
mavenantarchiva

catch failure with failonerror=false for <artifact:dependencies


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


Solution

  • 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>