首页 > 解决方案 > JUnit jar 文件的 GitHub 位置

问题描述

警告:第一个问题

我是 GitHub 的新手,正在尝试编写一个 ant 操作来编译一个简单的项目(Java)并编译和运行一个简单的测试包(使用 junit-4.1.2 和 Hamcrest-core-1.3)。我在这个问题中省略了项目代码,因为我认为它是不相关的。但是,如果您需要它,请发表评论,我将编辑问题或使 github 存储库可用。

我遵循了编写 build.xml 文件入门指南 - Ant的教程,并创建了以下 build.xml 文件:

<project name="EconomyBot" default="test" basedir=".">

<property name="build.dir" location="build"/>
<property name="src.dir" location="src"/>
<property name="bin.dir" location="bin"/>
<property name="testsrc.dir" location="test"/>

<path id="classpath">
    <pathelement location="lib/junit-4.12.jar"/>
    <pathelement location="lib/hamcrest-core-1.3.jar"/>
</path>

<target name="init">
    <tstamp />
    <mkdir dir="${bin.dir}" />
</target>

<target name="clean" description="remove intermediate files">
    <delete dir="${bin.dir}" />
</target>

<target name="compile" depends="init" description="compile the source ">
    <mkdir dir="${build.dir}"/>
    <javac srcdir="${src.dir}" destdir="${bin.dir}"  classpathref="classpath" includeantruntime="true"/>
</target>

<target name="test-compile" depends="compile">
    <javac srcdir="${testsrc.dir}" destdir="${build.dir}" classpathref="classpath" includeantruntime="false"/>
</target>

<target name="test" depends="test-compile">
    <junit printsummary="on" haltonfailure="yes" fork="true">
        <classpath>
            <path refid="classpath"/>
            <pathelement location="${build.dir}"/>
        </classpath>
        <formatter type="brief" usefile="false" />
        <batchtest>
            <fileset dir="${testsrc.dir}" includes="**/*Test.java" />
        </batchtest>
    </junit>
</target>

</project>

回购结构(或重要位)如下:

project
--> lib
--> src
--> test
--> build.xml
--> project.iml

问题

现在,ant build 根据需要编译并运行测试。但问题是:

为了让它工作,hamcrest-core-1.3.jar 和 junit-4.12.jar 需要在 repo 旁边。我知道 ant 构建需要它来运行测试,但我不喜欢在项目 repo 中使用它。我知道我告诉 ant 在 repo 的 lib 文件夹中查找它:

<path id="classpath">
    <pathelement location="lib/junit-4.12.jar"/>
    <pathelement location="lib/hamcrest-core-1.3.jar"/>
</path>

我可以把它放在另一个地方吗,这样做的正确方法是什么。如果它在我的本地机器上,我可以简单地为全局 libs 文件夹创建一个环境变量,以否定必须在每个项目中拥有这些 .jar 文件,如果在 github 上有类似的东西?

顺便说一句,冒着被标记为一般风险的风险,我将不胜感激任何可以改进我的 build.xml 文件的方法。

标签: javagithubantjunit4hamcrest

解决方案


推荐阅读