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.api;
20
21 import org.apache.maven.api.annotations.Experimental;
22 import org.apache.maven.api.annotations.Immutable;
23 import org.apache.maven.api.annotations.Nonnull;
24
25 /**
26 * A result of collecting, flattening and resolving {@link DependencyCoordinates}s.
27 * Dependency is the output of the <dfn>collection</dfn> process, which builds the graph of dependencies,
28 * followed by <dfn>flattening</dfn> and <dfn>resolution</dfn>.
29 * The version selection is done for each dependency during the collection phase.
30 * The flatten phase will keep only a single version per ({@code groupId}, {@code artifactId}) pair.
31 * The resolution will actually download the dependencies (or artifacts) that have been computed.
32 *
33 * @since 4.0.0
34 */
35 @Experimental
36 @Immutable
37 public interface Dependency extends Artifact {
38 /**
39 * {@return the type of the dependency}
40 * A dependency can be a <abbr>JAR</abbr> file,
41 * a modular-<abbr>JAR</abbr> if it is intended to be placed on the module-path,
42 * a <abbr>JAR</abbr> containing test classes, <i>etc.</i>
43 *
44 * @see DependencyCoordinates#getType()
45 */
46 @Nonnull
47 Type getType();
48
49 /**
50 * {@return the time at which the dependency will be used}
51 * If may be, for example, at compile time only, at run time or at test time.
52 *
53 * @see DependencyCoordinates#getScope()
54 */
55 @Nonnull
56 DependencyScope getScope();
57
58 /**
59 * Returns whether the dependency is optional or mandatory.
60 * Contrarily to {@link DependencyCoordinates}, the obligation of a {@code Dependency} is always present.
61 * The value is computed during the dependencies collection phase.
62 *
63 * @return {@code true} if the dependency is optional, or {@code false} if mandatory
64 * @see DependencyCoordinates#getOptional()
65 */
66 boolean isOptional();
67
68 /**
69 * {@return coordinates with the same identifiers as this dependency}
70 */
71 @Nonnull
72 @Override
73 DependencyCoordinates toCoordinates();
74 }