java Ant如果/除非属性问题
预先警告,这是我第一次尝试实际创建ANT构建脚本。我正试图使我的测试目标仅在compiled
属性设置为true时运行,此外,我希望我的距离目标运行,除非junit.failure
属性设置为true。但出于某种原因,下面的代码似乎没有达到我的预期目的;这意味着当我试图运行ant
时,它不会执行测试,因为compiled
没有设置为true(我相信),但如果我查看bin文件夹,我可以看到。类文件确实生成了。因此,这意味着dist也不会运行,因为它取决于编译和测试目标。关于我可能做错了什么有什么想法或想法吗
<project name="project" default="dist" basedir="." xmlns:if="ant:if" xmlns:unless="ant:unless">
<description>
Build file for the project
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="lib" location="lib"/>
<property name="bin" location="bin"/>
<property name="dist" location="dist"/>
<property name="distDirName" value="dist"/>
<!-- including the external jar files -->
<path id="proj.classpath">
<fileset dir="${lib}" includes="*.jar"/>
<pathelement location="${bin}"/>
</path>
<target name="compile" description="compile the source">
<!-- Create the distribution directory -->
<mkdir dir="${bin}"/>
<!-- Compile the java code from ${src} into ${bin} -->
<javac srcdir="${src}" classpathref="proj.classpath" destdir="${bin}"/>
<!-- Set condition for dependent target -->
<condition property="compiled">
<and>
<available file="**/SampleTest.class"/>
<available file="**/DBConnection.class"/>
</and>
</condition>
</target>
<target name="test" depends="compile" if="compiled">
<junit failureproperty="junit.failure" errorproperty="junit.failure" printsummary="withOutAndErr" fork="yes" haltonfailure="true" haltonerror="true">
<formatter type="xml"/>
<test name="this.one.dir.SampleTest" todir="${bin}"/>
<classpath refid="proj.classpath"/>
</junit>
</target>
<target name="dist" depends="compile,test" unless="junit.failure" description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}"/>
<!-- Put everything in ${bin} into the distribution.jar file -->
<jar jarfile="${dist}/distribution.jar" basedir="${basedir}" excludes="**/test/,${distDirName}/**"/>
</target>
</project>
共 (0) 个答案