Knowledge Base > DCover CLI > Passing the classpath

How to pass the classpath from Maven or Gradle to the CLI

Generating the classpath from Maven

Diffblue Cover CLI will automatically detect and use the classpath for a Maven project if one is not provided by the user. If you wish to supply your own classpath to dcover, follow these instructions.

While there is more than one way to generate the project’s full classpath (including dependencies) from Maven, one example is as follows:

When compiling the project, the output from Maven should have indicated where the project’s class files were written to. This is typically at target/classes within the directory containing the project’s pom.xml file.

Next, run the mvn dependency:build-classpath command from the directory containing the pom.xml file for the module you wish to build.

This will print out a classpath, prefixed by Dependencies classpath.

Append the target/classes folder (or equivalent) as the first entry to the dependencies classpath: /home/myUser/myProject/target/classes:... (where ... represents the contents of the above dependencies classpath)

Generating the classpath from Gradle

While there is more than one way to generate a project’s full classpath (including dependencies) from Gradle, one example is as follows:

Append the following task at the end of your project’s (or module’s) build.gradle file (works on Gradle 6.3 and above):

task printClasspath {
    doLast {
        println "Test classpath = ${sourceSets.test.runtimeClasspath.asPath}";
    }
}

Execute the task by running gradle printClasspath (or ./gradlew printClasspath / gradlew.bat printClasspath if your project uses a Gradle Wrapper).

This will print out the full classpath used to run your tests, prefixed by Test classpath =.

For example:

$ gradle printClasspath

> Configure project :micro-core
Test classpath = /home/myUser/projects/gradle/sample-boot-micro/micro-core/build/classes/java
/test:/home/myUser/projects/gradle/sample-boot-micro/micro-core/build/classes/java/main:/home
/myUser/.gradle/caches/modules-2/files-2.1/com.h2database/h2/1.4.199/7bf08152984ed8859740ae3f
97fae6c72771ae45/h2-1.4.199.jar

BUILD SUCCESSFUL in 752ms

Adding a JUnit dependency

Diffblue Cover CLI requires a JUnit dependency to be passed in before it can generate and verify (compile and run) unit tests. Add this dependency to the end of your classpath.

This can be found by searching the following directories in the user’s home folder for a JUnit JAR file:

.m2/repository (Maven)

.gradle/caches (Gradle)

Passing the classpath to the CLI

Once the full classpath has been generated, it can be passed to the CLI via the -cp argument:

-cp "/home/myUser/myProject/target/classes:...".