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.api;
20  
21  import java.util.Set;
22  
23  import org.apache.maven.api.annotations.Experimental;
24  import org.apache.maven.api.annotations.Immutable;
25  import org.apache.maven.api.annotations.Nonnull;
26  import org.apache.maven.api.annotations.Nullable;
27  import org.apache.maven.api.model.Dependency;
28  
29  /**
30   * A dependency's {@code Type} is uniquely identified by a {@code String},
31   * and semantically represents a known <i>kind</i> of dependency.
32   * <p>
33   * It provides information about the file type (or extension) of the associated artifact,
34   * its default classifier, and how the artifact will be used in the build when creating
35   * class-paths or module-paths.
36   * <p>
37   * For example, the type {@code java-source} has a {@code jar} extension and a
38   * {@code sources} classifier. The artifact and its dependencies should be added
39   * to the build path.
40   *
41   * @since 4.0.0
42   */
43  @Experimental
44  @Immutable
45  public interface Type extends ExtensibleEnum {
46      /**
47       * Artifact type name for a POM file.
48       */
49      String POM = "pom";
50  
51      /**
52       * Artifact type name for a BOM file.
53       */
54      String BOM = "bom";
55  
56      /**
57       * Artifact type name for a JAR file that can be placed either on the class-path or on the module-path.
58       * The path (classes or modules) is chosen by the plugin, possibly using heuristic rules.
59       * This is the behavior of Maven 3.
60       */
61      String JAR = "jar";
62  
63      /**
64       * Artifact type name for a fat-JAR file that can be only on the class-path.
65       * The fat-JAR is a self-contained JAR and its transitive dependencies will not be resolved, if any.
66       * This type is new in Maven 4.
67       */
68      String FATJAR = "fatjar";
69  
70      /**
71       * Artifact type name for a JAR file to unconditionally place on the class-path.
72       * If the JAR is modular, its module information are ignored.
73       * This type is new in Maven 4.
74       */
75      String CLASSPATH_JAR = "classpath-jar";
76  
77      /**
78       * Artifact type name for a JAR file to unconditionally place on the module-path.
79       * If the JAR is not modular, then it is loaded by Java as an unnamed module.
80       * This type is new in Maven 4.
81       */
82      String MODULAR_JAR = "modular-jar";
83  
84      /**
85       * Artifact type name for a JAR file that can be placed either on the annotation processor class-path
86       * or module-path. The path (classes or modules) is chosen by the plugin, possibly using heuristic rules.
87       */
88      String PROCESSOR = "processor";
89  
90      /**
91       * Artifact type name for a JAR file to unconditionally place on the annotation processor class-path.
92       * If the JAR is modular, its module information are ignored.
93       */
94      String CLASSPATH_PROCESSOR = "classpath-processor";
95  
96      /**
97       * Artifact type name for a JAR file to unconditionally place on the annotation processor module-path.
98       * If the JAR is not modular, then it is loaded by Java as an unnamed module.
99       */
100     String MODULAR_PROCESSOR = "modular-processor";
101 
102     /**
103      * Artifact type name for source code packaged in a JAR file.
104      */
105     String JAVA_SOURCE = "java-source";
106 
107     /**
108      * Artifact type name for javadoc packaged in a JAR file.
109      */
110     String JAVADOC = "javadoc";
111 
112     /**
113      * Artifact type name for a Maven plugin.
114      */
115     String MAVEN_PLUGIN = "maven-plugin";
116 
117     /**
118      * Artifact type name for a JAR file containing test classes. If the main artifact is placed on the class-path
119      * ({@value #JAR} or {@value #CLASSPATH_JAR} types), then the test artifact will also be placed on the class-path.
120      * Otherwise, if the main artifact is placed on the module-path ({@value #JAR} or {@value #MODULAR_JAR} types),
121      * then the test artifact will be added using {@code --patch-module} option.
122      */
123     String TEST_JAR = "test-jar";
124 
125     /**
126      * Returns the dependency type id.
127      * The id uniquely identifies this <i>dependency type</i>.
128      *
129      * @return the id of this type, never {@code null}.
130      */
131     @Nonnull
132     String id();
133 
134     /**
135      * Returns the dependency type language.
136      *
137      * @return the language of this type, never {@code null}.
138      */
139     @Nonnull
140     Language getLanguage();
141 
142     /**
143      * Get the file extension of artifacts of this type.
144      *
145      * @return the file extension, never {@code null}.
146      */
147     @Nonnull
148     String getExtension();
149 
150     /**
151      * Get the default classifier associated to the dependency type.
152      * The default classifier can be overridden when specifying
153      * the {@link Dependency#getClassifier()}.
154      *
155      * @return the default classifier, or {@code null}.
156      */
157     @Nullable
158     String getClassifier();
159 
160     /**
161      * Specifies if the artifact already embeds its own dependencies.
162      * This is the case for JEE packages or similar artifacts such as
163      * WARs, EARs, etc.
164      *
165      * @return if the artifact's dependencies are included in the artifact
166      */
167     boolean isIncludesDependencies();
168 
169     /**
170      * Types of path (class-path, module-path, …) where the dependency can be placed.
171      * For most deterministic builds, the array length should be 1. In such case,
172      * the dependency will be unconditionally placed on the specified type of path
173      * and no heuristic rule will be involved.
174      *
175      * <p>It is nevertheless common to specify two or more types of path. For example,
176      * a Java library may be compatible with either the class-path or the module-path,
177      * and the user may have provided no instruction about which type to use. In such
178      * case, the plugin may apply rules for choosing a path. See for example
179      * {@link JavaPathType#CLASSES} and {@link JavaPathType#MODULES}.</p>
180      */
181     @Nonnull
182     Set<PathType> getPathTypes();
183 }