蚂蚁在构建时下载一个罐子 [英] Ant Download a Jar at Build

查看:69
本文介绍了蚂蚁在构建时下载一个罐子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将forbiddenapis检查集成到我的项目中.我已经定义了:

I'm trying to integrate forbiddenapis check into my project. I've defined that:

<target name="forbidden-checks" depends="clean, runtime, test">
  <ivy:cachepath organisation="de.thetaphi" module="forbiddenapis" revision="2.2" inline="true" pathid="classpath"/>
  <taskdef uri="antlib:de.thetaphi.forbiddenapis" classpathref="classpath"/>
  <forbiddenapis classpathref="all-lib-classpath" dir="${build.dir}" targetVersion="${javac.version}">
    <bundledsignatures name="jdk-unsafe"/>
    <bundledsignatures name="jdk-deprecated"/>
    <bundledsignatures name="jdk-non-portable"/>
  </forbiddenapis>
</target>

all-lib-classpath包括由bidbiddenapis插件检查的所有文件.我认为forbiddenapis jar将放入${build.dir}.但是我得到了这个错误:

all-lib-classpath includes all files to be checked by forbiddenapis plugin. I think that forbiddenapis jar will go into ${build.dir}. However I get that error:

Problem: failed to create task or type forbiddenapis
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

推荐答案

文件不会下载到您的工作区中. cachpath 任务将做两件事,即下载和缓存将jar放入默认目录〜/.ivy2/cache",然后基于这些缓存的jar创建一个Ant路径.

The files don't get downloaded into your workspace. The cachpath task will do two things, download and cache jars into the default directory "~/.ivy2/cache" and then create an Ant path based on those cached jars.

第二,正如@Denis Kurochkin指出的那样,您正在使用的任务显然需要声明一个名称空间,这在现代Ant任务中并不罕见.

Secondly, as @Denis Kurochkin pointed out, the task you're using apparently requires a namespace to be declared, not unusual with modern Ant tasks.

最后,我忍不住要演示如何配置ANT构建以在缺少常春藤jar的情况下安装它,从而使构建更加独立.

Finally I couldn't resist demonstrating how you can also configure your ANT build to install the ivy jar if it is missing, making your build even more stand-alone.

<project name="demo" default="forbidden-checks" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:fa="antlib:de.thetaphi.forbiddenapis">

  <available classname="org.apache.ivy.Main" property="ivy.installed"/>

  <target name="resolve" depends="install-ivy">
    <ivy:cachepath pathid="classpath">
      <dependency org="de.thetaphi" name="forbiddenapis" rev="2.2" />
    </ivy:cachepath>

    <ivy:cachepath pathid="all-lib-classpath">
      <dependency .... />
      <dependency .... />
      <dependency .... />
    </ivy:cachepath>
  </target>

  <target name="forbidden-checks" depends="resolve">

    <taskdef uri="antlib:de.thetaphi.forbiddenapis" classpathref="classpath"/>

    <fa:forbiddenapis classpathref="all-lib-classpath" dir="${build.dir}" targetVersion="${javac.version}">
      <bundledsignatures name="jdk-unsafe"/>
      <bundledsignatures name="jdk-deprecated"/>
      <bundledsignatures name="jdk-non-portable"/>
    </fa:forbiddenapis>
  </target>

  <target name="install-ivy" unless="ivy.installed">
    <mkdir dir="${user.home}/.ant/lib"/>
    <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
    <fail message="Ivy has been installed. Run the build again"/>
  </target>

</project>

这篇关于蚂蚁在构建时下载一个罐子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆