Skip to content

Ant task does not use project-relative paths for suppression file and output directory #7918

@ChristopherSchultz

Description

@ChristopherSchultz

When using the ant task with a reportoutputdirectory attribute and a <suppressionfile> child element where the paths are relative to the project root, running the ant task from the same directory as the build.xml file works as expected. However, when running e.g. ant -f /path/to/build.xml dependency-check from another directory, the suppression file is not found (unless fully-qualified from within the build script itself) and the report is written to a directory relative to the CWD of the invocation and not relative to the build.xml file, which is the typical expectation for relative paths in ant build scripts.

Version of dependency-check used
The problem occurs using version 12.1.0 of the Apache ant plugin

Log file
When reporting errors, 99% of the time log file output is required. Please post the log file as a gist and provide a link in the new issue.

To Reproduce
Steps to reproduce the behavior:

  1. Use the following build.xml script in e.g. a temp directory:
<project name="test" default="dependency-check" basedir=".">
  <!-- TODO: Set this path properly -->
  <property name="dependency-check.home" value="${user.home}/packages/dependency-check-ant" />

  <target name="prep">
    <echo file="dependency-check-suppressions.xml">
&lt;suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd"&gt;
&lt;/suppressions&gt;
    </echo>
  </target>

  <target name="dependency-check" depends="prep">
    <path id="dependency-check.path">
      <pathelement location="${dependency-check.home}/dependency-check-ant.jar"/>
      <fileset dir="${dependency-check.home}/lib">
        <include name="*.jar"/>
      </fileset>
    </path>
    <taskdef resource="dependency-check-taskdefs.properties">
      <classpath refid="dependency-check.path" />
    </taskdef>

    <property name="dependency-check.output-dir" value="dep-check-report-dir" />
    <mkdir dir="${dependency-check.output-dir}" />
    <dependency-check projectname="${ant.project.name}" reportoutputdirectory="${dependency-check.output-dir}">
      <suppressionfile path="dependency-check-suppressions.xml" />
      <fileset dir="${dependency-check.home}">
        <include name="**/*.jar"/>
      </fileset>
    </dependency-check>
  </target>
</project>
  1. Customize the value of the dependency-check ant library home
  2. Run ant

This should run successfully, creating a suppression file alongside the build.xml script, creating a directory called dep-check-report-dir, and placing the report in that directory.

  1. cd ..
  2. ant -f temp/build.xml

This will fail because the suppressions file does not exist. It does exist, but it's in the temp directory, alongside the build.xml script. If you fix the reference to the suppression file to be ${basedir}/dependency-check-suppressions.xml", then the script completes, but the report is put into an unexpected place: ./dep-check-report-dirinstead of./temp/dep-check-report-dir`.

Ant's documentation says that any non-absolute path should be relative to the project's basedir, which defaults to the directory containing the build.xml file.

It would be nice for dependency-check to resolve these relative paths in the same way, for consistency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    antchanges to antbug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions