Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping Maven Test Dependency

I am working on a project that use maven for building. What I am trying to do is to skip the test dependency. Basically running the maven build without the presence of artifact in my maven repository.

eg

<artifactId>example</artifactId>
<scope>test</scope>

This is from the pom file of my project and I have to maven build my project without having artifact example.

I have searched for solution such as use "-DskipTests=true" or "-Dmaven.test.skip=true". In my case they did skip the running of the tests but it still complains missing dependency file.

Does anyone know a way to run maven build without having to have test artifact in the maven repository?

Thanks.

like image 515
BiGzZ Avatar asked Nov 02 '11 18:11

BiGzZ


1 Answers

See https://issues.apache.org/jira/browse/MNG-4192. I think the only way around it is to move the test-scoped dependency into a Maven profile.

Here is an example:

    <profile>
      <id>test-with-extra-dependency</id>
      <dependencies>
        <dependency>
          <groupId>org.example.groupid</groupId>
          <artifactId>artifact-id</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>

You should now be able to run a build without tests:

mvn clean install -Dmaven.test.skip=true -DskipTests=true

After that you can run the tests with the profile enabled:

mvn test --activate-profiles test-with-extra-dependency

I wouldn't advise it, but this can be useful in case of a circular dependency between the current module and the test dependency, i.e. you can build the module, then build the test dependency using the build result, and finally test the module with the test dependency. If you find yourself wanting to do that, please try to restructure your project to eliminate the circular dependency (eg by moving the tests to a third module).

like image 75
seanf Avatar answered Oct 04 '22 04:10

seanf