Dave
Dave

Reputation: 19150

Can I configure Maven to ignore "test" scoped dependencies if I'm skipping running tests?

I’m using Maven 3.2.2. In one of my child modules, I have this dependency …

    <dependency>
        <groupId>org.mainco.subco</groupId>
        <artifactId>core</artifactId>
        <version>${project.parent.version}</version>
        <type>test-jar</type>
        <scope>test</scope>
    </dependency>

Is there a way to get Maven to ignore this dependency when running my release plugin if I specify “-DskipTests” (or some other skip test option)? Here are my release plugin goals …

-Darguments="-DskipTests -P prod -Dcloudbees" -Dresume=false release:prepare release:perform

I realize that I could work on the problem of getting that dependency built and ready to go, but this question specifically deals with Maven ignoring dependencies scoped as “test” when I do not intend to run any tests.

Thanks, - Dave

Upvotes: 4

Views: 3149

Answers (1)

Robert Scholte
Robert Scholte

Reputation: 12345

Before Maven starts executing the goals, it creates a buildplan. It'll go through all dependencies, no matter the scope. However, you can trick it with a profile triggered by a property. Be aware, profiles are often used for the wrong reasons (I noticed the prod-profile, that's such an example: configuration doesn't belong in the artifact. That's another discussion and there are enough threads about it).

In this case:

<profile>
  <activation>
    <property>skipTests</property>
    <value>!true<property>
  </activation>
  <dependencies>
  <!-- your test-scoped dependency -->
  </dependencies>
</profile>

So yes it can, but it is probably better to have this dependency available. If someone else checks out this code and tries to build it, it'll fail by default, right? That's not what users expect.

Upvotes: 3

Related Questions