为什么我的第二堂课没有看到其他模块的课?

时间:2019-03-23 21:35:43

标签: ant ivy

我最近与Ant + Ivy合作,并且有这样一个问题。我有两个模块:module1 -> module2。在module2测试中,我使用module1中的类。实际上在module1中的测试已成功通过。我不明白为什么测试是我的module2失败了,因为我已经通过ivy依赖项导入了module1,但是却出现了如下错误:

C:\builders\builders\src\test\java\com\builders\module2\Module2Test.java:3: error: package com.builders.module1 does not exist
    [javac] import com.builders.module1.Module1;

这是我的module2 / ivy.xml:

<ivy-module version="1.0">
    <info organisation="com.builders"
          module="module2"
          status="integration"/>

    <dependencies>
        <dependency org="junit" name="junit" rev="4.12"/>
        <dependency name="module1" rev="latest.integration"/>
    </dependencies>
</ivy-module>

我的build.xml

<project name="common" xmlns:ivy="antlib:org.apache.ivy.ant">

    <property file="${common.dir}/build.properties"/>

    <property name="ivy.jar.dir" value="${user.home}/.ivy2/jars"/>
    <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>

    <target name="load-ivy">
        <path id="ivy.lib.path">
            <pathelement location="${ivy.jar.file}"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml"
                 uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
    </target>

    <path id="lib.path.id">
        <fileset dir="${lib.dir}"/>
    </path>

    <path id="classpath.test">
        <pathelement location="lib/junit-jar-4.12.jar"/>
        <pathelement location="lib/hamcrest-core-jar-1.3.jar"/>
        <pathelement location="${classes.dir}"/>
    </path>

    <property name="ivy.local.default.root" value="${repository.dir}/local"/>
    <property name="ivy.shared.default.root" value="${repository.dir}/shared"/>


    <target name="resolve" depends="clean-lib, load-ivy" description="--> resolve and retrieve dependencies with ivy">
        <mkdir dir="${lib.dir}"/>
        <ivy:resolve file="${ivy.file}"/>
        <ivy:retrieve pattern="${lib.dir}/[artifact]-[type]-[revision].[ext]"/>
    </target>

    <target name="compile" depends="resolve" description="--> compile the project">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="lib.path.id" debug="true" includeAntRuntime="false"/>
    </target>

    <target name="ivy-new-version" depends="load-ivy" unless="ivy.new.revision">
        <property name="module.version.prefix" value="${module.version.target}-dev-b"/>
        <ivy:info file="${ivy.file}"/>
        <ivy:buildnumber organisation="${ivy.organisation}" module="${ivy.module}"
                revision="${module.version.prefix}" defaultBuildNumber="1" revSep=""/>
    </target>

    <target name="version" depends="ivy-new-version">
        <mkdir dir="${classes.dir}"/>
        <echo message="version=${ivy.new.revision}" file="${classes.dir}/${ant.project.name}.properties" append="false"/>
        <property file="${classes.dir}/${ant.project.name}.properties"/>
    </target>

    <target name="publish" depends="clean-build, jar, test-compile" description="--> publish this project in the ivy repository">
        <ivy:publish artifactspattern="${build.dir}/[artifact].[ext]"
                     resolver="shared"
                     pubrevision="1.0"
                     status="release"/>
    </target>

    <target name="test-compile">
        <mkdir dir="${test.build.dir}"/>
        <javac srcdir="${test.src.dir}" destdir="${test.build.dir}" includeantruntime="false">
            <classpath>
                <path refid="classpath.test"/>
                <pathelement location="${lib.dir}"/>
            </classpath>
        </javac>
    </target>

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

    <target name="clean-build" description="--> clean the project built files">
        <delete includeemptydirs="true" dir="${build.dir}"/>
    </target>

    <target name="clean-lib" description="--> clean the project libraries directory (dependencies)">
        <delete includeemptydirs="true" dir="${lib.dir}"/>
    </target>

    <target name="clean-repository">
        <delete includeemptydirs="true" dir="${repository.dir}"/>
    </target>

    <target name="clean" depends="clean-build, clean-lib, clean-repository" description="--> clean the project"/>
</project>

我想念什么?如何改善?

0 个答案:

没有答案