1

I have been using maven for about two years, but I don't think I understand profiles in maven exactly, especially when I encounter the following problem.

I have a maven project with three modules, secweb-parent, secweb-service and secweb-web, secweb-sevice depends on spring-webmvc, and secweb-web depends on secweb-service.

The problem is :

1) When I use 'mvn clean install -Dinclude', it works well, and spring-mvc.jar will be found in secweb-web.war

2) When I use 'mvn clean install -Pinclude-jar', it doesn't work, and spring-mvc.jar can't be found in secweb-web.war

Anybody know why ? And is there something I must pay attention to when I use profiles ?

(I know I can define scope of dependency, this project here just to demo different result of different profile activate method)


pom.xml for secweb-parent

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <properties>
        <project.version>1.0.0</project.version>
    </properties>

    <groupId>com.mediatek.dt</groupId>
    <artifactId>secweb-parent</artifactId>
    <version>${project.version}</version>
    <packaging>pom</packaging>

    <modules>
        <module>../secweb-web</module>
        <module>../secweb-service</module>
    </modules>
</project>

pom.xml for secweb-service

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.mediatek.dt</groupId>
        <artifactId>secweb-parent</artifactId>
        <version>${project.version}</version>
        <relativePath>../secweb-parent</relativePath>
    </parent>

    <artifactId>secweb-service</artifactId>

    <profiles>
        <profile>
            <id>include-jar</id>
            <activation>
                <property>
                    <name>include</name>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-webmvc</artifactId>
                    <version>2.5</version>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>

pom.xml for secweb-web

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.mediatek.dt</groupId>
        <artifactId>secweb-parent</artifactId>
        <version>${project.version}</version>
        <relativePath>../secweb-parent</relativePath>
    </parent>

    <artifactId>secweb-web</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>com.mediatek.dt</groupId>
            <artifactId>secweb-service</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</project>
tshepang
  • 12,111
  • 21
  • 91
  • 136
redflame
  • 11
  • 1

1 Answers1

-1

You mat check the active profile by using the Maven Help Plugin as the following example

change directory to the parent
e.g. cd /my/project/secweb-parent
Then execute the following command twice for comparing

mvn help:help:active-profiles

mvn help:help:active-profiles -Pinclude-jar

Anyhow the significant point is the version, you have defined as 1.0.0. I would prefer to use the 1.0.0-SNAPSHOT instead.

You may see further information about the SNAPSHOT, here.

Why would you use this? SNAPSHOT versions are used for projects under active development. If your project depends on a software component that is under active development, you can depend on a SNAPSHOT release, and Maven will periodically attempt to download the latest snapshot from a repository when you run a build. Similarly, if the next release of your system is going to have a version "1.4", your project would have a version "1.4-SNAPSHOT" until it was formally released.

As a default setting, Maven will not check for SNAPSHOT releases on remote repositories. To depend on SNAPSHOT releases, users must explicitly enable the ability to download snapshots using a repository or pluginRepository element in the POM.

There is also a useful question and answer about the snapshot at our stackoverflow, here as well.

I hope this may help.

Community
  • 1
  • 1
Charlee Chitsuk
  • 8,847
  • 2
  • 56
  • 71
  • Thanks for your reply, but I can't find any different from the output of 1) mvn help:help:active-profiles and 2) mvn help:help:active-profiles -Pinclude-jar. – redflame Mar 06 '13 at 11:50