0

is there a way where i can pass a command switch to change my dependencies?

meaning, i have

<dependency>
            <groupId>api</groupId>
            <artifactId>api</artifactId>
            <version>0.0.1-SNAPSHOT</version>

        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>

        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>

        </dependency>

and set it up in such a way where if i do

mvn package -Dprovided

my effective POM would be

<dependency>
            <groupId>nmsc</groupId>
            <artifactId>nmsc_api</artifactId>
            <version>0.0.1-SNAPSHOT</version>

        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <scope>provided</scope>
        </dependency>

without using profiles as profiles require me to put the dependencies in twice. is this possible?

scphantm
  • 4,293
  • 8
  • 43
  • 77

1 Answers1

2

Using profiles doesn't require you to list the dependencies multiple times if you pair it with variables, though if you're just doing that for a single property, then maybe you should just override a property directly:

<properties>
    <myExeScope>compile<myExeScope>
</properties>

<dependencies>
    <dependency>
        <groupId>nmsc</groupId>
        <artifactId>nmsc_api</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <scope>${myExeScope}</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <scope>${myExeScope}</scope>
    </dependency>
</dependencies>

Then you should be able to override the scope of the specified dependencies:

mvn -DmyExeScope=provided

Note, I haven't compiled this, so if there are typos please correct them and note the correction.

Jared
  • 1,887
  • 3
  • 20
  • 45