是否可以从build.xml中将jar文件添加到ant类路径?

时间:2012-08-07 13:53:36

标签: ant pmd

我想将PMD jar添加到ant构建中,但我想在jar中检查源代码控制,以便其他开发人员不必修改他们的环境。因此,复制到ant lib文件夹不是理想的情况。有没有其他方法将该jar文件添加到ant classpath?

1 个答案:

答案 0 :(得分:1)

我不喜欢在源代码修订系统中管理存储jar。我理解为什么,但SCM系统不适合存储大型二进制对象。

以下是一些使您的构建可跨机器重复的替代选项:

选项1:创建“bootstrap”目标

使用ANT get task将PMD jar下载到ANT可访问的目录,即$ HOME / .ant / lib:

<target name="bootstrap" description="Install jars required by build">
    <mkdir dir="${user.home}/.ant/lib"/>
    <get src="http://search.maven.org/remotecontent?filepath=pmd/pmd/4.3/pmd-4.3.jar" dest="${user.home}/.ant/lib/pmd.jar"/>
</target>

选项2:使用依赖关系管理

Ivy可用于管理所有构建的依赖项(类似于Maven)

使用常春藤的优点是它可用于管理所有构建类路径(使用配置):

<target name="resolve" description="Use ivy to resolve classpaths">
    <ivy:resolve/>

    <ivy:cachepath pathid="compile.path" conf="compile"/>
    <ivy:cachepath pathid="build.path" conf="build"/>
</target>

然后,名为 ivy.xml 的文件将列出项目的依赖项

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>

    <configurations>
        <conf name="compile" description="Required to compile application"/>
        <conf name="build"   description="Required by the ANT build"/>
    </configurations>

    <dependencies>
        <!-- compile dependencies -->
        <dependency org="org.slf4j" name="slf4j-api" rev="1.6.4" conf="compile->default"/>

        <!-- build dependencies -->
        <dependency org="pmd" name="pmd" rev="4.3" conf="build->default"/>    
    </dependencies>

</ivy-module>

此选项看起来更复杂,但可用于管理所有第三方广告。它还有一个好处,就是了解jar可能对其他jar有传递的依赖关系。

选项3:声纳

我不知道您是否听说过Sonar项目?

可以使用选项1或2安装单个jar文件,这将自动下载以下分析工具所需的jar文件:

  • PMD
  • FindBugs的
  • Checkstyle的

值得调查!