Pregunta

We have taken all the dependencies to two separate pom files with dependencyManagement Sections. The requirement is to allow building a module with snapshot dependencies and release with release versions.These two pom files(X and Y) contain all the permitted snapshot versions of all modules and all the release versions of all modules. So a module pom file has a dependencyManagement section that imports pom file with release dependencies and a profile that is to be used for builds that contains a dependencyManagement section that imports the pom file with snapshot dependencies. But the problem is, the imported dependencies from the dependency management section in the profile does not get resolved at a build (eventhough the profile is active). If we remove the dependencyManagement section outside the profile (the one with the release versions), these get resolved. Is this expected behaviour? If so, why? Or is this a bug in maven? Tested in both maven 2 and 3.

The following sample pom files show the problem.

project X

<project>
<modelVersion>4.0.0</modelVersion>
 <groupId>maven</groupId>
 <artifactId>X</artifactId>
 <packaging>pom</packaging>
 <name>X</name>
 <version>1.0</version>
 <dependencyManagement>
   <dependencies>
     <dependency>
       <groupId>test</groupId>
       <artifactId>a</artifactId>
       <version>1.0</version>
     </dependency>
     <dependency>
       <groupId>test</groupId>
       <artifactId>b</artifactId>
       <version>1.0</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>
 </dependencyManagement>
</project>

Project Y

<project>
 <modelVersion>4.0.0</modelVersion>
 <groupId>maven</groupId>
 <artifactId>Y</artifactId>
 <packaging>pom</packaging>
 <name>Y</name>
 <version>1.0-SNAPSHOT</version>
 <dependencyManagement>
   <dependencies>
     <dependency>
       <groupId>test</groupId>
       <artifactId>a</artifactId>
       <version>1.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>test</groupId>
       <artifactId>b</artifactId>
       <version>1.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>test</groupId>
       <artifactId>c</artifactId>
       <version>1.0-SNAPSHOT</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>
 </dependencyManagement>
</project>

Project Z

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>maven</groupId>
  <artifactId>Z</artifactId>
  <packaging>pom</packaging>
  <name>Z</name>
  <version>1.0</version>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>maven</groupId>
        <artifactId>X</artifactId>
        <version>1.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <profiles>
      <profile>
        <id>non-release</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <build>true</build>
        </properties>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>maven</groupId>
                    <artifactId>Y</artifactId>
                    <version>1.0-SNAPSHOT</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
      </profile>
  </profiles>
</project>

mvn help:active-profiles returns non-release. But mvn help:effective-pom returns test:a:1.0, test:b:1.0, test:c:1.0-SNAPSHOT

I want to get snapshot versions for a and b also.

Any idea why it happens like this? If this is because of the order it gets resolved, how can I get over with it get snapshot dependencies resolved at builds without mentioning a profile and get release versions resolved at release time?

¿Fue útil?

Solución

This is because you have a dependencyManagement section in the main section of POM, outside profile definitions. This means that definitions included there are profile-independent and so are always taken into account. There is no option in Maven to make it "forget" a dependency, once defined — except by using profiles.

Consider moving the maven:X:1.0:pom to a profile then.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top