gpt4 book ai didi

java - Ant 在构建时下载一个 Jar

转载 作者:行者123 更新时间:2023-11-30 08:33:51 24 4
gpt4 key购买 nike

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

<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 包括所有要被 forbiddenapis 插件检查的文件。我认为 forbiddenapis jar 将进入 ${build.dir}。但是我得到了那个错误:

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 路径。

其次,正如@Denis Kurochkin 所指出的,您正在使用的任务显然需要声明一个 namespace ,这在现代 Ant 任务中并不罕见。

最后,我忍不住演示了如何配置您的 ANT 构建以在缺少 ivy jar 时安装它,从而使您的构建更加独立。

例子

build.xml

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

关于java - Ant 在构建时下载一个 Jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39207497/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com