View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.project.inheritance.t04;
20  
21  import java.io.File;
22  import java.util.Set;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.project.MavenProject;
26  import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
27  import org.junit.jupiter.api.Test;
28  
29  import static org.junit.jupiter.api.Assertions.assertEquals;
30  import static org.junit.jupiter.api.Assertions.assertNotNull;
31  import static org.junit.jupiter.api.Assertions.assertTrue;
32  
33  /**
34   * Verifies the version of a dependency listed in a parent's
35   * dependencyManagement section is chosen over another version of the same
36   * dependency, listed transitively.
37   *
38   */
39  @Deprecated
40  class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase {
41      // ----------------------------------------------------------------------
42      //
43      // p1 inherits from p0
44      // p0 inherits from super model
45      //
46      // or we can show it graphically as:
47      //
48      // p1 ---> p0 --> super model
49      //
50      // p1 has a depMgmt section that specifies versions 1.0 of jars "a" & "b"
51      // jar "a" has a transitive dependency on 2.0 of jar "b", but maven should
52      // prefer to use version 1.0.
53      //
54      // ----------------------------------------------------------------------
55  
56      @Test
57      void testDependencyManagementOverridesTransitiveDependencyVersion() throws Exception {
58          File localRepo = getLocalRepositoryPath();
59          File pom0 = new File(localRepo, "p0/pom.xml");
60          File pom0Basedir = pom0.getParentFile();
61          File pom1 = new File(pom0Basedir, "p1/pom.xml");
62  
63          // load the child project, which inherits from p0...
64          MavenProject project0 = getProjectWithDependencies(pom0);
65          MavenProject project1 = getProjectWithDependencies(pom1);
66  
67          assertEquals(pom0Basedir, project1.getParent().getBasedir());
68          Set set = project1.getArtifacts();
69          assertNotNull(set, "No artifacts");
70          assertTrue(set.size() > 0, "No Artifacts");
71          assertTrue(set.size() == 3, "Set size should be 3, is " + set.size());
72  
73          for (Object aSet : set) {
74              Artifact artifact = (Artifact) aSet;
75              System.out.println("Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion()
76                      + " Optional=" + (artifact.isOptional() ? "true" : "false"));
77              assertTrue(
78                      artifact.getVersion().equals("1.0"), "Incorrect version for " + artifact.getDependencyConflictId());
79          }
80      }
81  }